Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.
TypeScript acmeagentsai-agentscertificate-managementdevsecopsenvironment-variableskubernetesopen-sourcepampkipostgresprivate-caprivileged-access-managementsecret-managementsecret-managersecretssecrets-managementsecuritysecurity-toolsvault
feat: match access request webhook events on overlapping paths
InfisiCalvin668f1242e39c
diff --git a/backend/src/services/webhook/webhook-fns.test.ts b/backend/src/services/webhook/webhook-fns.test.tsindex 025b4dc877..cfa5ae40c4 100644--- a/backend/src/services/webhook/webhook-fns.test.ts+++ b/backend/src/services/webhook/webhook-fns.test.ts@@ -1,6 +1,6 @@import { ActorType } from "@app/services/auth/auth-type";-import { getWebhookPayload } from "./webhook-fns";+import { getWebhookPayload, isWebhookPathSubscribed } from "./webhook-fns";import { AccessRequestWebhookAction, ChangeRequestWebhookAction, WebhookEvents, WebhookType } from "./webhook-types";const projectFields = {@@ -373,3 +373,29 @@ describe("getWebhookPayload: secrets.access-request.modified", () => {expect(result.attachments[0].content.body.map((b) => b.type)).toEqual(["TextBlock", "FactSet"]);});});++describe("isWebhookPathSubscribed", () => {+ describe("concrete event paths use pattern matching", () => {+ test.each([+ ["/api/billing", "/api/*", true],+ ["/api/billing", "/**", true],+ ["/api/billing", "/web/*", false],+ ["/", "/", true]+ ])("event %s against hook %s is %s", (eventPath, hookPath, expected) => {+ expect(isWebhookPathSubscribed(WebhookEvents.ChangeRequestModified, eventPath, hookPath)).toBe(expected);+ });+ });++ describe("access request paths are globs and use overlap", () => {+ test.each([+ ["/api/billing", "/api/*", true],+ ["/api/*", "/api/billing", true],+ ["/**", "/", true],+ ["/api/*", "/**", true],+ ["/api/*", "/web/*", false],+ ["/prod-a/*", "/prod-b/*", false]+ ])("request %s against hook %s is %s", (requestPath, hookPath, expected) => {+ expect(isWebhookPathSubscribed(WebhookEvents.AccessRequestModified, requestPath, hookPath)).toBe(expected);+ });+ });+});diff --git a/backend/src/services/webhook/webhook-fns.ts b/backend/src/services/webhook/webhook-fns.tsindex 735593178d..954fae5689 100644--- a/backend/src/services/webhook/webhook-fns.ts+++ b/backend/src/services/webhook/webhook-fns.ts@@ -2,6 +2,7 @@ import picomatch from "picomatch";import { TWebhooks } from "@app/db/schemas";import { EventType, TAuditLogServiceFactory, WebhookTriggeredEvent } from "@app/ee/services/audit-log/audit-log-types";+import { haveDisjointLiteralPrefixes } from "@app/lib/casl/glob-subset";import { crypto } from "@app/lib/crypto/cryptography";import { NotFoundError } from "@app/lib/errors";import { logger } from "@app/lib/logger";@@ -596,6 +597,14 @@ export type TFnTriggerWebhookDTO = {auditLogService: Pick<TAuditLogServiceFactory, "createAuditLog">;};+// An access request's path is a glob, not a folder, so hook and event are both patterns.+// haveDisjointLiteralPrefixes only proves disjointness when it is certain, so negating it+// delivers whenever overlap is possible rather than dropping the event silently.+export const isWebhookPathSubscribed = (eventType: WebhookEvents, eventPath: string, hookPath: string) =>+ eventType === WebhookEvents.AccessRequestModified+ ? !haveDisjointLiteralPrefixes(eventPath, hookPath)+ : picomatch.isMatch(eventPath, hookPath, { strictSlashes: false });+// this is reusable function// used in secret queue to trigger webhook and update status when secrets changesexport const fnTriggerWebhook = async ({@@ -613,7 +622,7 @@ export const fnTriggerWebhook = async ({const toBeTriggeredHooks = webhooks.filter(({ secretPath: hookSecretPath, isDisabled, filteredEvents }) => {const isEventSubscribed = !filteredEvents || filteredEvents.length === 0 || filteredEvents.includes(event.type);- return !isDisabled && picomatch.isMatch(secretPath, hookSecretPath, { strictSlashes: false }) && isEventSubscribed;+ return !isDisabled && isWebhookPathSubscribed(event.type, secretPath, hookSecretPath) && isEventSubscribed;});if (!toBeTriggeredHooks.length) return;logger.info({ environment, secretPath, projectId }, "Secret webhook job started");