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
create webhook API to receive calls from AWS
Matheus Nogueiraf47f36c611bb
diff --git a/backend/src/ee/routes/v1/honey-token-router.ts b/backend/src/ee/routes/v1/honey-token-router.tsindex 21bc2a20b0..fc5992f02a 100644--- a/backend/src/ee/routes/v1/honey-token-router.ts+++ b/backend/src/ee/routes/v1/honey-token-router.ts@@ -66,7 +66,7 @@ export const registerHoneyTokenRouter = async (server: FastifyZodProvider) => {connectionId: z.string().nullable(),createdAt: z.date().nullable(),updatedAt: z.date().nullable(),- decryptedConfig: z.object({ secretToken: z.string() }).nullable()+ decryptedConfig: z.object({ webhookSigningKey: z.string() }).nullable()})})}@@ -80,4 +80,32 @@ export const registerHoneyTokenRouter = async (server: FastifyZodProvider) => {return { config };}});++ server.route({+ url: "/:orgId/trigger",+ method: "POST",+ config: {+ rateLimit: writeLimit+ },+ schema: {+ params: z.object({+ orgId: z.string().trim()+ }),+ body: z.unknown(),+ response: {+ 200: z.object({+ acknowledged: z.boolean()+ })+ }+ },+ handler: async (req) => {+ const { acknowledged } = await server.services.honeyToken.handleTrigger({+ orgId: req.params.orgId,+ signature: req.headers["x-infisical-signature"] as string | undefined,+ payload: req.body+ });++ return { acknowledged };+ }+ });};diff --git a/backend/src/ee/services/honey-token/honey-token-config-service.ts b/backend/src/ee/services/honey-token/honey-token-config-service.tsindex 3dc458e5e5..9eec694e22 100644--- a/backend/src/ee/services/honey-token/honey-token-config-service.ts+++ b/backend/src/ee/services/honey-token/honey-token-config-service.ts@@ -3,7 +3,8 @@ import crypto from "node:crypto";import { ForbiddenError } from "@casl/ability";import { OrganizationActionScope } from "@app/db/schemas";-import { BadRequestError } from "@app/lib/errors";+import { BadRequestError, NotFoundError, UnauthorizedError } from "@app/lib/errors";+import { logger } from "@app/lib/logger";import { OrgServiceActor } from "@app/lib/types";import { TKmsServiceFactory } from "@app/services/kms/kms-service";import { KmsDataKey } from "@app/services/kms/kms-types";@@ -39,7 +40,7 @@ export const honeyTokenConfigServiceFactory = ({orgPermission: OrgServiceActor;type: HoneyTokenType;connectionId: string;- config: { secretToken: string };+ config: { webhookSigningKey: string };}) => {const { permission } = await permissionService.getOrgPermission({scope: OrganizationActionScope.Any,@@ -111,7 +112,7 @@ export const honeyTokenConfigServiceFactory = ({});if (!config) {- const generatedToken = `htk_live_${crypto.randomBytes(24).toString("hex")}`;+ const generatedKey = `htk_live_${crypto.randomBytes(24).toString("hex")}`;return {id: null,orgId: orgPermission.orgId,@@ -119,7 +120,7 @@ export const honeyTokenConfigServiceFactory = ({connectionId: null,createdAt: null,updatedAt: null,- decryptedConfig: { secretToken: generatedToken }+ decryptedConfig: { webhookSigningKey: generatedKey }};}@@ -128,7 +129,7 @@ export const honeyTokenConfigServiceFactory = ({orgId: orgPermission.orgId});- let decryptedConfig: { secretToken: string } | null = null;+ let decryptedConfig: { webhookSigningKey: string } | null = null;if (config.encryptedConfig) {const decrypted = decryptor({cipherTextBlob: config.encryptedConfig@@ -142,8 +143,76 @@ export const honeyTokenConfigServiceFactory = ({};};+ const SIGNATURE_TOLERANCE_MS = 5 * 60 * 1000;++ const handleTrigger = async ({+ orgId,+ signature,+ payload+ }: {+ orgId: string;+ signature: string | undefined;+ payload: unknown;+ }) => {+ if (!signature) {+ throw new UnauthorizedError({ message: "Missing X-Infisical-Signature header" });+ }++ // Header format: t=<unix-seconds>,v1=<hmac-sha256-hex>+ const parts = Object.fromEntries(signature.split(",").map((p) => p.split("="))) as Record<string, string>;+ const timestamp = parts.t;+ const signatureHash = parts.v1;++ if (!timestamp || !signatureHash) {+ throw new UnauthorizedError({+ message: "Invalid X-Infisical-Signature format. Expected t=<timestamp>,v1=<signature>"+ });+ }++ const timestampMs = Number(timestamp) * 1000;+ if (Number.isNaN(timestampMs) || Math.abs(Date.now() - timestampMs) > SIGNATURE_TOLERANCE_MS) {+ throw new UnauthorizedError({ message: "Request timestamp is too old or invalid" });+ }++ const config = await honeyTokenConfigDAL.findOne({+ orgId,+ type: HoneyTokenType.AWS+ });++ if (!config?.encryptedConfig) {+ throw new NotFoundError({ message: "No honey token configuration found for this organization" });+ }++ const { decryptor } = await kmsService.createCipherPairWithDataKey({+ type: KmsDataKey.Organization,+ orgId+ });++ const decrypted = decryptor({ cipherTextBlob: config.encryptedConfig });+ const storedConfig = AwsHoneyTokenConfigSchema.parse(JSON.parse(decrypted.toString()) as unknown);++ const bodyString = JSON.stringify(payload);+ const signedPayload = `${timestamp}.${bodyString}`;+ const expectedSignature = crypto+ .createHmac("sha256", storedConfig.webhookSigningKey)+ .update(signedPayload)+ .digest("hex");++ const expectedBuf = Buffer.from(expectedSignature, "hex");+ const receivedBuf = Buffer.from(signatureHash, "hex");++ if (expectedBuf.byteLength !== receivedBuf.byteLength || !crypto.timingSafeEqual(expectedBuf, receivedBuf)) {+ throw new UnauthorizedError({ message: "Invalid webhook signature" });+ }++ logger.info({ orgId, payload }, `Honey token trigger received [orgId=${orgId}]`);++ return { acknowledged: true };+ };+return {upsertConfig,- getConfig+ getConfig,+ handleTrigger};};diff --git a/backend/src/ee/services/honey-token/honey-token-types.ts b/backend/src/ee/services/honey-token/honey-token-types.tsindex facac43bb8..938b6f6e36 100644--- a/backend/src/ee/services/honey-token/honey-token-types.ts+++ b/backend/src/ee/services/honey-token/honey-token-types.ts@@ -32,7 +32,7 @@ export type THoneyTokenEventMetadata = z.infer<typeof HoneyTokenEventMetadataSch// --- Config schemas (typed shape for the encrypted config blob per provider) ---export const AwsHoneyTokenConfigSchema = z.object({- secretToken: z.string().min(1)+ webhookSigningKey: z.string().min(1)});export type TAwsHoneyTokenConfig = z.infer<typeof AwsHoneyTokenConfigSchema>;diff --git a/frontend/src/hooks/api/honeyToken/types.ts b/frontend/src/hooks/api/honeyToken/types.tsindex 4a1c9120b5..9aa93c0ff1 100644--- a/frontend/src/hooks/api/honeyToken/types.ts+++ b/frontend/src/hooks/api/honeyToken/types.ts@@ -10,7 +10,7 @@ export type THoneyTokenConfig = {createdAt: string | null;updatedAt: string | null;decryptedConfig: {- secretToken: string;+ webhookSigningKey: string;} | null;};@@ -18,6 +18,6 @@ export type TUpsertHoneyTokenConfigDTO = {type: HoneyTokenType;connectionId: string;config: {- secretToken: string;+ webhookSigningKey: string;};};diff --git a/frontend/src/pages/organization/SettingsPage/components/OrgProductSettingsTab/HoneyTokenSection.tsx b/frontend/src/pages/organization/SettingsPage/components/OrgProductSettingsTab/HoneyTokenSection.tsxindex 8e06a1c66b..9d6b70d9f9 100644--- a/frontend/src/pages/organization/SettingsPage/components/OrgProductSettingsTab/HoneyTokenSection.tsx+++ b/frontend/src/pages/organization/SettingsPage/components/OrgProductSettingsTab/HoneyTokenSection.tsx@@ -31,7 +31,7 @@ const CF_TEMPLATE_URL =const schema = z.object({connectionId: z.string().min(1, "AWS Connection is required"),- secretToken: z.string().min(1, "Secret Token is required")+ webhookSigningKey: z.string().min(1, "Webhook Signing Key is required")});type FormData = z.infer<typeof schema>;@@ -62,7 +62,7 @@ export const HoneyTokenSection = () => {resolver: zodResolver(schema),defaultValues: {connectionId: "",- secretToken: ""+ webhookSigningKey: ""}});@@ -71,11 +71,11 @@ export const HoneyTokenSection = () => {reset({connectionId: existingConfig.connectionId ?? "",- secretToken: existingConfig.decryptedConfig.secretToken+ webhookSigningKey: existingConfig.decryptedConfig.webhookSigningKey});}, [existingConfig, reset]);- const secretToken = watch("secretToken");+ const webhookSigningKey = watch("webhookSigningKey");const cfCommand = useMemo(() =>@@ -87,9 +87,9 @@ export const HoneyTokenSection = () => {" --capabilities CAPABILITY_NAMED_IAM \\"," --parameters \\",` ParameterKey=WebhookUrl,ParameterValue=${webhookUrl} \\`,- ` ParameterKey=WebhookSigningKey,ParameterValue=${secretToken}`+ ` ParameterKey=WebhookSigningKey,ParameterValue=${webhookSigningKey}`].join("\n"),- [secretToken, webhookUrl]+ [webhookSigningKey, webhookUrl]);const onSubmit = async (data: FormData) => {@@ -98,7 +98,7 @@ export const HoneyTokenSection = () => {type: HoneyTokenType.AWS,connectionId: data.connectionId,config: {- secretToken: data.secretToken+ webhookSigningKey: data.webhookSigningKey}});createNotification({@@ -161,14 +161,14 @@ export const HoneyTokenSection = () => {</div><div className="flex-1"><Field>- <FieldLabel>Secret Token</FieldLabel>+ <FieldLabel>Webhook Signing Key</FieldLabel><FieldContent><div className="flex items-center gap-2"><div className="flex h-9 flex-1 items-center overflow-hidden rounded-md border border-mineshaft-500 bg-mineshaft-900 px-3 font-mono text-sm text-bunker-200">- {isTokenVisible ? secretToken : "•".repeat(30)}+ {isTokenVisible ? webhookSigningKey : "•".repeat(30)}</div><IconButton- aria-label="toggle secret token visibility"+ aria-label="toggle signing key visibility"variant="outline"size="md"onClick={() => setIsTokenVisible.toggle()}@@ -176,11 +176,11 @@ export const HoneyTokenSection = () => {<FontAwesomeIcon icon={isTokenVisible ? faEyeSlash : faEye} /></IconButton><IconButton- aria-label="copy secret token"+ aria-label="copy signing key"variant="outline"size="md"onClick={() => {- navigator.clipboard.writeText(secretToken);+ navigator.clipboard.writeText(webhookSigningKey);setTokenCopied(true);}}>