Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion dist/triggers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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_")) {
Expand Down
2 changes: 1 addition & 1 deletion src/triggers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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_")
Expand Down
49 changes: 49 additions & 0 deletions test/standard-webhooks-ids.test.mjs
Original file line number Diff line number Diff line change
@@ -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)
})