Hire ready-to-work AI agents on Sokosumi — the marketplace built on Masumi
Back to Blog
Articles

x402 Protocol Security: The Two-Phase Gap Explained

Masumi TeamJuly 28, 2026

On July 23, Coinbase announced that any business can start accepting AI agent payments with three lines of code. The CDP x402 SDK is live. The technical barrier is effectively gone.

Two days earlier, a paper accepted to USENIX Security 2026 tested 15 major x402 protocol facilitators. Violations in every single one.

Three independent research groups published security analyses of the x402 protocol between May and July 2026. Their findings converge on one structural problem: the Two-Phase Gap. If you're building agentic payments infrastructure, this is the piece you need to read.

What Is the Two-Phase Gap?

Settlement-path inconsistencies. A blockchain reorganization after a server delivers a resource can revert the payment. The resource stays delivered. Under realistic conditions, researchers measured revert-grant probabilities up to 5.18%. A second sub-variant is more direct: an attacker observes the `X-PAYMENT` header in transit, submits the authorization first, consumes the nonce, and blocks the legitimate payment from settling.

Replay across the HTTP-chain boundary. The blockchain prevents double-spending via nonces. The HTTP layer doesn't always get that information in time. If the server grants access before atomically recording which payment identities have already been used, the same proof can produce multiple resource grants. On testnet: 248 grants from a single payment. [1]

Cache leakage. x402 places payment material inside ordinary HTTP headers. Ordinary HTTP infrastructure treats those responses with ordinary caching defaults. With nginx's default settings, researchers measured 100% cache leakage: paid responses fully visible to unpaid clients. [1]

Server-selection manipulation. Before x402 runs, an AI agent must select which service to pay. Discovery layers that compress a service catalog using LLM relevance ranking are vulnerable. A single crafted malicious server achieved 71.8% selection rate in tests. Five Sybil servers reached 60.2% together. [1]

The root cause is the same across all four: HTTP assumes synchronous atomicity. Blockchain assumes probabilistic finality. x402 bridges them without eliminating the gap between those assumptions.

The Scale: All 15 Facilitators Tested, All Failed

A paper submitted to arXiv on July 21, 2026 and accepted to USENIX Security 2026 expanded the scope to production deployments. [2] Researchers tested 15 major x402 facilitators serving 60,000 sellers and 360,000 buyers.

Violations across all 15.

The attack categories cover the full economic surface: unauthorized service access without payment (Free Shopping), theft of assets held by facilitators (Asset Theft), disruption of payment functionality (Service Denial), and unbounded sponsor-paid gas abuse (Gas Abuse).

Coinbase and other affected parties implemented mitigations after responsible disclosure. The paper will be presented at USENIX Security in August 2026.

A third independent paper (arXiv 2605.30998, May 2026) documented additional vulnerability classes and demonstrated mathematically that pay-per-token pricing models face a structural manipulation gap: attackers can extract value from honest pricing before mitigations activate. [3] Proposed defenses reduce attacker leverage from 8.7x to 0.9x, but the gap grows with token count, making reasoning-heavy AI workloads particularly exposed without careful implementation.

The x402 Foundation launched formally on July 14 with 40 member organizations, including Visa, Mastercard, Google, AWS, and Stripe. [4] Both things are simultaneously true: the protocol just achieved institutional legitimacy, and every tested production deployment has exploitable vulnerabilities.

What Cardano's eUTXO Model Changes

Our implementation on Cardano takes a different approach to the problems these papers identify, and the analysis below reflects Masumi's engineering findings.

Of the 75 million x402 transactions processed in a recent 30-day window, most settled USDC on Base. [5] Cardano's share is still small. The Cardano Foundation joined x402 as an Associate Member in July 2026, specifically naming Masumi Network and ODATANO as examples of ecosystem adoption. [7] (Masumi's x402 on Cardano implementation has been live since October 2025 (https://www.masumi.network/blogs/x402-machine-payments-on-cardano).)

The technical difference between EVM and Cardano matters for several of the attacks described above.

On EVM chains, contracts maintain shared mutable state. Multiple concurrent transactions can attempt to modify the same storage slot, with outcomes determined by transaction ordering. This is the environment where concurrent payment races are most exploitable at the settlement layer.

Cardano uses the extended UTXO (eUTXO) model. Each transaction explicitly declares which UTXOs it consumes. A UTXO can only be spent once. If two concurrent requests try to consume the same payment UTXO, exactly one succeeds and the other fails. Deterministically. Before any resource is granted.

This closes the shared-state mutation vector behind Attack II. You cannot produce 248 grants from one payment UTXO on Cardano, because the UTXO no longer exists after the first spend. It also narrows Attack I by removing the concurrent-race condition from the settlement layer.

The Two-Phase Gap itself is not gone. HTTP is still synchronous. A server still makes a grant decision before on-chain confirmation completes. But eUTXO removes the specific condition that makes EVM-based x402 particularly susceptible to concurrent abuse.

What Masumi Adds Beyond the Protocol

Masumi's x402 implementation on Cardano extends the base protocol with an on-chain trust layer. The additions address attack vectors that cryptographic primitives alone cannot solve.

On-chain agent registry. An AI agent can verify it's paying a legitimate, registered endpoint before submitting payment. This directly counters Attack IV. The server-selection manipulation that achieved 71.8% malicious selection relies on agents trusting LLM relevance rankings without independent verification. Registry-based identity breaks that trust assumption.

Dispute resolution and refund mechanisms. The USENIX paper found economic attacks on facilitators across all 15 tested deployments. Economic losses without recourse are what make these attacks worth running. Masumi's documented dispute resolution and on-chain audit logs change the attacker's calculus.

Decision logs. Forensic analysis after a payment incident requires a record. Masumi creates one on-chain, immutably.

The implementation is open source at masumi-network/x402-cardano (https://github.com/masumi-network/x402-cardano). The full trust-layer architecture is detailed in the Masumi Agent SDK documentation (https://www.masumi.network).

What Developers Should Do Right Now

Three changes have the highest impact per effort:

Pre-grant idempotency. Before delivering any resource, atomically record whether this payment identity has already been used. Check AND record in a single atomic operation. This closes Attack II. The 248-grants-from-one-payment result is a pure implementation gap, not a protocol impossibility.

Cache-Control headers. Set `Cache-Control: no-store` on all x402-gated responses. nginx defaults will cache them. This is a one-line fix that closes Attack III.

Confirmation depth. The x402 spec allows setting how many block confirmations are required before treating a payment as final. Most SDKs default to k=1. For resources with meaningful economic value, raise this.

If you're choosing settlement infrastructure: EVM-based x402 gives you liquidity, ecosystem depth, and 150 million transactions of real usage history. [5] Cardano's eUTXO gives you deterministic concurrency guarantees that structurally reduce the attack surface for concurrent payment exploitation. Neither is complete without the application-layer mitigations above.

The security research is not an argument against x402. It's an argument for implementing it with appropriate care.

FAQ

What is the x402 protocol?

x402 revives the dormant HTTP 402 "Payment Required" status code to let AI agents and APIs pay for resources per-request, in stablecoins, without accounts or checkout flows. The x402 Foundation, launched under the Linux Foundation on July 14, 2026, now has 40 member organizations including Visa, Mastercard, Google, Stripe, and AWS. [4]

How does the x402 protocol work?

An AI agent requests a paid endpoint. The endpoint returns a 402 response with payment requirements. The agent's wallet signs the payment, submits it on-chain, attaches the proof to the `X-PAYMENT` header, and retransmits the request. The server verifies the proof, delivers the resource, and settlement completes on-chain.

What is the difference between x402 and Stripe MPP?

Stripe's Merchant Payments Protocol (MPP) operates through existing card rails with Stripe as intermediary. x402 is a protocol-layer standard for stablecoin payments directly over HTTP, with no payment processor required. x402 is better for per-request AI agent billing at sub-cent prices. MPP is better for higher-value transactions where card fraud protection and compliance infrastructure have real value.

Can AI agents make payments autonomously using x402?

Yes. An agent with a funded wallet can discover a paid endpoint, construct the payment proof, and complete the transaction without human sign-off per transaction. Coinbase's CDP x402 SDK, launched July 23, 2026, makes the integration three lines of code for service providers. [6]

How do AI agents pay each other using x402?

Agent-to-agent x402 payments work the same way as agent-to-service at the protocol layer. One agent acts as client (constructs and sends the payment proof), the other acts as facilitator (verifies and delivers the service). Masumi's A2A Protocol integration (https://www.masumi.network/blogs/a2a-protocol-and-the-agent-economy) adds on-chain identity verification so each agent knows who it's transacting with before payment is submitted.

Ready to build on x402 with Cardano's deterministic payment guarantees? The Masumi x402 implementation (https://github.com/masumi-network/x402-cardano) is open source and production-ready. For agents that need verified identity, dispute resolution, and on-chain audit logs out of the box, explore Sokosumi (https://www.sokosumi.com) or the Masumi Agent SDK.

Sources

[1] "Five Attacks on x402 Agentic Payment Protocol" | https://arxiv.org/abs/2605.11781 | "x402's risks stem from HTTP-chain boundary rather than isolated SDK bugs; 248 grants from one payment demonstrated on testnet; 100% cache leakage with nginx defaults; 71.8% malicious server selection rate" (May 2026)

[2] "When HTTP 402 Meets the Blockchain: Risks on Emerging x402 Payments" | https://arxiv.org/abs/2607.19545 | "Violations found in all 15 evaluated facilitators serving 60,000 sellers and 360,000 buyers; accepted USENIX Security 2026" (July 21, 2026)

[3] "Free-Riding in the AI Economy: Demystifying Logic Flaws in x402-Enabled Payment Systems" | https://arxiv.org/html/2605.30998 | "Mathematical proof of manipulation gap in pay-per-token pricing; resource leakage ratios up to 100% against official SDKs" (May 2026)

[4] Linux Foundation, "Operational Launch of x402 Foundation" | https://www.prnewswire.com/news-releases/linux-foundation-announces-operational-launch-of-x402-foundation-to-standardize-internet-native-payments-for-ai-agents-and-applications-302824778.html | "40 member organizations including Visa, Mastercard, Google, AWS, Stripe, Circle, Coinbase" (July 14, 2026)

[5] CoinDesk, "Visa, Mastercard, and Ripple Join the Standard Letting AI Agents Pay in Stablecoins" | https://www.coindesk.com/tech/2026/07/15/visa-mastercard-and-ripple-join-the-standard-letting-ai-agents-pay-in-stablecoins | "75 million transactions, $24 million in value over 30 days; average transaction $0.32" (July 15, 2026)

[6] CoinDesk, "Coinbase Closes the Gaps in AI Agent Economy for Businesses, Users and Developers" | https://www.coindesk.com/business/2026/07/23/coinbase-closes-the-gaps-in-ai-agent-economy-for-businesses-users-and-developers | "CDP x402 SDK: 3 lines of code to accept AI agent payments; all Coinbase Business clients eligible" (July 23, 2026)

[7] Cardano Foundation on X | https://x.com/Cardano_CF/status/2077035809266335942 | "Cardano Foundation joined x402 as Associate Member; named Masumi Network and ODATANO as Cardano ecosystem early adopters" (July 2026)

[8] DataForSEO, Keyword Research US/en | via seo-geo-researcher subagent | "x402 protocol: 720/mo, KD 29, competition 0.060 (LOW); agentic payments: 590/mo, KD 10; no educational long-form content ranking for x402 protocol" (July 27, 2026)