fix(x402): bind signed payment to the approved payment option - #1404
Open
SashaMIT wants to merge 1 commit into
Open
fix(x402): bind signed payment to the approved payment option#1404SashaMIT wants to merge 1 commit into
SashaMIT wants to merge 1 commit into
Conversation
retry_http_request_with_x402 validates the user-approved payment option against the spending limit, but then calls wrapFetchWithPayment with a plain x402Client, which signs whatever payment requirements the server returns on the retry's 402. A registered service could present a cheap option at confirmation time and demand a larger amount (or different recipient) at retry time. Pass a payment-requirements selector into the x402Client: - retry path: selector accepts only requirements matching the approved option on network/asset/payTo at an amount not exceeding the approved amount; anything else throws before signing. - direct (no-confirmation) path: selector caps the signed amount at the configured maxPaymentUsdc, matching the limit the confirmation path already enforces. Made-with: Cursor
🟡 Heimdall Review Status
|
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.
Summary
retry_http_request_with_x402asks the user (or agent policy) to approve a specific payment option, validates that option againstmaxPaymentUsdc— and then signs whatever the server returns on the retry's 402, becausewrapFetchWithPaymentreceives a plainx402Clientwith the defaultaccepts[0]selector. The approved option is never enforced on the payload that actually gets signed.A registered service can therefore present a cheap option at confirmation time and demand a larger amount — or a different recipient — when the retry happens. The
maxPaymentUsdccheck gives false assurance because it runs against the approved option's amount, not the signed one.Fix
Pass a payment-requirements selector into the
x402Clientconstructor (the hook the x402 SDK provides for exactly this):retry_http_request_with_x402):createApprovedPaymentSelectoraccepts only requirements matching the approved option onnetwork/asset/payToat an amount not exceeding the approved amount; anything else throws before any signature is produced.http_request_with_x402, which by design skips user confirmation):createCappedPaymentSelectorrefuses requirements above the configuredmaxPaymentUsdc, so the provider's own spending limit also binds what actually gets signed there.Test plan
utils.selector.test.ts: matching requirement selected; inflated amount refused; swapped recipient refused; wrong network refused; v2pricefield handled; cap selector accepts-at/refuses-above the limittsc --noEmitclean; eslint/prettier cleanMade with Cursor