Skip to content

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

feat: add secrets.change-request.modified webhook event

InfisiCalvin990ea4c49c11
diff --git a/backend/src/services/webhook/webhook-fns.test.ts b/backend/src/services/webhook/webhook-fns.test.ts
index 0c326a0237..d59ae1527f 100644
--- a/backend/src/services/webhook/webhook-fns.test.ts
+++ b/backend/src/services/webhook/webhook-fns.test.ts
@@ -1,5 +1,7 @@
+import { ActorType } from "@app/services/auth/auth-type";
+
import { getWebhookPayload } from "./webhook-fns";
-import { WebhookEvents, WebhookType } from "./webhook-types";
+import { ChangeRequestWebhookAction, WebhookEvents, WebhookType } from "./webhook-types";
const projectFields = {
projectId: "proj-1",
@@ -93,3 +95,106 @@ describe("getWebhookPayload: honey-token.triggered", () => {
});
});
});
+
+const changeRequestPayload = {
+ projectId: "proj-1",
+ projectName: "Secrets management",
+ environment: "prod",
+ environmentName: "Production",
+ secretPath: "/api",
+ action: ChangeRequestWebhookAction.Merged,
+ request: {
+ id: "req-1",
+ slug: "clever-otter",
+ url: "https://app.infisical.com/organizations/org-1/projects/secret-management/proj-1/approval?requestId=req-1",
+ status: "close",
+ hasMerged: true,
+ isBypassed: false,
+ policy: { id: "pol-1", name: "Production secrets", enforcementLevel: "hard" },
+ requestedBy: { type: ActorType.USER as const, id: "user-1", name: "Ada Lovelace", email: "[email protected]" },
+ createdAt: "2026-08-20T10:00:00.000Z",
+ updatedAt: "2026-08-20T10:42:00.000Z"
+ }
+};
+
+describe("getWebhookPayload: secrets.change-request.modified", () => {
+ test("general payload nests project and request", () => {
+ const result = getWebhookPayload({
+ type: WebhookEvents.ChangeRequestModified,
+ payload: { ...changeRequestPayload, type: WebhookType.GENERAL }
+ });
+
+ expect(result).toEqual({
+ event: "secrets.change-request.modified",
+ action: "merged",
+ project: { id: "proj-1", name: "Secrets management" },
+ request: {
+ id: "req-1",
+ slug: "clever-otter",
+ url: changeRequestPayload.request.url,
+ target: {
+ environment: { name: "Production", slug: "prod" },
+ secretPath: "/api"
+ },
+ status: "close",
+ hasMerged: true,
+ isBypassed: false,
+ policy: { id: "pol-1", name: "Production secrets", enforcementLevel: "hard" },
+ requestedBy: { type: "user", id: "user-1", name: "Ada Lovelace", email: "[email protected]" },
+ createdAt: "2026-08-20T10:00:00.000Z",
+ updatedAt: "2026-08-20T10:42:00.000Z"
+ }
+ });
+ });
+
+ test("general payload carries a null requester when the author was deleted", () => {
+ const result = getWebhookPayload({
+ type: WebhookEvents.ChangeRequestModified,
+ payload: {
+ ...changeRequestPayload,
+ type: WebhookType.GENERAL,
+ request: { ...changeRequestPayload.request, requestedBy: null }
+ }
+ }) as { request: { requestedBy: unknown } };
+
+ expect(result.request.requestedBy).toBeNull();
+ });
+
+ test("general payload carries no free text fields", () => {
+ const result = getWebhookPayload({
+ type: WebhookEvents.ChangeRequestModified,
+ payload: { ...changeRequestPayload, type: WebhookType.GENERAL }
+ });
+
+ const serialized = JSON.stringify(result);
+ expect(serialized).not.toContain("commitMessage");
+ expect(serialized).not.toContain("bypassReason");
+ });
+
+ test("slack payload names the transition", () => {
+ const result = getWebhookPayload({
+ type: WebhookEvents.ChangeRequestModified,
+ payload: { ...changeRequestPayload, type: WebhookType.SLACK }
+ }) as { text: string; attachments: { fields: { title: string; value?: string }[] }[] };
+
+ expect(result.text).toBe("A secret change request was merged.");
+ expect(result.attachments[0].fields.map((f) => f.title)).toEqual([
+ "Project",
+ "Environment",
+ "Secret Path",
+ "Policy",
+ "Status",
+ "Requested By",
+ "Bypassed"
+ ]);
+ });
+
+ test("teams payload is an adaptive card with a fact set", () => {
+ const result = getWebhookPayload({
+ type: WebhookEvents.ChangeRequestModified,
+ payload: { ...changeRequestPayload, type: WebhookType.MICROSOFT_TEAMS }
+ }) as { attachments: { content: { body: { type: string }[] } }[] };
+
+ expect(result.attachments[0].content.body.map((b) => b.type)).toEqual(["TextBlock", "FactSet"]);
+ });
+});
diff --git a/backend/src/services/webhook/webhook-fns.ts b/backend/src/services/webhook/webhook-fns.ts
index 1a36d97d7d..031d96d212 100644
--- a/backend/src/services/webhook/webhook-fns.ts
+++ b/backend/src/services/webhook/webhook-fns.ts
@@ -391,6 +391,87 @@ export const getWebhookPayload = (event: TWebhookPayloads) => {
}
}
+ if (event.type === WebhookEvents.ChangeRequestModified) {
+ const { projectId, projectName, environment, environmentName, secretPath, type, action, request } = event.payload;
+
+ switch (type) {
+ case WebhookType.SLACK:
+ return {
+ text: `A secret change request was ${action}.`,
+ attachments: [
+ {
+ color: "#E7F256",
+ fields: [
+ { title: "Project", value: projectName, short: false },
+ { title: "Environment", value: environmentName || environment, short: false },
+ { title: "Secret Path", value: secretPath, short: false },
+ { title: "Policy", value: request.policy.name, short: false },
+ { title: "Status", value: request.hasMerged ? "Merged" : request.status, short: false },
+ { title: "Requested By", value: request.requestedBy?.name || "Unknown", short: false },
+ { title: "Bypassed", value: request.isBypassed ? "Yes" : "No", short: false }
+ ]
+ }
+ ]
+ };
+ case WebhookType.MICROSOFT_TEAMS:
+ return {
+ type: "message",
+ attachments: [
+ {
+ contentType: "application/vnd.microsoft.card.adaptive",
+ content: {
+ type: "AdaptiveCard",
+ version: "1.2",
+ body: [
+ {
+ type: "TextBlock",
+ size: "Medium",
+ weight: "Bolder",
+ text: `A secret change request was ${action}.`
+ },
+ {
+ type: "FactSet",
+ facts: [
+ { title: "Project", value: projectName || "" },
+ { title: "Environment", value: environmentName || environment },
+ { title: "Secret Path", value: secretPath || "" },
+ { title: "Policy", value: request.policy.name },
+ { title: "Status", value: request.hasMerged ? "Merged" : request.status },
+ { title: "Requested By", value: request.requestedBy?.name || "Unknown" },
+ { title: "Bypassed", value: request.isBypassed ? "Yes" : "No" }
+ ]
+ }
+ ]
+ }
+ }
+ ]
+ };
+ case WebhookType.GENERAL:
+ default:
+ return {
+ event: event.type,
+ action,
+ project: { id: projectId, name: projectName },
+ request: {
+ id: request.id,
+ slug: request.slug,
+ url: request.url,
+ target: {
+ environment: { name: environmentName, slug: environment },
+ secretPath
+ },
+ status: request.status,
+ hasMerged: request.hasMerged,
+ isBypassed: request.isBypassed,
+ policy: request.policy,
+ requestedBy: request.requestedBy,
+ createdAt: request.createdAt,
+ updatedAt: request.updatedAt
+ }
+ };
+ }
+ }
+
if (event.type === WebhookEvents.TestEvent) {
const { projectName, projectId, environment, environmentName, secretPath } = event.payload;
return {
diff --git a/backend/src/services/webhook/webhook-types.ts b/backend/src/services/webhook/webhook-types.ts
index 6a5b648aa0..6574b3d66b 100644
--- a/backend/src/services/webhook/webhook-types.ts
+++ b/backend/src/services/webhook/webhook-types.ts
@@ -44,15 +44,32 @@ export enum WebhookEvents {
SecretModified = "secrets.modified",
SecretRotationFailed = "secrets.rotation-failed",
HoneyTokenTriggered = "honey-token.triggered",
+ ChangeRequestModified = "secrets.change-request.modified",
TestEvent = "test"
}
export const SUBSCRIBABLE_WEBHOOK_EVENTS = [
WebhookEvents.SecretModified,
WebhookEvents.SecretRotationFailed,
- WebhookEvents.HoneyTokenTriggered
+ WebhookEvents.HoneyTokenTriggered,
+ WebhookEvents.ChangeRequestModified
] as const;
+export enum ChangeRequestWebhookAction {
+ Created = "created",
+ Reviewed = "reviewed",
+ Closed = "closed",
+ Reopened = "reopened",
+ Merged = "merged"
+}
+
+export type TWebhookActor = {
+ type: ActorType.USER | ActorType.IDENTITY;
+ id: string;
+ name: string;
+ email: string | null;
+};
+
export type TSubscribableWebhookEvent = (typeof SUBSCRIBABLE_WEBHOOK_EVENTS)[number];
type TWebhookSecretModifiedEventPayload = {
@@ -113,8 +130,34 @@ type TWebhookTestEventPayload = {
};
};
+type TWebhookChangeRequestModifiedEventPayload = {
+ type: WebhookEvents.ChangeRequestModified;
+ payload: {
+ projectId: string;
+ projectName?: string;
+ environment: string;
+ environmentName?: string;
+ secretPath?: string;
+ type?: string | null;
+ action: ChangeRequestWebhookAction;
+ request: {
+ id: string;
+ slug: string;
+ url: string;
+ status: string;
+ hasMerged: boolean;
+ isBypassed: boolean;
+ policy: { id: string; name: string; enforcementLevel: string };
+ requestedBy: TWebhookActor | null;
+ createdAt: string;
+ updatedAt: string;
+ };
+ };
+};
+
export type TWebhookPayloads =
| TWebhookSecretModifiedEventPayload
| TWebhookSecretRotationFailedEventPayload
| TWebhookHoneyTokenTriggeredEventPayload
+ | TWebhookChangeRequestModifiedEventPayload
| TWebhookTestEventPayload;