Skip to content

[Agents] Add a spending cap and a payee allowlist to the x402 coding-tool examples - #36125

Open
benmcalillycreative wants to merge 1 commit into
cloudflare:productionfrom
benmcalillycreative:x402-coding-tools-spend-limits
Open

benmcalillycreative wants to merge 1 commit into
cloudflare:productionfrom
benmcalillycreative:x402-coding-tools-spend-limits

Conversation

@benmcalillycreative

Copy link
Copy Markdown

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 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.

Documentation checklist

🤖 Generated with Claude Code

https://claude.ai/code/session_015tB4xz1UGsjNmx37Qr7CNC

…tool examples

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015tB4xz1UGsjNmx37Qr7CNC
@benmcalillycreative
benmcalillycreative marked this pull request as ready for review December 6, 2026 02:36
@cloudflare-docs-bot

Copy link
Copy Markdown
Contributor

Review coverage

🟡 1 ownership area needs approval.

Suggested reviewers: @irvinebroque @southpolesteve

Needs approval Eligible approvers Suggested
agents @irvinebroque, @rita3ko, @cloudflare/ai-agents, @cloudflare/dev-plat-leads, @cloudflare/product-owners irvinebroque, southpolesteve
CODEOWNERS mappings for displayed areas (1)
Pattern Owners
/src/content/docs/agents/ @irvinebroque, @rita3ko, @cloudflare/ai-agents, @cloudflare/dev-plat-leads, @cloudflare/product-owners

@cloudflare-docs-bot

cloudflare-docs-bot Bot commented Dec 6, 2026 •

Copy link
Copy Markdown
Contributor

AI Review

✅ Reviewed 34e9503 · 1 finding · incremental

👉 Fix in your agent 👈
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants