Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

feat(webhook): add get-by-id route and allow machine identity auth

Tre Dubrava8fff82575db8
diff --git a/backend/src/server/routes/v1/webhook-router.ts b/backend/src/server/routes/v1/webhook-router.ts
index 044880e509..21dcfe0671 100644
--- a/backend/src/server/routes/v1/webhook-router.ts
+++ b/backend/src/server/routes/v1/webhook-router.ts
@@ -45,7 +45,7 @@ export const registerWebhookRouter = async (server: FastifyZodProvider) => {
config: {
rateLimit: writeLimit
},
- onRequest: verifyAuth([AuthMode.JWT]),
+ onRequest: verifyAuth([AuthMode.JWT, AuthMode.IDENTITY_ACCESS_TOKEN]),
schema: {
operationId: "createWebhook",
body: z
@@ -133,7 +133,7 @@ export const registerWebhookRouter = async (server: FastifyZodProvider) => {
config: {
rateLimit: writeLimit
},
- onRequest: verifyAuth([AuthMode.JWT]),
+ onRequest: verifyAuth([AuthMode.JWT, AuthMode.IDENTITY_ACCESS_TOKEN]),
schema: {
operationId: "updateWebhook",
params: z.object({
@@ -208,7 +208,7 @@ export const registerWebhookRouter = async (server: FastifyZodProvider) => {
config: {
rateLimit: writeLimit
},
- onRequest: verifyAuth([AuthMode.JWT]),
+ onRequest: verifyAuth([AuthMode.JWT, AuthMode.IDENTITY_ACCESS_TOKEN]),
schema: {
operationId: "deleteWebhook",
params: z.object({
@@ -257,7 +257,7 @@ export const registerWebhookRouter = async (server: FastifyZodProvider) => {
config: {
rateLimit: writeLimit
},
- onRequest: verifyAuth([AuthMode.JWT]),
+ onRequest: verifyAuth([AuthMode.JWT, AuthMode.IDENTITY_ACCESS_TOKEN]),
schema: {
operationId: "testWebhook",
params: z.object({
@@ -282,13 +282,43 @@ export const registerWebhookRouter = async (server: FastifyZodProvider) => {
}
});
+ server.route({
+ method: "GET",
+ url: "/:webhookId",
+ config: {
+ rateLimit: readLimit
+ },
+ onRequest: verifyAuth([AuthMode.JWT, AuthMode.IDENTITY_ACCESS_TOKEN]),
+ schema: {
+ operationId: "getWebhookById",
+ params: z.object({
+ webhookId: z.string().trim()
+ }),
+ response: {
+ 200: z.object({
+ webhook: sanitizedWebhookSchema.extend({ url: z.string() })
+ })
+ }
+ },
+ handler: async (req) => {
+ const webhook = await server.services.webhook.getWebhookById({
+ actor: req.permission.type,
+ actorId: req.permission.id,
+ actorAuthMethod: req.permission.authMethod,
+ actorOrgId: req.permission.orgId,
+ id: req.params.webhookId
+ });
+ return { webhook };
+ }
+ });
+
server.route({
method: "GET",
url: "/",
config: {
rateLimit: readLimit
},
- onRequest: verifyAuth([AuthMode.JWT]),
+ onRequest: verifyAuth([AuthMode.JWT, AuthMode.IDENTITY_ACCESS_TOKEN]),
schema: {
operationId: "listWebhooks",
querystring: z.object({
diff --git a/backend/src/services/webhook/webhook-service.ts b/backend/src/services/webhook/webhook-service.ts
index 2cf09bcbd9..b791bffe01 100644
--- a/backend/src/services/webhook/webhook-service.ts
+++ b/backend/src/services/webhook/webhook-service.ts
@@ -19,6 +19,7 @@ import {
SUBSCRIBABLE_WEBHOOK_EVENTS,
TCreateWebhookDTO,
TDeleteWebhookDTO,
+ TGetWebhookByIdDTO,
TListWebhookDTO,
TSubscribableWebhookEvent,
TTestWebhookDTO,
@@ -251,10 +252,36 @@ export const webhookServiceFactory = ({
});
};
+ const getWebhookById = async ({ id, actor, actorId, actorAuthMethod, actorOrgId }: TGetWebhookByIdDTO) => {
+ const webhook = await webhookDAL.findById(id);
+ if (!webhook) throw new NotFoundError({ message: `Webhook with ID '${id}' not found` });
+
+ const { permission } = await permissionService.getProjectPermission({
+ actor,
+ actorId,
+ projectId: webhook.projectId,
+ actorAuthMethod,
+ actorOrgId,
+ actionProjectType: ActionProjectType.Any
+ });
+ ForbiddenError.from(permission).throwUnlessCan(ProjectPermissionActions.Read, ProjectPermissionSub.Webhooks);
+
+ const { decryptor: secretManagerDecryptor } = await kmsService.createCipherPairWithDataKey({
+ type: KmsDataKey.SecretManager,
+ projectId: webhook.projectId
+ });
+ const { url } = decryptWebhookDetails(webhook, (value) =>
+ secretManagerDecryptor({ cipherTextBlob: value }).toString()
+ );
+
+ return { ...withEventsFilter(webhook), url };
+ };
+
return {
createWebhook,
deleteWebhook,
listWebhooks,
+ getWebhookById,
updateWebhook,
testWebhook
};
diff --git a/backend/src/services/webhook/webhook-types.ts b/backend/src/services/webhook/webhook-types.ts
index 9791e895c5..2e1843a3bf 100644
--- a/backend/src/services/webhook/webhook-types.ts
+++ b/backend/src/services/webhook/webhook-types.ts
@@ -25,6 +25,10 @@ export type TDeleteWebhookDTO = {
id: string;
} & Omit<TProjectPermission, "projectId">;
+export type TGetWebhookByIdDTO = {
+ id: string;
+} & Omit<TProjectPermission, "projectId">;
+
export type TListWebhookDTO = {
environment?: string;
secretPath?: string;