Repository navigation
fix: accept a confirmation token with its prose formatting attached - #250
Merged
Merged
Conversation
The preview text names the token inside backticks and ends the sentence
with a period, so a caller lifting it out of the text often sends back
`v1.…`. or v1.…. rather than the token. verifyAndConsume parsed the
argument with a bare split('.'), so every one of those was refused as
malformed — and the refusal reissues a fresh token presented exactly the
same way, so a caller that mis-clips once never converges.
Measured before the fix: backticks, a trailing period, a leading space
and surrounding quotes all report `malformed`; a trailing newline
reports `mismatch`. Only the byte-exact string applied.
unwrap() strips whitespace, surrounding backticks or quotes, and
trailing punctuation before parsing. None of those can occur in a
`v1.<base36>.<base64url>` token, so nothing about the check relaxes: the
HMAC still decides, and the stripped form is what the single-use set
records, so punctuation cannot be used to replay a spent token.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This was referenced Sep 14, 2026
bardesss
added a commit
that referenced
this pull request
Nov 6, 2026
…250) The preview text names the token inside backticks and ends the sentence with a period, so a caller lifting it out of the text often sends back `v1.…`. or v1.…. rather than the token. verifyAndConsume parsed the argument with a bare split('.'), so every one of those was refused as malformed — and the refusal reissues a fresh token presented exactly the same way, so a caller that mis-clips once never converges. Measured before the fix: backticks, a trailing period, a leading space and surrounding quotes all report `malformed`; a trailing newline reports `mismatch`. Only the byte-exact string applied. unwrap() strips whitespace, surrounding backticks or quotes, and trailing punctuation before parsing. None of those can occur in a `v1.<base36>.<base64url>` token, so nothing about the check relaxes: the HMAC still decides, and the stripped form is what the single-use set records, so punctuation cannot be used to replay a spent token. Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
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.
Problem
#249 moves the confirmation token into the preview's
contenttext, which is the right fix for clients that never forwardstructuredContent. It leaves one edge behind.The token is now delivered as prose: wrapped in backticks, with the sentence's period right after the closing one.
verifyAndConsumeparsed its argument with a barepresented.split('.')and no trimming, so anything short of a byte-exact copy was refused. Measured against #249's branch:The rejection branch then reissues a fresh token and presents it the same way, backticks and trailing period included. So a caller that consistently clips one character past the token never converges. That is the same nine-previews-all-unconfirmed loop #249 reports, reached by a different route.
Fix
unwrap()insrc/core/confirm.tsstrips whitespace, surrounding backticks or quotes, and trailing punctuation before the token is parsed. It runs in a loop so a token that is both wrapped and followed by a period comes out clean.Nothing about the check relaxes. None of those characters can occur inside a
v1.<base36>.<base64url>token, the HMAC still decides, and a wrong or forged token fails exactly as before. The stripped form is what the single-use set records, so punctuation is not a way to replay a spent token.Tests
test/confirm.test.ts, three cases, all written before the fix and watched to fail:usedwhen the bare form is replayedThe first drives a stopped clock, because the same intent signed in the same millisecond produces the same token and the previous iteration already spent it.
Docs
One bullet in
docs/security.md, the page that owns the handshake's mechanism.docs/writes.mdis untouched, so this does not conflict with #249.The three gates
What was exercised
Harness tests only, plus the before-and-after measurement above run against the real
registerWriteToolandConfirmTokens. Not run against a live stack. The change is confined to one pure string function and the single call site that feedssplit('.').Merge order
Independent of #249, no overlapping files. Worth landing in the same release, since on its own #249 still loses to a mis-clipped token and on its own this fixes a path that nothing reaches yet.
🤖 Generated with Claude Code