From eff22485543bca313af939d9cdd7d011d000cd1c Mon Sep 17 00:00:00 2001 From: Andrew Lee <5784515+andyrewlee@users.noreply.github.com> Date: Mon, 30 Nov 2026 12:43:52 -0800 Subject: [PATCH] Accept opaque Standard Webhooks delivery identifiers --- README.md | 2 +- dist/triggers.js | 2 +- src/triggers.ts | 2 +- test/standard-webhooks-ids.test.mjs | 49 +++++++++++++++++++++++++++++ 4 files changed, 52 insertions(+), 3 deletions(-) create mode 100644 test/standard-webhooks-ids.test.mjs diff --git a/README.md b/README.md index 43366eb..a44f987 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ Use the URL with a Streamable HTTP MCP client. The catalog lists the supported a ## Incoming events and channels -The [generic signed webhook](catalog/triggers/webhook.yaml) uses Standard Webhooks. The `@checkfu/integrations/webhooks` export verifies native GitHub, Linear, and Notion deliveries and returns a verified event, account, and deduplication ID. The [Discord channel](catalog/services/discord.yaml) uses signed interactions. Its reply builder returns a standard Fetch request with redirects disabled through manual handling. The host sends the request and handles the response. +The [generic signed webhook](catalog/triggers/webhook.yaml) uses Standard Webhooks. The verifier returns the exact authenticated delivery ID. IDs are opaque, nonempty strings that exclude the signing delimiter (`.`). Apply the host's transport and storage limits when using them as idempotency keys. The `@checkfu/integrations/webhooks` export verifies native GitHub, Linear, and Notion deliveries and returns a verified event, account, and deduplication ID. The [Discord channel](catalog/services/discord.yaml) uses signed interactions. Its reply builder returns a standard Fetch request with redirects disabled through manual handling. The host sends the request and handles the response. Hosts own credential storage, replay protection, permissions, routing, and deployment. Each catalog surface describes what this library can provide to a host. [Standard Webhooks](https://www.standardwebhooks.com/) ยท [Discord interactions](https://docs.discord.com/developers/interactions/receiving-and-responding) diff --git a/dist/triggers.js b/dist/triggers.js index 67dd7a0..92e9acb 100644 --- a/dist/triggers.js +++ b/dist/triggers.js @@ -6,7 +6,7 @@ export async function verifyWebhookDelivery(body, headers, secret, nowMs = Date. const id = headers.get("webhook-id"); const timestamp = headers.get("webhook-timestamp"); const signatures = headers.get("webhook-signature"); - if (id === null || !/^[A-Za-z0-9_-]{1,128}$/u.test(id) || + if (id === null || id === "" || id.includes(".") || timestamp === null || !isFreshTimestamp(timestamp, triggers.webhook.toleranceSeconds, nowMs) || signatures === null || signatures.length > 1024 || !secret.startsWith("whsec_")) { diff --git a/src/triggers.ts b/src/triggers.ts index 9683ce5..7b82a63 100644 --- a/src/triggers.ts +++ b/src/triggers.ts @@ -20,7 +20,7 @@ export async function verifyWebhookDelivery( const timestamp = headers.get("webhook-timestamp") const signatures = headers.get("webhook-signature") if ( - id === null || !/^[A-Za-z0-9_-]{1,128}$/u.test(id) || + id === null || id === "" || id.includes(".") || timestamp === null || !isFreshTimestamp(timestamp, triggers.webhook.toleranceSeconds, nowMs) || signatures === null || signatures.length > 1024 || !secret.startsWith("whsec_") diff --git a/test/standard-webhooks-ids.test.mjs b/test/standard-webhooks-ids.test.mjs new file mode 100644 index 0000000..3b60347 --- /dev/null +++ b/test/standard-webhooks-ids.test.mjs @@ -0,0 +1,49 @@ +import assert from "node:assert/strict" +import { createHmac, randomBytes } from "node:crypto" +import { test } from "node:test" +import { verifyWebhookDelivery } from "@checkfu/integrations/triggers" + +const now = 1_800_000_000_000 +const timestamp = String(now / 1000) +const key = randomBytes(32) +const secret = "whsec_" + key.toString("base64") +const body = Buffer.from('{"action":"created"}\n') + +function signedHeaders(id) { + const signature = createHmac("sha256", key) + .update(`${id}.${timestamp}.`) + .update(body) + .digest("base64") + return new Headers({ + "webhook-id": id, + "webhook-timestamp": timestamp, + "webhook-signature": "v1," + signature, + }) +} + +test("Standard Webhooks returns the exact authenticated opaque identifier", async t => { + for (const [label, id] of [ + ["underscore and hyphen", "delivery_2-1"], + ["colon", "account:receipt:1"], + ["slash", "batch/receipt/1"], + ["128 characters", "a".repeat(128)], + ["129 characters", "a".repeat(129)], + ["1024 characters", "a".repeat(1024)], + ]) { + await t.test(label, async () => { + const headers = signedHeaders(id) + assert.equal(await verifyWebhookDelivery(body, headers, secret, now), headers.get("webhook-id")) + }) + } +}) + +test("Standard Webhooks declines missing, empty, delimited, and unauthenticated identifiers", async () => { + const missing = signedHeaders("receipt") + missing.delete("webhook-id") + assert.equal(await verifyWebhookDelivery(body, missing, secret, now), null) + assert.equal(await verifyWebhookDelivery(body, signedHeaders(""), secret, now), null) + assert.equal(await verifyWebhookDelivery(body, signedHeaders("receipt.1"), secret, now), null) + const altered = signedHeaders("account:receipt:1") + altered.set("webhook-id", "account:receipt:2") + assert.equal(await verifyWebhookDelivery(body, altered, secret, now), null) +})