Research
Five Attacks on x402 Agentic Payment Protocol
x402 revives the long-reserved HTTP 402 Payment Required status code so that APIs, content, and AI agents can pay each other natively over the web — an agent requests a resource, receives a price…

- arXiv
- 2605.11781
- Published
- 2026-05-12
- Authors
- Zelin Li, Qin Wang, Zhipeng Wang
AI summary
Overview
Research area: Blockchain payment protocols and web security — specifically the security of agentic, HTTP-native micropayment protocols (x402) that bridge synchronous web authorization and asynchronous on-chain settlement.
Technical level: Advanced. The paper combines a formal system model (entities, adversary capability classes, four security definitions, theorems with probability bounds) with an empirical testbed study. The attack narratives themselves are readable for intermediate readers, but the security-property section assumes comfort with probabilistic reasoning and blockchain finality concepts.
Scope: A formal and empirical security analysis of the x402 payment protocol, presenting five concrete attacks across four classes, a reproducible testbed evaluation, an audit of three open-source SDKs and four live endpoints, and proposed mitigations.
What This Paper Is About
x402 revives the long-reserved HTTP 402 Payment Required status code so that APIs, content, and AI agents can pay each other natively over the web — an agent requests a resource, receives a price quote such as 0.01 USDC on Base, signs a payment payload, and the server releases the resource after an off-chain facilitator verifies and settles the payment on chain. The problem is that this design fuses two layers with fundamentally different guarantees: HTTP decides in milliseconds, while a blockchain only offers probabilistic finality that a reorganization can undo. The paper's goal is to formalize the trust boundaries in x402, demonstrate concrete attacks that exploit them, measure how practical those attacks are on real chains and live deployments, and propose mitigations that preserve x402's web-native usability.
Key Contributions
-
A formal security abstraction for x402. The authors model the system as a tuple of clients, resource servers, facilitators, blockchain, network, time, and security parameter; define the message formats for
PaymentRequirementsandPaymentPayload; and abstract four security properties — authorization soundness, payment–service correspondence, replay resistance, and facilitator k-atomicity — with accompanying theorems (Theorems 6–9) and a confirmation-depth corollary. -
Five attacks organized into four classes, each with measurable indicators. These cover settlement-path inconsistencies (I-A revert-grant under optimistic execution, I-B unauthorized settlement preemption), replay/idempotency failures (II), header/proxy confusion (III), and agent server-selection manipulation (IV). Each is specified with violation events, adversary capability sets, and quantitative metrics such as revert-grant probability (RGP) and duplicate-grant rate (DGR).
-
A reproducible testbed and quantitative evaluation. Over 25,000 payment requests across 48 configurations on Hardhat/Anvil and Base Sepolia, supplemented by validation on four production x402 endpoints, with 95% Wilson score confidence intervals reported for rate metrics.
-
A systematic multi-implementation audit and responsible disclosure. Three open-source x402 SDKs and four live endpoints were audited, yielding 11 vulnerabilities across five classes with severity ratings, and findings were privately reported to Coinbase via HackerOne (#3679163, #3679179, #3679220). The authors also propose mitigations including canonical encoding, two-phase settlement, mandatory idempotency with resource binding, and caching hygiene.
Main Findings
-
All five attacks are practical. Validation on local chains, Base Sepolia, and live endpoints showed every attack class succeeds, producing either unpaid service (the resource is delivered but settlement fails) or paid-but-denied outcomes (the payer is charged but receives nothing).
-
Revert-grant succeeds even with honest facilitators. Under optimistic execution, the revert-grant probability measured RGP₀ of up to 5.18% with honest facilitators; with a Byzantine facilitator it reached 100%.
-
Settlement preemption is cheap and caller-unbound. Because the settlement path does not bind the facilitator identity to the authorization — any observer can submit first under EIP-3009, and Permit2 lacks a facilitator field or caller check — an attacker consumes the nonce and the legitimate settlement fails. On Base Sepolia, preemption yields an HTTP 402 to the paying client.
-
Replay is a one-to-many failure. Without a pre-grant idempotency check, DGR = n for n replays of the same payload; on a live deployment, one payment produced 248 grants while the blockchain accepted only one settlement. The paper frames this as an ordinary web idempotency bug made expensive by attached money.
-
Ordinary web infrastructure leaks paid content. Header/proxy confusion produced a 100% leak rate through nginx configuration, and a live CDN leak was observed end-to-end; header ambiguity is described as a deployment-dependent parser risk.
-
Agents can be steered before payment begins. In Bazaar-style discovery, a single crafted resource server captured 71.8% of selections, and five Sybil servers captured 60.2%.
-
Theory clarifies when the protocol holds. Under conservative execution (grant only after k confirmations) with an honest facilitator and k-deep chain finality, the authorization-soundness failure probability is bounded by ε_chain(k); optimistic execution violates it (Theorem 7); absence of pre-grant uniqueness enforcement gives replay with probability 1 (Theorem 8); and a non-k-atomic facilitator defeats even conservative servers (Theorem 9).
-
Concrete confirmation-depth guidance. For Base (average block time T_b ≈ 2 s, ε_chain(k) ≈ e^(−αk)), the authors recommend k ≥ 3 for resources valued below $1 (target failure < 10⁻²) and k ≥ 12 for resources above $10 (target failure < 10⁻⁴).
-
Real SDKs and endpoints miss the preconditions. The audit found grant-before-settle behavior in a third-party Python SDK, missing resource-identifier binding, fire-and-forget settlement, and absent
Cache-Controlheaders — 11 vulnerabilities across five classes. -
Note on coverage: the supplied paper text is truncated partway through the Attack II procedure, so the step-by-step procedures, adversary details, and per-attack measurements for Attack III and Attack IV appear here only as reported in the abstract and Table 1; fuller detail is not present in the provided content.
Methodology in Plain English
The authors worked in three layers. First, they built a formal model: they listed every party in an x402 exchange (client, resource server, facilitator, blockchain, plus the network and its caches and proxies), wrote down the exact messages exchanged, and defined what an attacker is allowed to do — delay or replay network traffic, corrupt clients, corrupt facilitators, reorder transactions in the mempool within chain finality limits, or run an honest-but-curious server. Against this model they defined four properties a secure payment protocol should have, then proved theorems showing which execution policies preserve them and which break them.
Second, they turned each formal failure event into a runnable attack. Attack I-A exploits granting before finality (the server treats a mempool sighting or shallow inclusion as durable payment, then a reorg or replacement removes it). Attack I-B exploits caller-unbound settlement (a proxy, logger, or malicious server copies the X-PAYMENT header and settles first). Attack II exploits the absence of an atomic claim on (pay_id, resource_id) before granting. Attack III exploits how caches and parsers handle payment headers. Attack IV exploits how agents pick which server to pay.
Third, they ran the attacks. They built a reproducible testbed on Hardhat/Anvil local chains and Base Sepolia, issued over 25,000 payment requests across 48 configurations, and also probed four production x402 endpoints. They reported rate metrics with 95% Wilson score confidence intervals, then audited three open-source SDKs and the four live endpoints for whether deployed code actually enforces the preconditions the theorems require. Findings were disclosed to Coinbase through HackerOne before publication.
Why This Matters
Impact on research. The paper argues that x402 should be treated as a cross-layer security protocol, not an HTTP payment wrapper, and provides the vocabulary to do so: authorization soundness, payment–service correspondence, replay resistance, and facilitator k-atomicity. Prior work on payment channels, probabilistic micropayments, service execution, and API security does not cover this boundary where synchronous web authorization meets asynchronous settlement, so the formalization gives follow-on work a target to extend or refute.
Real-world applications:
- Paid API and content access for autonomous agents. The motivating scenario — an AI agent querying a weather API priced at 0.01 USDC on Base with no API keys or account setup — is exactly where grant-before-finality and replay bugs translate directly into lost revenue or free content.
- Agent-to-agent (A2A) commerce. x402 is cited as a payment backbone for A2A commerce, so weaknesses in server selection mean an adversary can redirect machine-to-machine spend before any payment logic runs.
- CDN, reverse-proxy, and API-gateway deployments. The 100% nginx leak and observed live CDN leak show that caching hygiene and header handling are security-critical, not operational housekeeping; logging middleware and TLS terminators become preemption points when they hold spendable payment material.
- SDK and merchant integration. The audit findings — grant-before-settle, missing resource-identifier binding, fire-and-forget settlement, absent
Cache-Control— are concrete integration bugs that merchants accepting x402 payments can check for today.
Industry relevance. The ecosystem is large and growing: Coinbase released x402 in May 2025, SDKs exist in TypeScript, Python, Go, and .NET, and the Bazaar discovery layer catalogs over 13,000 registered resource servers. The authors' coordinated disclosure to Coinbase and the severity-rated vulnerability list make the work directly actionable for implementers rather than purely theoretical.
Future Directions
- Enforcing and standardizing the mitigations. The proposed fixes — canonical encoding of payment payloads, two-phase settlement, mandatory idempotency keyed to both payment and resource identity, and caching hygiene — need specification-level adoption and independent validation across the TypeScript, Python, Go, and .NET SDKs.
- Defenses at the discovery layer. Attack IV shows selection bias of 71.8% from one crafted server and 60.2% from five Sybils; the paper validates the manipulation but leaves open how Bazaar-style registries should authenticate servers, rate-limit registrations, or expose Sybil resistance to the selecting agent.
- How much confirmation depth is enough in practice. Corollary 10 recommends k ≥ 3 below $1 and k ≥ 12 above $10 for Base, but the underlying ε_chain(k) is chain-specific and the paper's guidance is tied to Base's ≈ 2 s block time; translating this to other chains and to latency-sensitive agent workloads remains open.
- Fully malicious servers and broader deployment coverage. The threat model assumes honest-but-curious resource servers, with fully malicious servers deferred to the later discussion section; extending the analysis to that setting, and auditing a wider set of production endpoints beyond the four examined, are natural next steps.
Target Audience
Protocol designers and security engineers building or reviewing HTTP-native payment systems; blockchain researchers working on settlement finality and cross-layer trust; SDK maintainers and merchants integrating x402; and security auditors who need a structured checklist of failure events, adversary capabilities, and measurable indicators. AI-agent platform developers choosing paid endpoints through discovery layers will also find Attack IV and the disclosure findings directly relevant, while readers seeking a gentle introduction should expect a steep formal section before the attack narratives.
Authors’ abstract
The x402 protocol revives the HTTP 402 Payment Required status code to enable web-native micropayments across APIs, content, and agents. It combines synchronous HTTP authorization with asynchronous blockchain settlement and introduces a cross-layer attack surface absent from conventional web and on-chain payments. In this paper, we formally analyze x402 and empirically show that it is vulnerable in both design and implementation. We present five concrete attacks that reveal…
The full abstract on arXiv