A Spend Cap Is Not a Price Check: x402 Clients and Price Expectations
An x402 client pays whatever the 402 says, up to a cap. The cap limits how much you can lose. It does not tell you whether the price is right. A seller that quotes ten times the usual amount, or swaps the recipient, passes every default check.
We showed in our audit of the $1 default cap that spend controls fail closed on size. This post asks the next question. What does the client do when the amount is small, plausible, and wrong?
We ran the published @x402/core 2.30.0 (npm, modified 4 November 2026) with a real EIP-3009 signer and a counter on the signer boundary. Then we read the open fix, PR #3920, and its review thread, plus a small related fix for MCP, PR #4150.
The report that started it
Issue #3866 was opened on 21 October 2026 against @x402/fetch 2.28.0. The reporter ran an adversarial seller on Base Sepolia that quoted ten times the canonical price. In three of three sessions the client signed an EIP-3009 transferWithAuthorization for the inflated amount. The only guard that engaged was the caller's spend limit, and a tenfold hike of a cheap resource sits well under any sane limit.
A reviewer in the thread made two points worth keeping. First, a mocked settlement proves the client signed and handed over an authorization. It does not prove an on-chain overpayment. Second, "a spending cap and an agreed price are different rules". A seller's own "canonical price" label is not an independent expectation the client can enforce. Whatever check we build needs an expectation that comes from the caller.
The issue is still open, with 29 comments.
What the default client does
Our harness registers the real ExactEvmScheme with a throwaway key on eip155:84532 and wraps createPaymentPayload to count signer calls. The seller's expected price is 0.01 USDC (10,000 atomic units) to a fixed recipient. We feed the client a series of 402 bodies. Every row below is a real run, on 2026-11-06.
// @x402/core 2.30.0 + @x402/evm 2.30.0, default spend controls
default cap: 0.01 USDC (expected) SIGNED signerCalls+= 1
default cap: 0.10 USDC (10x hike) SIGNED signerCalls+= 1
default cap: 0.99 USDC (99x hike) SIGNED signerCalls+= 1
default cap: 1.01 USDC REJECTED signerCalls+= 0 (spendControls.maxAmountPerPayment $1)
default cap: 0.00 (zero amount) SIGNED signerCalls+= 1
default cap: 0.01 to attacker payTo SIGNED signerCalls+= 1
The cap does exactly what it says. At 1.01 USDC the signer never runs. At 0.99 USDC, a 99x hike, it runs and produces a valid authorization. A different recipient at the right price also signs. The client has no notion of "who should I be paying" or "what did I agree to".
The hook that already exists
The client has had an escape hatch for this. onBeforePaymentCreation receives the paymentRequired and the selectedRequirements, and may return { abort: true, reason } before any payload is built. We wrote the check a careful buyer would write: compare amount, recipient, asset and network against a tuple the caller supplied out of band.
const guarded = () => base().onBeforePaymentCreation(async (ctx) => {
const r = ctx.selectedRequirements;
if (r.amount !== EXPECT.amount || r.payTo.toLowerCase() !== EXPECT.payTo
|| r.asset.toLowerCase() !== EXPECT.asset.toLowerCase() || r.network !== EXPECT.network)
return { abort: true, reason: `expectation_mismatch ...` };
});
hook: 0.01 USDC (expected) SIGNED signerCalls+= 1
hook: 0.10 USDC (10x hike) REJECTED signerCalls+= 0
hook: 0.001 USDC (price drop) REJECTED signerCalls+= 0
hook: 0.01 to attacker payTo REJECTED signerCalls+= 0
Rejected means the signer ran zero times. Nothing exists that could settle. The hook is enough. The gap is deployment: every client has to register it, the issue reports that the official fetch example does not demonstrate it, and the example PR that would, #3799 (a listing check), is still open. A commenter in the thread put it plainly: an aborting hook enforces, the problem is that registration is opt-in.
Note the price-drop row. We reject a lower amount too. A mid-session drop is the bait a patient seller uses before a later hike, and a zero amount is its own bug class (the thread links #3660, "Amount validation as exact law").
PR #3920: move the check into the client
PR #3920 by gobeyondfj-cmd puts the expectation inside x402Client spend controls, so it is on by default once configured and does not depend on a hook. At head e993bef (7 commits, 1,179 additions, 9 deletions, updated 5 November) it adds three fields.
expectedAmount
Either a Money value or "first-accepted", default false. With a value, every offer must match it, converted to atomic units with the asset's default decimals. With "first-accepted", the first payload the client successfully creates for a quote key becomes the anchor, and later drift is rejected.
expectedAmountTolerance
A multiplier, default 1.0, must be at least 1.0. It applies in both directions: an offer above expected * tolerance or below expected / tolerance is a mismatch. The author's reasoning matches ours: a price drop is the bait pattern.
expectedPayTo
Added after review. A recipient the caller approved, enforced whether or not an amount expectation is set. A mismatch throws QuoteMismatchError with field: "payTo" and source: "caller-config".
The quote key is the tuple resource URL, scheme, network, asset and payTo. A second ledger binds the first committed payTo per URL, scheme, network and asset, so a recipient swap on a known quote is rejected even in "first-accepted" mode. Rejections throw QuoteMismatchError, carrying the key, expected and offered values, and whether the anchor came from caller config or the quote ledger. If the offer cannot be evaluated at all, for instance a decimal-ledger amount or an asset with unknown decimals, a second error, QuoteExpectationUnsupportedError, fails closed rather than skipping the check.
The enforcement point is a third filter pass in applySpendControls, after the asset allow-list and the cumulative cap. A rejected quote never reaches the scheme client or the signer. The PR reports its core suite passing; we read the diff and the thread, we did not build the branch.
Four review rounds, four real gaps
The thread is worth reading as a specification exercise. Independent reviewers ran their own unsigned harnesses against successive heads and each found something.
- Recipient substitution. The first version compared only the amount. A reviewer whose own guard package,
@tanilo/x402-guard0.1.1, had compared the recipient only when the terms named one, and never asset or network, reported that gap in both places. The PR added the recipient ledger, thenexpectedPayTo. - Concurrent first calls. Ledgers were written after the awaited
createPaymentPayload, so two calls on a fresh client could both pass an empty-ledger check and reach the signer. Payload creation is now serialized per client through a promise chain, which makes check and record atomic. - Standalone
expectedPayTorejected decimal-ledger offers that it had no reason to evaluate. The unsupported-amount check now lives only inside the two amount branches. - Address case. Recipient comparison treated checksummed and lowercase EVM addresses as equal, but the quote key still used the raw string, so a case-only change slipped past a first-accepted anchor. One canonicalization function now serves both. A negative control that reverts only the key normalization fails, which proves the test is live.
The PR is open, mergeable, and shows REVIEW_REQUIRED with no formal review recorded. The scrutiny so far is community-driven. That is useful evidence, but it is not a maintainer decision.
What it still does not cover
The README of the PR is candid about the first limitation: "first-accepted" detects change, not correctness. If the first quote is already inflated, the client anchors on it. The explicit Money expectation is the strong mode, and it needs the caller to know the price.
The second limitation is a different threat. The thread shows reviewers separating two controls cleanly. Two identical concurrent calls both succeed, because identical offers are consistent. That is quote consistency, not idempotency. Duplicate payment on retry is the subject of our double-sign audit, and a price expectation does nothing for it.
Third, for an LLM-driven buyer the expectation itself can be derived from untrusted text. If the agent read the price from a page an attacker controls, a deterministic check compares the offer to a poisoned number. We covered the neighbouring surface in the payment-metadata injection audit. The expectation must come from configuration or a signed mandate, not from model output.
A smaller fix in the same family: PR #4150
MCP has a version of the same question. In @x402/mcp 2.30.0, after a paid call the server may return a corrective 402. If a scheme hook recovers local state, the client retries once. Reading the shipped source, the retry re-runs onPaymentRequested and the before-payment hooks with the corrective terms, then calls createPaymentPayload on the new 402.
PR #4150 ports the Python and Go behaviour: the retry signs the originally approved offer, passed in as approvedPaymentRequired, and approval runs against that same offer. The corrective 402 still reaches handlePaymentResponse so a scheme can recover. The effect is that a later 402 cannot change amount, asset or recipient after the human or policy said yes. It is tracked by drift issue #4147. We read both versions and did not run an MCP server against them.
What it means for LLM4Agents
We are the seller in this story, and our buyers are autonomous agents. Three consequences follow.
First, our quote is not a fixed price. The gateway computes the 402 amount per request from the model and an input-size estimate, as in our tokenizer-drift audit. An exact-match expectedAmount would reject our own honest quotes whenever a prompt length changes.
Second, and this is our reading of the diff, not a run: the quote key has no request-body component. Our endpoint URL is the same for every prompt. A client using "first-accepted" would anchor on the first prompt's price and reject the next one with a different length. The PR itself notes that ResourceInfo has no method field in v2. PR #3741, also open, would declare the paid HTTP method. Neither carries a body or a price class.
Third, the shape our buyers need is a ceiling per request plus a pinned recipient and asset, not an equality check. The recipient and asset binding is exactly what protects them from a look-alike gateway. The amount side should be a tolerance band or a per-request maximum they set from their own token budget.
Staying on the frontier
- Document the buyer-side guard today. Publish an
onBeforePaymentCreationsnippet in our integration docs that pinspayTo, asset and network from configuration, and caps amount per request. It works on 2.30.0 with no SDK change. - Pin our own recipient publicly. Put our payment addresses in a stable, signed place so buyers have an out-of-band source for
expectedPayTo. A pin is useless if buyers must copy it from the 402 itself. - Keep our quote monotone and explainable. Return the inputs of the estimate (model, token estimate, rate) in a response field, so a buyer can recompute a ceiling and see that a repeat call with the same prompt gives the same amount.
- Test our quotes against #3920. Build the PR branch, run
first-acceptedand a tolerance of 2 against varying prompts, and report the failure mode upstream if the key cannot carry a price class. Ask for a quote key that can include a buyer-supplied scope. - Keep the expectation out of the model's hands. In our agent templates, set the ceiling and recipient in configuration or a signed mandate, never from text the model read.
- Watch #3866, #3920, #3741 and #4150. The decision on whether price expectation is a default or an opt-in will shape every buyer SDK we integrate with.
Pay the price you agreed to
Register an agent on LLM4Agents and pay per request in stablecoins over an OpenAI-compatible gateway.
Register agent