Skip to content

fix: accept a confirmation token with its prose formatting attached - #250

Merged
bardesss merged 1 commit into
mainfrom
fix/confirm-token-trim
Sep 14, 2026
Merged

bardesss merged 1 commit into
mainfrom
fix/confirm-token-trim

Conversation

@bardesss

Copy link
Copy Markdown
Owner

Problem

#249 moves the confirmation token into the preview's content text, which is the right fix for clients that never forward structuredContent. 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.

To apply this, call delete_media again with the same arguments plus confirm set to v1.mu19umat.jIpG3egWkO8E5DG3qoSHDK1yU9_QVEMmyJzpBCoZ0vk.

verifyAndConsume parsed its argument with a bare presented.split('.') and no trimming, so anything short of a byte-exact copy was refused. Measured against #249's branch:

exact              applied
with backticks     malformed
trailing period    malformed
leading space      malformed
quoted             malformed
trailing newline   mismatch

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() in src/core/confirm.ts strips 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:

  • seven wrappings of a valid token all verify (backticks, trailing period, both together, leading space, trailing newline, double quotes, single quotes with a comma)
  • a wrapped token issued for a different target is still refused, so stripping cannot launder one
  • a token spent in its wrapped form reports used when the bare form is replayed

The 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.md is untouched, so this does not conflict with #249.

The three gates

> arr-mcp@1.26.4 lint
> eslint .

> arr-mcp@1.26.4 typecheck
> tsc --noEmit

 Test Files  103 passed (103)
      Tests  2679 passed (2679)

What was exercised

Harness tests only, plus the before-and-after measurement above run against the real registerWriteTool and ConfirmTokens. Not run against a live stack. The change is confined to one pure string function and the single call site that feeds split('.').

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

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>
@bardesss
bardesss merged commit 1d654a1 into main Sep 14, 2026
2 checks passed
@bardesss
bardesss deleted the fix/confirm-token-trim branch September 14, 2026 13:51
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>
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