Skip to content

feat(web-fetch): add ssrfPolicy.allowRfc2544BenchmarkRange config option - #61830

Merged
obviyus merged 3 commits into
openclaw:mainfrom
xing-xing-coder:feat/web-fetch-ssrf-rfc2544-refresh
Apr 9, 2026
Merged

obviyus merged 3 commits into
openclaw:mainfrom
xing-xing-coder:feat/web-fetch-ssrf-rfc2544-refresh

Conversation

@xing-xing-coder

Copy link
Copy Markdown
Contributor

Summary

  • Problem: the underlying SSRF / guarded-fetch stack already supports allowRfc2544BenchmarkRange, but web_fetch had no scoped config surface to pass that policy through for fake-IP proxy environments such as Clash TUN, Mihomo, and Surge.
  • Why it matters: in those environments, normal public destinations can resolve into 198.18.0.0/15, making web_fetch unusable even though the underlying network guard already has the necessary benchmark-range allowance capability.
  • What changed: added an opt-in tools.web.fetch.ssrfPolicy.allowRfc2544BenchmarkRange config path, threaded it through runtime/schema handling and web_fetch, and added regression coverage for default-blocked behavior, explicit opt-in behavior, and cache isolation across policy variants.
  • What did NOT change (scope boundary): no default behavior change, no broader SSRF relaxation, and no private-network allowlist expansion beyond this scoped web_fetch opt-in.

Change Type (select all)

  • Bug fix
  • Feature
  • Refactor required for the fix
  • Docs
  • Security hardening
  • Chore/infra

Scope (select all touched areas)

  • Gateway / orchestration
  • Skills / tool execution
  • Auth / tokens
  • Memory / storage
  • Integrations
  • API / contracts
  • UI / DX
  • CI/CD / infra

Linked Issue/PR

Root Cause / Regression History (if applicable)

  • Root cause: web_fetch did not expose an existing lower-level SSRF policy capability at the tool config layer.
  • Missing guardrail: no regression test covered “blocked by default, allowed only when explicitly enabled, and isolated across cache variants”.
  • Prior context: this behavior has been reported repeatedly in Clash/Surge/Mihomo fake-IP environments.

Regression Test Plan (if applicable)

  • Coverage level that should have caught this:
    • Unit test
    • Seam / integration test
    • End-to-end test
    • Existing coverage already sufficient
  • Target test or file:
    • src/agents/tools/web-fetch.ssrf.test.ts
    • src/config/schema.test.ts
    • src/config/schema.base.generated.test.ts
  • Scenario the test should lock in:
    • default blocked behavior
    • explicit opt-in behavior
    • cache isolation between strict and permissive policy variants
    • schema/generated config alignment

User-visible / Behavior Changes

  • New opt-in config:
    • tools.web.fetch.ssrfPolicy.allowRfc2544BenchmarkRange
  • Default behavior remains unchanged.
  • When enabled, web_fetch can access fake-IP-proxied public destinations resolving into 198.18.0.0/15.

Security Impact (required)

  • New permissions/capabilities? (Yes/No) Yes
  • Secrets/tokens handling changed? (Yes/No) No
  • New/changed network calls? (Yes/No) No
  • Command/tool execution surface changed? (Yes/No) No
  • Data access scope changed? (Yes/No) No
  • If any Yes, explain risk + mitigation:
    • This is a narrow web_fetch-only opt-in for one special-use range.
    • Default behavior remains fail-closed.
    • Cache keys now include ssrfPolicy so permissive results do not bleed into stricter instances.

Repro + Verification

Environment

  • OS: WSL2 Ubuntu
  • Runtime/container: local worktree
  • Relevant config:
    • tools.web.fetch.ssrfPolicy.allowRfc2544BenchmarkRange: true

Steps

  1. Run web_fetch against a URL resolving into 198.18.0.0/15 with default config.
  2. Confirm it is blocked.
  3. Enable tools.web.fetch.ssrfPolicy.allowRfc2544BenchmarkRange.
  4. Re-run the same request.
  5. Confirm it succeeds and does not reuse permissive cache state for stricter tool instances.

Expected

  • Default config blocks RFC 2544 targets.
  • Explicit opt-in allows them for web_fetch.
  • Cache remains policy-specific.

Actual

  • Verified locally with targeted schema/runtime/SSRF regression coverage.

Evidence

  • Targeted tests passing after the patch
  • Trace/log snippets
  • Screenshot/recording
  • Perf numbers (if relevant)

Human Verification (required)

  • Verified:
    • runtime config accepts the new path
    • generated schema stays aligned
    • default blocked behavior remains intact
    • explicit opt-in works
    • cache isolation works
  • Not verified:
    • full repo-wide pnpm check
    • unrelated global CI failures outside the touched web_fetch / schema surface

Compatibility / Migration

  • Backward compatible? (Yes/No) Yes
  • Config/env changes? (Yes/No) Optional new config only
  • Migration needed? (Yes/No) No

Risks and Mitigations

  • Risk: users may enable the exemption unnecessarily.
    • Mitigation: explicit opt-in, narrow scope, default-off.
  • Risk: cache reuse could widen behavior across policy variants.
    • Mitigation: ssrfPolicy is now part of the cache key.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation agents Agent runtime and tooling size: S labels Apr 6, 2026
@greptile-apps

greptile-apps Bot commented Apr 6, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR adds an opt-in tools.web.fetch.ssrfPolicy.allowRfc2544BenchmarkRange config option to allow web_fetch to access IPs in the 198.18.0.0/15 RFC 2544 benchmark range, addressing usability issues in fake-IP proxy environments (Clash TUN, Mihomo, Surge). The change is well-scoped: it threads the config through TypeScript types, Zod schema, schema help/labels, and the generated baseline, re-throws SsrFBlockedError so the provider fallback path cannot silently bypass the SSRF guard, and includes a policy-aware cache key to prevent permissive results from bleeding into stricter tool instances.

Key changes:

  • New tools.web.fetch.ssrfPolicy.allowRfc2544BenchmarkRange config field (default: off, opt-in only)
  • Cache key now includes a serialized ssrfPolicy suffix to isolate permissive from strict results
  • Regression tests cover default-blocked behavior, explicit opt-in behavior, and cache isolation
  • Schema, Zod, TypeScript types, help text, labels, and generated baseline are all updated consistently

Confidence Score: 4/5

Safe to merge; default behavior is unchanged and the SSRF guard is fail-closed.

The implementation is well-scoped and security-sensitive paths are handled correctly: SsrFBlockedError is re-thrown (not swallowed by provider fallback), the policy normalization ensures only explicit true enables the exemption, and cache key isolation prevents cross-policy cache reuse. The one issue found — cache key derived from raw rather than normalized policy — is a style/correctness concern that can cause unnecessary cache misses but not security regressions. Schema, types, Zod, help text, labels, and generated baseline are all kept in sync. Score is 4 rather than 5 because of the cache key inconsistency.

src/agents/tools/web-fetch.ts lines 370–397 (cache key ordering and input source)

Prompt To Fix All With AI
This is a comment left during a code review.
Path: src/agents/tools/web-fetch.ts
Line: 370-397

Comment:
**Cache key built from raw `ssrfPolicy`, not the normalized effective policy**

The `ssrfPolicySuffix` is serialized from `params.ssrfPolicy` (the raw config object), but the variable that actually governs fetch behavior — `policy` — is computed ~25 lines later and normalizes the input:

```typescript
// effective policy: only 'true' enables the exemption
const policy =
  params.ssrfPolicy?.allowRfc2544BenchmarkRange === true
    ? { allowRfc2544BenchmarkRange: true }
    : undefined;
```

Because the cache key uses the raw object, semantically equivalent strict configs (`ssrfPolicy: undefined`, `ssrfPolicy: {}`, `ssrfPolicy: { allowRfc2544BenchmarkRange: false }`) all produce different cache keys even though they produce identical SSRF behavior. This causes unnecessary cache misses and fragmentation when configs vary structurally but not behaviorally.

The fix is to compute `policy` before building the cache key, then derive the suffix from `policy`:

```typescript
const policy =
  params.ssrfPolicy?.allowRfc2544BenchmarkRange === true
    ? { allowRfc2544BenchmarkRange: true }
    : undefined;
const ssrfPolicySuffix = policy ? `:${JSON.stringify(policy)}` : "";
const cacheKey = normalizeCacheKey(
  `fetch:${params.url}:${params.extractMode}:${params.maxChars}${ssrfPolicySuffix}`,
);
```

This ensures the cache key directly reflects the effective SSRF behavior, not the raw config shape. The security invariant (permissive and strict entries are still isolated from each other) is preserved.

How can I resolve this? If you propose a fix, please make it concise.

Reviews (1): Last reviewed commit: "chore(config): regenerate schema artifac..." | Re-trigger Greptile

Comment thread src/agents/tools/web-fetch.ts Resolved
@xing-xing-coder
xing-xing-coder force-pushed the feat/web-fetch-ssrf-rfc2544-refresh branch from 6c9900d to f680319 Compare April 6, 2026 14:08

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f6803193a9

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/agents/tools/web-fetch.ssrf.test.ts Resolved
Comment thread src/agents/tools/web-fetch.ssrf.test.ts Resolved
@xing-xing-coder
xing-xing-coder force-pushed the feat/web-fetch-ssrf-rfc2544-refresh branch 4 times, most recently from 30c32c1 to a33f553 Compare April 9, 2026 05:05
@xing-xing-coder

Copy link
Copy Markdown
Contributor Author

@obviyus This PR fixes a long-standing issue that has a pretty big impact for users running OpenClaw behind a proxy, and now that CI is passing, I’d really appreciate it if you had a chance to take a look.

@obviyus obviyus self-assigned this Apr 9, 2026
@obviyus
obviyus force-pushed the feat/web-fetch-ssrf-rfc2544-refresh branch from a33f553 to a97f183 Compare April 9, 2026 08:12
@openclaw-barnacle openclaw-barnacle Bot removed the docs Improvements or additions to documentation label Apr 9, 2026
@obviyus
obviyus force-pushed the feat/web-fetch-ssrf-rfc2544-refresh branch from a97f183 to 543ba32 Compare April 9, 2026 08:18

@obviyus obviyus left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed latest changes; landing now.

@obviyus
obviyus merged commit 68781bf into openclaw:main Apr 9, 2026
8 checks passed
@obviyus

obviyus commented Apr 9, 2026

Copy link
Copy Markdown
Collaborator

Landed on main.

Thanks @xing-xing-coder.

lovewanwan pushed a commit to lovewanwan/openclaw that referenced this pull request Apr 28, 2026
ogt-redknie pushed a commit to ogt-redknie/OPENX that referenced this pull request May 2, 2026
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request May 24, 2026
jameslcowan pushed a commit to jameslcowan/openclaw that referenced this pull request Jun 2, 2026
vixco pushed a commit to vixco/openclaw that referenced this pull request Aug 16, 2026
zooqueen pushed a commit to zooqueen/openclaw that referenced this pull request Sep 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants