Skip to main content

Security

The x402 escrow system is designed with security as a primary concern. This page covers the security model and best practices.

Security Model

Session Token Security

Session tokens are secrets. Treat them like API keys or passwords.
PropertyImplementation
Generation256-bit cryptographically random
Storagebcrypt hash (cost factor 10)
TransmissionHTTPS only, shown once
ValidationConstant-time comparison

ERC-3009 Authorization

Escrow sessions use ERC-3009 transferWithAuthorization:
  • Replay protection: Nonces are derived from payment info hash
  • Time-bounded: validAfter and validBefore constraints
  • Receiver-locked: Authorization tied to specific receiver

Rate Limiting

All endpoints are rate-limited:
EndpointLimit
/api/verify, /api/settle1000/min per API key
Auth endpoints10/min per IP
Session management100/min per user
Reclaim operations10/min per wallet

Attack Vectors & Mitigations

Session Token Theft

Risk: Attacker obtains session token and drains balance Mitigations:
  • Tokens shown only once at creation
  • HTTPS required for all communications
  • Sessions can be voided by owner
  • Expiry limits exposure window

Replay Attacks

Risk: Attacker replays valid payment payload Mitigations:
  • Each request has unique requestId
  • Facilitator tracks processed requests
  • Idempotency built into protocol

Authorization Expiry Racing

Risk: Facilitator fails to capture before expiry Mitigations:
  • Sync capture when expiry < 30min
  • Cron job captures when expiry < 2h
  • Monitoring and alerts on pending amounts

Best Practices

For Server Operators

  • Store API keys in environment variables
  • Use secrets management (AWS Secrets Manager, Vault)
  • Rotate keys periodically
  • Never commit keys to version control
  • Always verify payment before serving content
  • Don’t trust client-provided payment data
  • Use the facilitator’s verify endpoint
  • Implement retry logic for transient failures
  • Return appropriate error messages
  • Log all payment events for auditing

For Client Applications

  • Store tokens securely (encrypted storage)
  • Clear tokens on logout
  • Handle token expiry gracefully
  • Only communicate over HTTPS
  • Validate SSL certificates
  • Implement certificate pinning for mobile
  • Show clear deposit amounts
  • Display available balance
  • Provide easy reclaim functionality

Error Codes

CodeMeaningAction
invalid_signatureERC-3009 signature failedRetry with fresh signature
invalid_session_tokenWrong session tokenUse correct token or create new session
session_expiredPast authorization expiryCreate new session
insufficient_balanceNot enough balanceTop up or create new session

Smart Contract Architecture

The escrow system is built on Base’s Commerce Payments Protocol, a battle-tested payment infrastructure.

AuthCaptureEscrow Contract

The core escrow logic lives in the AuthCaptureEscrow contract:

View Source Code

Open-source, auditable smart contract
Key Security Features:
FeatureImplementation
Reentrancy ProtectionReentrancyGuardTransient modifier
Access ControlRole-based (operator, payer) sender validation
Time BoundsEnforced expiry windows (preApproval → authorization → refund)
Amount Safetyuint120 overflow protection, balance verification
Fee ConstraintsMin/max basis points validation

Contract Functions

FunctionWho CallsPurpose
authorize()OperatorDeposit payer funds into escrow
capture()OperatorRelease funds to receiver (supports partial)
void()OperatorCancel auth, return all funds to payer
reclaim()PayerRetrieve uncaptured funds after expiry
refund()OperatorReturn captured funds to payer

Contract Addresses

Currently Base Sepolia only. The facilitator is currently deployed on Base Sepolia (testnet). Base Mainnet support coming soon.
NetworkContractAddress
Base SepoliaAuthCaptureEscrow0xbDEa0d1BCc5966192b070fDF62ab4eF5B4420Cff
Base SepoliaERC3009 Collector0x0E3dF9510De65469c4518d7843919C0B8c7a7757
Base SepoliaUSDC0x036CbD53842c5426634e7929541eC2318f3dCF7e
ContractAddress
AuthCaptureEscrow0xbDEa0d1BCc5966192b070fDF62ab4eF5B4420Cff
ERC3009 Collector0x0E3dF9510De65469c4518d7843919C0B8c7a7757
USDC0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913

Auditing

The escrow contracts are based on Base’s Commerce Payments Protocol. Contact us for audit reports.