How does x402 stop replay attacks, where a payment is used twice?
Short answer
Each payment can move money only once. On EVM networks the signed authorization carries a random one-time number that the token contract records and then refuses, plus an expiry time. On Solana the payment is a signed transaction, which the network executes only once. A captured payment also cannot be redirected, because the signature fixes the amount and the recipient.
What a replay attack is
A payment in x402 travels as a signed message in an HTTP header. Anyone who can read that header, such as the seller, a proxy or a logging system, has a copy. A replay attack is taking that copy and submitting it again to collect a second time.
x402 does not rely on keeping the message secret. It relies on the message being useless after its first use.
On EVM networks
The standard payment is an EIP-3009 authorization. Three things in it stop reuse.
| Protection | How it works |
|---|---|
| A one-time number | The authorization includes a random 32-byte nonce. The token contract records each nonce an address has used and rejects it the second time |
| An expiry | validBefore is a time limit. After it, the token contract refuses the transfer |
| A fixed destination and amount | to and value are part of what was signed. A copy cannot be pointed at another address or a larger sum |
The record of used nonces lives in the token contract itself, on the blockchain. It does not depend on the facilitator or the seller keeping track. Anyone can check whether a nonce has been used by calling the token's authorizationState function.
See what EIP-3009 is.
On Solana
The buyer signs a transaction, not a message. A given Solana transaction is executed once. The x402 specification for Solana notes that the network's deduplication "ensures the transfer only executes once on-chain".
The specification also limits what that transaction may contain, so it can only make the single transfer the offer asked for. See x402 on Solana.
What the blockchain does not cover
The chain guarantees the money moves once. It does not stop a seller from handing out the goods twice. That part is the seller's and the facilitator's job.
The Solana specification describes the case directly. If the same payment is sent for settlement several times in quick succession, each call can come back reporting success, even though only one transfer happened. A seller that delivers on every "success" would deliver more than once for one payment.
The recommended fix is for the facilitator to keep a short-lived record of payments it is already settling, and to reject a repeat with a duplicate_settlement error. The specification suggests keeping each entry for 120 seconds.
What sellers should do
- Use a maintained facilitator and SDK. They implement these checks. Writing your own verification is where mistakes are made.
- Treat each payment as good for one response. If you build anything custom, record the payment's identifier when you accept it and refuse to serve it again.
- Keep the time window short. The offer's
maxTimeoutSecondssets how long a signed payment stays valid. A shorter window leaves less time for anything to go wrong. - Do not log payment headers where they are not needed. A used payment is harmless, but an unused, unexpired one is still spendable by whoever submits it to you first.
What buyers should know
- A payment you signed but that was never settled expires by itself at
validBefore. - Your signature cannot be changed into a bigger payment or one to a different address.
- A seller cannot charge you again from the same signature. A second charge needs a second signature from your wallet.
The wider picture of risk, including the parts the protocol does not handle, is in is x402 safe?
Sources
Facts checked against these sources on . Protocols change, so the official specification wins if it disagrees with this page. Read this page as Markdown.
Related questions
Who writes this. Ask402 is published by Havok Holdings LLC, which also runs Agent402, one of the x402 services covered here. Agent402 is labelled wherever it appears. Everything else is described from each project’s own documentation, and nobody pays to be listed.