Scope the reused x402 payment signature to tools the server charges for - #368
Merged
Conversation
Follow-up to #365, which made the challenge-signed payment reach the retry by checking the cache before the tool metadata gate. That also attached the session signature to every tools/call, including free tools, handing a live authorization to calls that never asked for one. The cache now records which tools the server actually charged for (a payment-required tool result, or an HTTP 402 on a tools/call), and the signature is reused only for those. Session-level reuse across paid calls is unchanged — mcp.apify.com treats the signature as a prepaid token (#247). Also adds the CHANGELOG entry the fix was missing. Refs #365, #343, #247 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01YFNAoYc88jVSqaj86VdTUJ
epistemedeus
approved these changes
Aug 11, 2026
epistemedeus
left a comment
Contributor
There was a problem hiding this comment.
Reviewed the result-challenge and HTTP 402 paths. The paymentRequiredTools scope closes cached-authorization spillover to free and unknown tools without reintroducing the retry failure from #365. The new tests cover those boundaries and preserve the documented prepaid-session reuse behavior. Looks good.
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.
Follow-up to #365 (thanks @epistemedeus — the diagnosis there was right and the fix is correct). Checking the cache before the tool-metadata gate also means the session's payment signature is now attached to every
tools/call, including free tools, handing a live authorization to calls that never asked for one. The cache now records which tools the server actually charged for, and reuses the signature only for those.X402PaymentCache.paymentRequiredToolsrecords a tool on a payment-required tool result (bridge) or an HTTP 402 on atools/call(middleware)_meta.x402or a previous charge; proactive signing still requires_meta.x402Refs #365, #343, #247
https://claude.ai/code/session_01YFNAoYc88jVSqaj86VdTUJ
Generated by Claude Code