Repository navigation
fix(x402): cap the USDC the Go client signs per tool call - #19
Merged
Merged
Conversation
The x402 hook approved every payment request, so a server could ask for any amount and the client would sign it. Add Config.MaxPaymentPerCall (decimal USDC, default 0.05, also X402_MAX_PAYMENT_PER_CALL). Requests above it fail with ErrPaymentExceedsMax, and requests in another asset or on another network fail with ErrPaymentUnsupported. Nothing is signed in either case.
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.
Why
With an EVM key set, the Go client approved every x402 payment request. A server could ask for any amount (for example 1,000 USDC) and the client would sign it.
What
Config.MaxPaymentPerCall: the most USDC signed for one tool call, as a decimal string. Default"0.05"(DefaultMaxPaymentPerCall), twice the $0.025 per-call price. Also read fromX402_MAX_PAYMENT_PER_CALL.ErrPaymentExceedsMaxand nothing is signed.eip155:8453) fail withErrPaymentUnsupported, since the cap can't be compared in another asset.NewClientreturn an error (only when an EVM key is set).Tests
go test ./...adds unit tests for parsing and checking, plus tests against a local MCP server that asks for payment: 1,000 USDC is refused with no paid call, 0.025 USDC is paid once, and a custom 0.01 cap refuses 0.025.Compatibility
No API removed. Callers paying under 0.05 USDC per call see no change. Anyone relying on paying more must set
MaxPaymentPerCall.