T09 · Insecure Skill Coding Practices
- Location
x402.mjs:69- Finding
Automatic Signing of Untrusted, Unbounded Payment Requirements
- Content
View full analysis
= 2 || String(maxAmount).length > 6) { // Already in base units value = BigInt(maxAmount); } else { // Legacy: whole token amount value = BigInt(maxAmount) * BigInt(1e6); } // Authorization struct const authorization = { from: account.address, to: requirement.payTo || requirement.payToAddress, value, validAfter, validBefore, nonce, }; // EIP-712 domain const domain = { name: requirement.extra?.name || "USD Coin", version: requirement.extra?.version || "2", chainId: network.chainId, verifyingContract: requirement.asset || requirement.usdcAddress, }; // EIP-712 types const types = { TransferWithAuthorization: [ { name: "from", type: "address" }, { name: "to", type: "address" }, { name: "value", type: "uint256" }, { name: "validAfter", type: "uint256" }, { name: "validBefore", type: "uint256" }, { name: "nonce", type: "bytes32" }, ], }; // Sign const signature = await account.signTypedData({ domain, types, primaryType: "TransferWithAuthorization", message: authorization, }); ``` ```javascript // Find supported payment option const requirement = requirements.accepts.find( r => r.scheme === "exact" && SUPPORTED_NETWORKS[r.network] ); if (!requirement) { throw new Error("No supported payment options found"); } // Create and sign payment const payment = await createPaymentSignature( account, requirement, requirements.x402Version ); // Retry with payment header const paidResponse = await fetch(url ...[truncated 2421 chars]- Remediation
View remediation
