Repository navigation
[COMMEX-2359] Harden platform webhook verification - #1544
Open
jolinger-godaddy wants to merge 1 commit into
Open
jolinger-godaddy wants to merge 1 commit into
jolinger-godaddy wants to merge 1 commit into
Conversation
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.
🦋 Changeset detectedLatest commit: 4554d50 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Jira
https://godaddy-corp.atlassian.net/browse/COMMEX-2359
This hardens
verifyWebhookSubscriptionso apps can rely on it for platform event deliveries instead of each one rolling its own check.What changes:
JSON.stringify, which can differ from what was signed.webhook-signaturecan hold a space-separated list ofv1,signatures, so a secret rotation can sign with both. Any match passes. The tag is read in either case; the platform sendsV1,.strictRawBodyoption refuses a body that isn't raw instead of falling back toJSON.stringify. The Express and TanStack webhook middleware turn it on by default. Express readsreq.rawBody(anexpress.json({ verify })hook) or a Bufferreq.bodyfromexpress.raw(); a stringexpress.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 passstrictRawBody: true, and the README has a Next.js webhook example that does.toleranceSecondsoption, off by default. The platform's retry timing isn't documented, and a retry refused as too old would be lost.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.webhookFailureStatusandwebhookFailureBodyare exported, so a handler callingverifyWebhookSubscriptiondirectly (like the Next.js example) can answer the same way the middleware does.webhook-id/webhook-timestampheaders use the first value. Only the signature header is treated as a list.verification.tsand 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, andstrictRawBody: falsekeeps 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,lintandbuildpass.No dependencies. The once-only helper (COMMEX-2324) and the event handler build on this.