Skip to content

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

fix: fix migration and add badge to show possible events

adilsona927d27153bb
diff --git a/backend/src/db/migrations/20260409120000_add-webhook-event-toggles.ts b/backend/src/db/migrations/20260409120000_add-webhook-event-toggles.ts
index 30384744f7..827adcdda8 100644
--- a/backend/src/db/migrations/20260409120000_add-webhook-event-toggles.ts
+++ b/backend/src/db/migrations/20260409120000_add-webhook-event-toggles.ts
@@ -12,7 +12,7 @@ export async function up(knex: Knex): Promise<void> {
await knex.schema.alterTable(TableName.Webhook, (table) => {
if (!hasBlockedEventsColumn) {
- table.specificType(BLOCKED_EVENTS_COLUMN, "text[]").notNullable().defaultTo(knex.raw("'{}'"));
+ table.specificType(BLOCKED_EVENTS_COLUMN, "text[]").nullable();
}
});
}
diff --git a/backend/src/db/schemas/webhooks.ts b/backend/src/db/schemas/webhooks.ts
index a35603ed0d..af30b4a090 100644
--- a/backend/src/db/schemas/webhooks.ts
+++ b/backend/src/db/schemas/webhooks.ts
@@ -6,7 +6,6 @@
import { z } from "zod";
import { zodBuffer } from "@app/lib/zod";
-import { WebhookEvents } from "@app/services/webhook/webhook-types";
import { TImmutableDBKeys } from "./models";
@@ -31,10 +30,7 @@ export const WebhooksSchema = z.object({
type: z.string().default("general").nullable().optional(),
encryptedPassKey: zodBuffer.nullable().optional(),
encryptedUrl: zodBuffer,
- blockedEvents: z
- .nativeEnum(WebhookEvents)
- .array()
- .default([WebhookEvents.SecretModified, WebhookEvents.SecretRotationFailed])
+ blockedEvents: z.string().array().nullable().optional()
});
export type TWebhooks = z.infer<typeof WebhooksSchema>;
diff --git a/backend/src/services/webhook/webhook-fns.ts b/backend/src/services/webhook/webhook-fns.ts
index ae262947e3..632e4505e5 100644
--- a/backend/src/services/webhook/webhook-fns.ts
+++ b/backend/src/services/webhook/webhook-fns.ts
@@ -262,7 +262,8 @@ export const getWebhookPayload = (event: TWebhookPayloads) => {
};
}
- throw new Error(`Unhandled webhook event type: ${(event as { type: string }).type}`);
+ logger.warn({ event }, "Unhandled webhook event");
+ return null;
};
export type TFnTriggerWebhookDTO = {
@@ -310,8 +311,9 @@ export const fnTriggerWebhook = async ({
type: event.type,
payload: { ...event.payload, type: hook.type, projectName }
} as TWebhookPayloads;
-
- return triggerWebhookRequest(hook, secretManagerDecryptor, getWebhookPayload(formattedEvent));
+ const payload = getWebhookPayload(formattedEvent);
+ if (!payload) return;
+ return triggerWebhookRequest(hook, secretManagerDecryptor, payload);
})
);
diff --git a/backend/src/services/webhook/webhook-service.ts b/backend/src/services/webhook/webhook-service.ts
index bcdfb32d39..19a401eb3c 100644
--- a/backend/src/services/webhook/webhook-service.ts
+++ b/backend/src/services/webhook/webhook-service.ts
@@ -3,7 +3,7 @@ import { ForbiddenError } from "@casl/ability";
import { ActionProjectType, TWebhooksInsert } from "@app/db/schemas";
import { TPermissionServiceFactory } from "@app/ee/services/permission/permission-service-types";
import { ProjectPermissionActions, ProjectPermissionSub } from "@app/ee/services/permission/project-permission";
-import { NotFoundError } from "@app/lib/errors";
+import { BadRequestError, NotFoundError } from "@app/lib/errors";
import { blockLocalAndPrivateIpAddresses } from "@app/lib/validator";
import { TKmsServiceFactory } from "../kms/kms-service";
@@ -41,14 +41,14 @@ export const webhookServiceFactory = ({
const toBlockedEvents = (
isSecretModifiedEventEnabled?: boolean,
isSecretRotationFailedEventEnabled?: boolean
- ): WebhookEvents[] => {
- const blocked: WebhookEvents[] = [];
+ ): string[] => {
+ const blocked: string[] = [];
if (isSecretModifiedEventEnabled === false) blocked.push(WebhookEvents.SecretModified);
if (isSecretRotationFailedEventEnabled === false) blocked.push(WebhookEvents.SecretRotationFailed);
return blocked;
};
- const withEventFlags = <T extends { blockedEvents?: WebhookEvents[] | null }>(webhook: T) => ({
+ const withEventFlags = <T extends { blockedEvents?: string[] | null }>(webhook: T) => ({
...webhook,
isSecretModifiedEventEnabled: !webhook.blockedEvents?.includes(WebhookEvents.SecretModified),
isSecretRotationFailedEventEnabled: !webhook.blockedEvents?.includes(WebhookEvents.SecretRotationFailed)
@@ -136,13 +136,13 @@ export const webhookServiceFactory = ({
const updateData: {
isDisabled?: boolean;
- blockedEvents?: WebhookEvents[];
+ blockedEvents?: string[];
} = {
...(isDisabled !== undefined ? { isDisabled } : {})
};
if (hasEventToggleUpdate) {
- const currentBlocked = new Set<WebhookEvents>(webhook.blockedEvents ?? []);
+ const currentBlocked = new Set<string>(webhook.blockedEvents ?? []);
if (isSecretModifiedEventEnabled !== undefined) {
if (isSecretModifiedEventEnabled) {
@@ -207,19 +207,23 @@ export const webhookServiceFactory = ({
ForbiddenError.from(permission).throwUnlessCan(ProjectPermissionActions.Read, ProjectPermissionSub.Webhooks);
let webhookError: string | undefined;
try {
+ const payload = getWebhookPayload({
+ type: WebhookEvents.TestEvent,
+ payload: {
+ projectName: project.name,
+ projectId: webhook.projectId,
+ environment: webhook.environment.slug,
+ secretPath: webhook.secretPath,
+ type: webhook.type
+ }
+ });
+
+ if (!payload) throw new BadRequestError({ message: "Failed to get webhook payload for test event" });
+
await triggerWebhookRequest(
webhook,
(value) => secretManagerDecryptor({ cipherTextBlob: value }).toString(),
- getWebhookPayload({
- type: WebhookEvents.TestEvent,
- payload: {
- projectName: project.name,
- projectId: webhook.projectId,
- environment: webhook.environment.slug,
- secretPath: webhook.secretPath,
- type: webhook.type
- }
- })
+ payload
);
} catch (err) {
webhookError = (err as Error).message;
diff --git a/frontend/src/pages/secret-manager/SettingsPage/components/WebhooksTab/WebhooksTab.tsx b/frontend/src/pages/secret-manager/SettingsPage/components/WebhooksTab/WebhooksTab.tsx
index 095b8355a2..3f81908311 100644
--- a/frontend/src/pages/secret-manager/SettingsPage/components/WebhooksTab/WebhooksTab.tsx
+++ b/frontend/src/pages/secret-manager/SettingsPage/components/WebhooksTab/WebhooksTab.tsx
@@ -18,6 +18,7 @@ import {
Tooltip,
Tr
} from "@app/components/v2";
+import { Badge } from "@app/components/v3";
import { ProjectPermissionActions, ProjectPermissionSub, useProject } from "@app/context";
import { withProjectPermission } from "@app/hoc";
import { usePopUp } from "@app/hooks";
@@ -28,7 +29,7 @@ import {
useTestWebhook,
useUpdateWebhook
} from "@app/hooks/api";
-import { TWebhook } from "@app/hooks/api/webhooks/types";
+import { TWebhook, WEBHOOK_EVENT_METADATA, WEBHOOK_EVENTS } from "@app/hooks/api/webhooks/types";
import { AddWebhookForm, TFormSchema } from "./AddWebhookForm";
import { EditWebhookEventsModal } from "./EditWebhookEventsModal";
@@ -156,15 +157,27 @@ export const WebhooksTab = withProjectPermission(
<Td>URL</Td>
<Td>Environment</Td>
<Td>Secret Path</Td>
+ <Td>
+ <div className="flex items-center gap-1">
+ <span>Events</span>
+ <Tooltip content="Events that are configured to trigger this webhook.">
+ <FontAwesomeIcon
+ icon={faInfoCircle}
+ size="xs"
+ className="text-mineshaft-400"
+ />
+ </Tooltip>
+ </div>
+ </Td>
<Td>Status</Td>
<Td className="text-right">Action</Td>
</Tr>
</THead>
<TBody>
- {isWebhooksLoading && <TableSkeleton columns={5} innerKey="webhooks-loading" />}
+ {isWebhooksLoading && <TableSkeleton columns={6} innerKey="webhooks-loading" />}
{!isWebhooksLoading && webhooks && webhooks?.length === 0 && (
<Tr>
- <Td colSpan={5}>
+ <Td colSpan={6}>
<EmptyState title="No webhooks found" icon={faPlug} />
</Td>
</Tr>
@@ -182,6 +195,12 @@ export const WebhooksTab = withProjectPermission(
lastRunErrorMessage
} = webhook;
+ const enabledEvents = WEBHOOK_EVENTS.filter(
+ (event) => webhook[WEBHOOK_EVENT_METADATA[event].key] !== false
+ );
+ const enabledEventsCount = enabledEvents.length;
+ const hasEnabledEvents = enabledEventsCount > 0;
+
return (
<Tr key={id}>
<Td className="max-w-xs overflow-hidden text-ellipsis hover:overflow-auto hover:break-all">
@@ -190,6 +209,27 @@ export const WebhooksTab = withProjectPermission(
</Td>
<Td>{environment.slug}</Td>
<Td>{secretPath}</Td>
+ <Td>
+ <Tooltip
+ content={
+ hasEnabledEvents ? (
+ <div className="space-y-0.5 text-xs">
+ {enabledEvents.map((event) => (
+ <div key={event}>{WEBHOOK_EVENT_METADATA[event].label}</div>
+ ))}
+ </div>
+ ) : (
+ "This webhook is not triggered by any events."
+ )
+ }
+ >
+ <Badge variant={hasEnabledEvents ? "success" : "danger"}>
+ {hasEnabledEvents
+ ? `${enabledEventsCount} Event${enabledEventsCount === 1 ? "" : "s"}`
+ : "No Events"}
+ </Badge>
+ </Tooltip>
+ </Td>
<Td>
{!lastStatus ? (
"-"