Skip to content

[COMMEX-2359] Harden platform webhook verification - #1544

Open
jolinger-godaddy wants to merge 1 commit into
godaddy:mainfrom
jolinger-godaddy:COMMEX-2359-webhook-verify
Open

jolinger-godaddy wants to merge 1 commit into
godaddy:mainfrom
jolinger-godaddy:COMMEX-2359-webhook-verify

Conversation

@jolinger-godaddy

Copy link
Copy Markdown

Jira

https://godaddy-corp.atlassian.net/browse/COMMEX-2359

This hardens verifyWebhookSubscription so apps can rely on it for platform event deliveries instead of each one rolling its own check.

What changes:

  • The signature is compared in constant time, over the exact body bytes (Buffer, ArrayBuffer or string). Before, it was a plain string compare, and a parsed body was re-serialized with JSON.stringify, which can differ from what was signed.
  • webhook-signature can hold a space-separated list of v1, signatures, so a secret rotation can sign with both. Any match passes. The tag is read in either case; the platform sends V1,.
  • New strictRawBody option refuses a body that isn't raw instead of falling back to JSON.stringify. The Express and TanStack webhook middleware turn it on by default. Express reads req.rawBody (an express.json({ verify }) hook) or a Buffer req.body from express.raw(); a string express.text() decoded doesn't count. TanStack now reads the body as bytes, so a byte-order mark is kept. Direct calls and the Next.js export stay lenient unless you pass strictRawBody: true, and the README has a Next.js webhook example that does.
  • New toleranceSeconds option, off by default. The platform's retry timing isn't documented, and a retry refused as too old would be lost.
  • The app's own problems (raw body lost or unreadable, no secret, bad options, or an unexpected failure inside verification, now WEBHOOK_VERIFICATION_FAILED) get a 500 with a generic body, even with strict mode off, so the platform keeps retrying while the app gets fixed. The detail is logged under the same correlation id, at error level the first time for each kind and at debug after that. A missing secret used to come back as a 401 bad signature.
  • webhookFailureStatus and webhookFailureBody are exported, so a handler calling verifyWebhookSubscription directly (like the Next.js example) can answer the same way the middleware does.
  • Repeated or comma-joined webhook-id/webhook-timestamp headers use the first value. Only the signature header is treated as a list.
  • Logs no longer include the request, since the body can hold shopper data. I also removed the old unused webhook verifier in verification.ts and updated the AGENTS.md note about it.

The strict default is a behaviour change for Express apps that only use an app-wide express.json(). The changeset says what to change, and strictRawBody: false keeps the old fallback. It's a minor because the package is still pre-production in practice.

Testing: new unit tests cover a known vector (the same signature this verifier accepted before), tampered body, id and timestamp, reordered JSON, a byte-order mark, signature lists (including Node's ", " join), strict mode, tolerance on both sides, and the Express and TanStack adapters. pnpm --filter @godaddy/app-connect test, typecheck, lint and build pass.

No dependencies. The once-only helper (COMMEX-2324) and the event handler build on this.

verifyWebhookSubscription now compares in constant time, signs the exact
body bytes, accepts a space-separated list of v1 signatures, and gains a
strictRawBody option and an optional toleranceSeconds (off by default).
The Express and TanStack webhook middleware turn strictRawBody on; Express
reads req.rawBody when kept. Setup problems (raw body lost, no secret) are
answered with 500 instead of 401.
@jolinger-godaddy
jolinger-godaddy requested a review from a team as a code owner November 23, 2026 22:24
@changeset-bot

changeset-bot Bot commented Nov 23, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 4554d50

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@godaddy/app-connect Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

⌂ Proxy