Research
Free-Riding the Agentic Web: A Systematic Security Analysis of x402 Payments
x402 turns the dormant HTTP 402 "Payment Required" status code into a negotiation channel so software agents can pay for resources and AI inference automatically, and it has reached roughly 130…

- arXiv
- 2605.30998
- Published
- 2026-05-29
- Authors
- Shengchen Ling, Yihang Huang, Yuefeng Du, Yuan Chen, Yajin Zhou, Lei Wu, Cong Wang
AI summary
Overview
Research area: Security analysis of blockchain-backed payment protocols for AI agents (cs.CR), specifically the Coinbase-originated x402 protocol, with a secondary result in LLM inference pricing.
Technical level: Advanced. The paper assumes familiarity with HTTP semantics, EIP-712/EIP-3009 typed-data signing, ERC-20 allowances, race conditions (TOCTOU), and mechanism-design arguments about hidden compute.
Scope (one sentence): The paper defines five security invariants for x402, audits the protocol, its official SDKs, and live deployments against them, reports four concrete flaw classes with measured exploitation and resource-leakage ratios up to 100%, and proves an impossibility result for pay-per-token pricing over hidden "thinking" tokens.
What This Paper Is About
x402 turns the dormant HTTP 402 "Payment Required" status code into a negotiation channel so software agents can pay for resources and AI inference automatically, and it has reached roughly 130 million all-time transactions and native integration in Google AP2, Cloudflare Agents, Stripe, and AWS Bedrock. The protocol splits fast off-chain signature verification (done by a "Facilitator") from slow on-chain settlement, and the paper asks whether the deployed protocol, official SDKs, and operator configurations actually preserve the safety properties the specification, prior payment-security literature, and vendor documentation all imply. The goal is to attribute every violation to a responsible layer (protocol, SDK, or deployment), measure real exposure, and propose defenses with provable bounds.
Key Contributions
-
Five grounded security invariants plus a three-layer taxonomy. The authors distill invariants I1–I5 (payment integrity, value consistency, context binding, authorization uniqueness, execution conservation), each anchored in at least two of the x402 specification (or a canonical EIP), prior payment-security work, and vendor documentation, then assign every violation to the protocol, SDK, or deployment layer.
-
Four concrete flaw classes with in-the-wild exposure measurements. Cross-resource substitution (F1), duplicate-settlement race (F2), allowance overdraft on the
uptoscheme (F3), and denial of settlement (F4), each reproduced against official SDKs or a production deployment (Thirdweb's AI-inference service), and each reaching resource-leakage ratios up to 100%. -
A structural impossibility result for hidden-compute pricing (F5). The paper proves that no output-only pricing scheme can be simultaneously fair to honest users and bounded against inflation of hidden "thinking" tokens, with an unavoidable sqrt(1+Θ) manipulation gap; the bound generalizes to any pay-per-consumption protocol over a hidden-compute service, with estimated manipulation ratios of 35–3,213× across 10 production language models.
-
Layered defenses with provable guarantees. Per-flaw mitigations plus a "defense triple" that the authors report cuts per-call reasoning cost by 47% and inverts attacker leverage from 8.7× to 0.9× at only 2.8% overhead. All findings were disclosed to vendors.
Main Findings
-
F1 — Cross-resource substitution (protocol layer, violates I3). The signed authorization commits to merchant, value, nonce, and expiry but not to the resource identifier, so a "floating authorization" can be detached from resource r_a and re-attached to any equal-priced resource r_b. None of the four official Coinbase SDKs (TypeScript, Python, Java, Go) enforces a sound resource-binding check: TypeScript/Python match only on network and scheme (predicate incompleteness), Java compares the HTTP path against an unsigned JSON field (malleable metadata), and Go forwards blindly to the stateless Facilitator. In 100 controlled rounds the substitution succeeded in all 100.
-
F1 composition and exposure. Composed with the F2 race under concurrency, 48% of trials showed resource swapping and 6% showed full service duplication. A full pagination census of the CDP resource registry (24,875 resources, 915 merchants across 868 hosts) found 99.6% of merchants expose only the
exactscheme; 38% of hosts (331 of 868) expose same-price sibling clusters (median 3, maximum 178 resources), and 91 hosts expose at least 10 mutually substitutable resources under a single authorization. -
F2 — Duplicate-settlement race (SDK layer, violates I4). Because verification is decoupled from on-chain settlement, concurrent requests carrying the same nonce can all clear verification while only one settles. On the official CDP facilitator on Base mainnet, fifty rounds of 20 concurrent requests produced duplicate service delivery in 6% of rounds, with multiplicity ≤ 2 (two distinct HTTP 200 responses, one settlement). Third-party confirmation is cited: Issue #1062, and Issue #1805 reporting a 5-concurrent-request incident where 4 requests received the same settlement proof; a partial SVM-side fix (PR #1468) adds a 120-second in-memory deduplication cache.
-
F2 is invisible on-chain and highly concentrated. Settlement records show a ≈0.02% failure rate and zero duplicate nonces, and the chains x402 uses run centralized sequencers with no public mempool. One facilitator operator relays settlement for 195 of 263 active Base merchants (74%), so a single facilitator fault has ecosystem-wide reach.
-
A settlement-gate omission (violates I1). The official Python Flask adapter gates settlement on a 2xx status, so a 302 redirect — the standard CDN/object-storage delivery pattern — is served without settlement and the nonce is never consumed. Of nine first-party adapters across four languages, Flask is the sole outlier; the other eight gate on status < 400.
-
F3 — Allowance overdraft on
upto(protocol layer, violates I2 and I5). Underupto, authorization is a spending cap with no per-deduction nonce, and verification is a non-binding snapshot check of remaining allowance against a safety floor (1,000 wei in Thirdweb's setting). An adversary with allowance V ≥ C_min launches N concurrent requests whose aggregate cost far exceeds V; all clear verification against the same snapshot, all outputs stream, and only the first k settle. On Thirdweb'sx402-ai-inferencedeployment (Arbitrum One), a 50-request burst against a 10,000-wei allowance delivered 47,277 tokens (= 47,277 wei) but settled only 4 (1,057 wei), a leakage ratio ρ = 97.76%. The deterministic long-context variant drives ρ toward 100%, and the reversion never decrements the allowance, leaving it replayable to the 24h default signature expiry. -
F3 serial replay. A $1.00 authorization at $0.01 per call yields up to 99 unauthorized calls at approximately zero cost-to-damage, reproduced in 10/10 trials; a passive network observer who captures the header can do the same. In the wild,
uptois rare — 39 declared resources, 0.79% of de-duplicated resources, across 8 merchants — but probing all 39 live-confirmed 16, concentrated in one merchant servingupto-priced, OpenAI-compatible AI inference. -
F4 — Denial of settlement (deployment layer, violates I1 and I5). The default third-party template imposes a settlement rate limit L_settle = 10 tx/s while provisioning verification far higher (L_verify ≫ L_settle). A burst above 10 req/s is fully verified and delivered, then rejected with 429 Too Many Requests at settlement, so the merchant delivers free service. A client-driven variant: disconnect the TCP stream after consuming output and before the merchant's
onFinishsettlement callback fires — disconnecting after 500 streamed tokens evaded settlement in the reported experiment (the text is truncated at this point). -
F5 — Hidden-compute pricing impossibility (deployment layer, violates I2 and I5). Pay-per-token inference on
uptoforces a verify-execute-settle workflow, making the merchant an unsecured creditor because cost is unknown until generation ends. The paper proves no output-only price can be both fair and bounded against hidden-token inflation, with a sqrt(1+Θ) manipulation gap, and estimates 35–3,213× manipulation ratios across 10 production language models. -
Context and defenses. Related hidden-compute work cited includes CoIn (94.7% detection of reasoning-token audits), BadThink (17× chain-of-thought inflation), and the BAR trilemma. The proposed defense triple reportedly cuts per-call reasoning cost by 47% and reduces attacker leverage from 8.7× to 0.9× at 2.8% overhead; a bounded front-running residual (g_front) from sequencer-side ordering is acknowledged as something no deployment defense closes.
Methodology in Plain English
The authors start from the specification, prior payment-security papers, and vendor documentation and derive the properties a correct x402 deployment must hold — then test the real system against them. They treat x402 not as one artifact but as a stack: a rail-agnostic HTTP convention, per-chain schemes (EIP-3009 exact on EVM, Solana-native signatures, the upto allowance extension), and a long tail of SDK and operator choices. Each flaw is then pinned to whichever layer is responsible, so readers can tell whether a bug survives a clean reimplementation.
Evidence comes from three directions: (1) code audit of the four official Coinbase SDKs and nine first-party server adapters, with each failure reduced to a short pseudocode pattern; (2) controlled reproduction — a self-run merchant, a self-run CDP facilitator on Base mainnet, and the Thirdweb production AI-inference deployment, with concurrency bursts and repeated trials and all economic impact internalized; (3) an exposure census of the CDP resource registry via full pagination traversal, plus passive HTTP 402 probing of live endpoints. For the pricing result they give a proof, adopting an entropy-projection method from prior work. They disclosed findings to vendors, and separate the adversary classes: a malicious shopper acting at machine speed, a passive header observer, and a chain-layer adversary capable of sequencer ordering.
Why This Matters
Impact on research. The paper extends the classic tri-party "Cashier-as-a-Service" abstraction to a four-principal system with an asynchronous blockchain and a stateless Facilitator, and it converts vague "spec ambiguity" complaints into an explicit protocol/SDK/deployment taxonomy that other payment-protocol analyses can reuse. The impossibility result moves hidden-compute billing from an engineering nuisance into a provable structural limit.
Real-world applications:
- Agent marketplaces and API providers: operators deploying the standard x402 template inherit the 10 tx/s settlement cliff and the Flask 302 gate, so the paper reads as a configuration checklist for anyone monetizing agent traffic.
- Facilitator operators: the finding that one operator relays settlement for 195 of 263 active Base merchants (74%) makes facilitator idempotency and deduplication an ecosystem-level reliability concern, not a per-merchant one.
- AI inference resellers: the Thirdweb measurement (97.76% leakage on a 50-request burst) shows
upto-priced inference is directly exploitable by ordinary concurrency. - Wallet and SDK maintainers: the four SDK failure patterns give concrete patch targets, and the eight-of-nine adapter comparison shows the correct gating pattern already exists in the same codebase.
Industry relevance. With roughly 130 million all-time transactions, 98.8% of EVM dollar volume in USDC, and native integration in Google AP2, Cloudflare Agents, Stripe, and AWS Bedrock, x402's flaws propagate into commercial stacks. The third-party incident reports cited (including one where 4 of 5 concurrent requests received the same settlement proof) indicate the analysis is being validated in production, and several findings already have partial fixes merged.
Future Directions
- Closing the front-running residual. The authors state that sequencer-side ordering leaves a bounded residual (g_front) that no deployment defense closes; designing mitigations that survive a chain-layer adversary remains open.
- Enforcing context binding at the protocol layer. Since the resource field is not inside the EIP-712 signed payload, binding is currently a per-SDK obligation that all four official SDKs fail; moving the resource into the signed tuple would remove the class rather than patch it.
- Pricing mechanisms for hidden compute. The sqrt(1+Θ) gap invites follow-up on verifiable reasoning-token accounting or commitment schemes that could shrink the gap below the proven bound.
- Validation beyond the observed deployments. The
uptocensus found only 39 declared resources across 8 merchants and the substitution census covers one registry, so the empirical floor could shift as dynamic pricing spreads and as newer SDK versions land.
Target Audience
Protocol and payment-security researchers; engineers building or operating x402 resource servers, facilitators, and agent wallets; AI-inference providers billing per token; and platform teams at companies integrating agentic payments (Cloudflare, Stripe, Google AP2, AWS Bedrock). It is most valuable to readers with enough blockchain and HTTP background to follow EIP-3009 nonce semantics and concurrency reasoning; beginners can read the flaw table and the plain-language impact sections but will struggle with the proofs.
Authors’ abstract
The x402 protocol has crossed from prototype to infrastructure for the agentic web, driving 130 million all-time transactions and embedded in Google Cloud, Cloudflare, and Stripe. Yet bridging synchronous HTTP requests with asynchronous blockchain finality creates state-synchronization challenges, and x402's security has so far been examined only in piecemeal vendor disclosures. It is moreover not one artefact but a stack of an HTTP semantic, per-chain schemes, and a long…
The full abstract on arXiv