T09 · Insecure Skill Coding Practices
- Location
client.py:256- Finding
Unvalidated Server-Directed Payment Authorization
- Content
View full analysis
Vulnerability Details
File Location:
client.py:256-274
Vulnerability Type: Automatic signing of untrusted payment terms
Risk Level: HighVulnerable Code
python auth = { "from": self.address, "to": Web3.to_checksum_address(terms["payTo"]), "value": str(int(terms["maxAmountRequired"])), "validAfter": str(now - 60), "validBefore": str(now + 600), "nonce": "0x" + secrets.token_bytes(32).hex(), } eip = terms["eip712"] signable = encode_typed_data( domain_data=eip["domain"], message_types=eip["types"], message_data={ "from": auth["from"], "to": auth["to"], "value": int(auth["value"]), "validAfter": int(auth["validAfter"]), "validBefore": int(auth["validBefore"]), "nonce": bytes.fromhex(auth["nonce"][2:]), }, ) sig = Account.sign_message(signable, private_key=self.account.key).signature.hex()Technical Analysis
The x402 payment implementation treats payment terms returned by the remote API as trusted. It signs an EIP-3009-style authorization using the wallet's private key without validating critical security boundaries, including:
- The
payTorecipient. - The
maxAmountRequiredvalue. - The EIP-712 domain chain ID.
- The EIP-712 verifying contract or token contract.
- Whether the domain represents the expected Base USDC contract.
- Whether the authorization amount equals the advertised fee of 50,000 USDC base units.
- Whether the offered payment scheme and message types are exactly those supported by the client.
Merely converting the supplied recipient into a checksum address does not establish that it is an authorized recipient. Likewise,
encode_typed_data()encodes the server-provided domain but does not determine whether that domain is safe or expected.This behavior exceeds the minimum privilege needed to pay a fixed fee because the server is effectively allowed to select both the authori ...[truncated 1623 chars]
- The
- Remediation
View remediation
Remediation Suggestions
Apply a strict local payment policy before constructing or signing the authorization:
- Require chain ID
8453for Base mainnet. - Require the EIP-712 verifying contract to equal the configured Base USDC address.
- Validate the complete EIP-712 domain, including expected name, version, chain ID, and verifying contract.
- Require
maxAmountRequiredto equal or fall below a caller-configurable hard cap. The documented $0.05 fee corresponds to 50,000 USDC base units. - Pin or explicitly allow-list the payment recipient instead of accepting arbitrary
payTovalues. - Validate the payment network, asset, scheme, and EIP-712 message type against an exact expected schema.
- Reject unknown fields, malformed offers, ambiguous offers, and responses containing multiple unsupported alternatives.
- Expose the recipient, asset, chain, and amount to the caller and require confirmation when they differ from pinned defaults.
- Keep the short authorization lifetime and unique nonce, but do not treat these controls as substitutes for recipient, amount, and domain validation.
- Add negative tests proving that altered recipients, inflated amounts, incorrect chain IDs, and unexpected verifying contracts are rejected before signing.
- Require chain ID
