Repository navigation
fix(svix): accept space-separated multi-signature headers - #3
Merged
Merged
Conversation
Svix sends every signature it holds during a signing-secret rotation,
separated by spaces: `v1,<old> v1,<new>`. Only one matches the secret the
receiver has, and the message must be accepted on that one.
The parser split the combined string on commas alone, so
`v1,AAA v1,BBB,t=..,id=..` became ['v1', 'AAA v1', 'BBB', ...]: the first
signature was captured as the literal `AAA v1` and the second was dropped,
because nothing preceding it equalled 'v1'. Result: every signature fails
for the whole duration of a rotation, on svix and on clerk, which
delegates to it.
The provider's own doc comment already documented the correct format
("multiple sigs v1,<sig1> v1,<sig2>"), so the intent was right and only
the parse was wrong. Split on commas AND whitespace; base64 contains no
whitespace, so this cannot split a signature.
Every existing svix and clerk test used a single signature, which is why
this branch was never exercised. Added six: the matching signature first,
last, and among three; none matching (so a parser that blindly accepted
multi-signature headers would not pass); tolerance still applying; and one
through the headers object, which is the path Clerk actually takes.
Verified by mutation: restoring the comma-only split fails exactly the
four acceptance tests and leaves the two rejection tests passing.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Mkd9oGgdMEFUftzCeiCfZw
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.
The bug
Svix sends every signature it holds during a signing-secret rotation, separated by spaces:
Only one matches the secret the receiver has, and the message must be accepted on that one.
svix.verifysplit the combined string on commas alone:So
v1,AAA v1,BBB,t=…,id=…becomes['v1', 'AAA v1', 'BBB', 't=…', 'id=…']:AAA v1— corrupted, never matchesBBBis skipped entirely, because the element before it isAAA v1, notv1Result: every signature fails for the whole duration of a rotation. It affects
svixandclerk, which delegates to it.Reproduced before fixing:
The fix
The provider's own doc comment already documented the correct format:
So the intent was right and only the parse was wrong. Split on commas and whitespace:
Base64 contains no whitespace, so this cannot split a signature in half. Single-signature headers parse exactly as before.
Why it survived
Every existing
svixandclerktest used a single signature —generateSvixSignatureonly ever produces one — so the multi-signature branch the comment describes had no coverage at all.Added six tests:
getSignature()is the path Clerk actually takes; the old tests passed a pre-joined string and bypassed itVerification
npm test— 117 pass, 0 failsplit(',')fails exactly the four acceptance tests and leaves the two rejection tests passing. A fix with no failing mutation would mean the tests prove nothing.Found by
Using this package in snill to replace a hand-rolled Clerk verifier (RestDB/snill#1647 — an unsigned webhook handler that had been shadowing the verified one). Snill works around it by passing one signature at a time; once this ships it can pass the header straight through.
🤖 Generated with Claude Code
https://claude.ai/code/session_01Mkd9oGgdMEFUftzCeiCfZw