You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Agents] Add a spending cap and a payee allowlist to the x402 coding-tool examples - #36125
The two examples on "Pay from coding tools" pay any 402 they meet: the x402 client's default cap of $1 per payment is the only limit, and the Claude Code hook fires on any WebFetch that hits a 402, so a page with injected instructions can steer the agent into paying sites the user never chose. This change keeps both examples as short as they were and adds two lines of defence before anything is signed: a lower per-payment cap (setSpendControls), and an onBeforePaymentCreation hook that pays only hosts listed in X402_ALLOWED_HOSTS. The hook checks the URL the agent asked for, not the 402's resource.url, which the seller writes. The prose notes that the same hook is where a human confirmation or a payee check belongs.
I ran the snippet against @x402/fetch 2.29: an allowed host at $0.01 is paid; a host not in the list is refused before signing; a $0.50 quote is refused by the cap.
Disclosure: I maintain x402-trust-guard, a payee check that plugs into this hook. It isn't mentioned in the change.
Fix the following review findings in PR #36125 (https://github.com/cloudflare/cloudflare-docs/pull/36125).
Before making changes, review each finding and present a brief summary table:
- For each finding, state whether you agree, disagree, or need clarification.
- If you disagree, explain why.
- If you need clarification before deciding, ask those questions.
- Then share your plan for which issues to tackle and in what order.
After triaging, follow this order:
1. Post a comment on this PR for any findings you are skipping, with the finding ID and your reasoning.
2. Then commit the fixes for the legitimate findings.
The comment must come before the commit because the next review reads PR comments.
## Code Review- C-0452adae | src/content/docs/agents/tools/payments/x402/pay-with-tool-plugins.mdx:65 | Allowlist check keys off the requested URL, which `fetch` may redirect away from
`host` comes from `args.url`, but the request that produces the 402 is made by `paidFetch`, and `fetch` follows redirects by default, so a 402 served by a redirect target on another host is still signed while the allowlist check sees the original, allowlisted hostname. The repo's own guidance on redirects notes that `redirect: "manual"` is what stops a request from following a redirect to another host (`src/content/docs/containers/configuration/outbound-traffic.mdx`). The Claude Code hook has the same shape with `new URL(url).hostname`.
```txt const host = new URL(args.url).hostname;```
Code Review
src/content/docs/agents/tools/payments/x402/pay-with-tool-plugins.mdx:65 · Allowlist check keys off the requested URL, which fetch may redirect away from
host comes from args.url, but the request that produces the 402 is made by paidFetch, and fetch follows redirects by default, so a 402 served by a redirect target on another host is still signed while the allowlist check sees the original, allowlisted hostname. The repo's own guidance on redirects notes that redirect: "manual" is what stops a request from following a redirect to another host (src/content/docs/containers/configuration/outbound-traffic.mdx). The Claude Code hook has the same shape with new URL(url).hostname.
const host = new URL(args.url).hostname;
Commands
/review Run a review now.
/full-review Review the entire PR diff.
/disable-auto-review Stop automatic reviews.
/rebase Rebase against production.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The two examples on "Pay from coding tools" pay any 402 they meet: the x402 client's default cap of $1 per payment is the only limit, and the Claude Code hook fires on any WebFetch that hits a 402, so a page with injected instructions can steer the agent into paying sites the user never chose. This change keeps both examples as short as they were and adds two lines of defence before anything is signed: a lower per-payment cap (
setSpendControls), and anonBeforePaymentCreationhook that pays only hosts listed inX402_ALLOWED_HOSTS. The hook checks the URL the agent asked for, not the 402'sresource.url, which the seller writes. The prose notes that the same hook is where a human confirmation or a payee check belongs.I ran the snippet against
@x402/fetch2.29: an allowed host at $0.01 is paid; a host not in the list is refused before signing; a $0.50 quote is refused by the cap.Disclosure: I maintain x402-trust-guard, a payee check that plugs into this hook. It isn't mentioned in the change.
Documentation checklist
🤖 Generated with Claude Code
https://claude.ai/code/session_015tB4xz1UGsjNmx37Qr7CNC