Repository navigation
feat(webhook): verify Seamless webhook signatures in core and the Node adapters - #279
Merged
Merged
Conversation
…e adapters Adds verifyWebhook on @seamless-auth/core/webhook (Standard Webhooks v1, constant-time comparison, 300 s tolerance both ways, two secrets while rotating, raw bytes only, typed with WebhookEventSchema after the signature verifies) and wraps it in requireWebhook for Express, the seamlessWebhook plugin for Fastify, and createWebhookHandler and verifyWebhookRequest for Next.js. Core and the Next.js adapter move to @seamless-auth/types 0.39.0. Closes #269
Bccorb
marked this pull request as ready for review
November 8, 2026 03:30
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.
Closes #269.
What it adds
@seamless-auth/core/webhook:verifyWebhook(rawBody, headers, { secret }),WebhookVerificationError(with areason), and the header constants. Standard Webhooks exactly as the API signs (seamless-auth-apisrc/lib/calloutSigning.tsonfeat/signed-webhooks): HMAC-SHA256 of${webhook-id}.${webhook-timestamp}.${rawBody}, keyed with the base64 afterwhsec_, one or more space-separatedv1,<base64>entries inwebhook-signature.timingSafeEqual), with every secret checked against everyv1entry and no early exit.@seamless-auth/types/webhook/constants.v1signature (unsupported_version). Unknown versions beside av1entry are ignored.whsec_plus canonical base64, or more than two, throwsTypeError.TypeError.WebhookEventSchemaonly after the signature verifies; a signed body that is not a known event isinvalid_payload.@seamless-auth/express/webhook):requireWebhook(options)middleware. It reads the body withexpress.raw(any content type), puts the typed event onreq.webhook, answers400 { error: "invalid_webhook", reason }, and passes aTypeErrortonextifexpress.json()already parsed the body.@seamless-auth/fastify/webhook):seamlessWebhookplugin serving one route, with a buffer content type parser in its own encapsulated context so the rest of the app keeps JSON parsing.@seamless-auth/nextjs/webhook):createWebhookHandler({ secret, onEvent })forroute.ts, andverifyWebhookRequest(request, options). Both readrequest.arrayBuffer().verifyWebhookandWebhookVerificationError.@seamless-auth/nextjsmove from@seamless-auth/types^0.38.0to^0.40.0.Depends on
fells-code/seamless-auth-api#580 (
feat/signed-webhooks), which is open and not released. The API release is held (fells-code/seamless-auth-api#566), so this has not been tested against a real delivery. The tests sign the way that branch's signer does.Tests
hmacand pinned in the test.request.text()would break.bundlerand NodeNext.dist/webhook.js: 18 mutants of core (constant-time compare, early exit, no tolerance, one-direction tolerance, timestamp format, missing header, repeated or empty header, malformed entry, unknown version accepted, unsupported version reason, signature length check, first secret only, more than two secrets, secret prefix, canonical base64, parsed body re-serialized, schema parse skipped, signature check skipped) and 3 of the adapters (Expressexpress.jsonin place ofexpress.raw, Fastify withoutremoveAllContentTypeParsers, Next.jsrequest.text()). Every one fails at least one test.Checks (at 344e643)
pnpm install --frozen-lockfile(after committing the lock): done, lockfile up to date.pnpm check:types-current:@seamless-auth/coreand@seamless-auth/nextjs^0.40.0are current (latest 0.40.0).pnpm test(builds every package, then runs jest): core 47 suites, 769 tests passed; express 39 suites, 561 passed; fastify 15 suites, 578 passed; nextjs 13 suites, 692 passed.node scripts/check-adapter-manifest.mjs: bundled manifest matches, 143 routes.Not run