Skip to content

fix(web-fetch): enable env proxy routing for fake-ip compatibility - #56564

Closed
sunkinux wants to merge 6 commits into
openclaw:mainfrom
sunkinux:fix-fake-ip-proxy-routing
Closed

sunkinux wants to merge 6 commits into
openclaw:mainfrom
sunkinux:fix-fake-ip-proxy-routing

Conversation

@sunkinux

@sunkinux sunkinux commented Mar 28, 2026 •

Copy link
Copy Markdown
Contributor

Problem

“00:16:53+08:00 [security] blocked URL fetch (url-fetch) target=https://www.cnn.com/2026/03/28/world/live-news/iran-war-us-israel-trump reason=Blocked: resolves to private/internal/special-use IP address
00:16:53+08:00 [tools] web_fetch failed: Blocked: resolves to private/internal/special-use IP address
00:16:55+08:00 [security] blocked URL fetch (url-fetch) target=https://www.foxnews.com/live-news/us-israel-iran-war-strait-hormuz-updates-march-26 reason=Blocked: resolves to private/internal/special-use IP address
00:16:55+08:00 [tools] web_fetch failed: Blocked: resolves to private/internal/special-use IP address”

web_fetch fails when using proxy software with fake-ip mode (Clash, Surge, etc.) because DNS resolves to 198.18.0.0/15 which is blocked by the SSRF guard. Even though fetchWithWebToolsNetworkGuard has useEnvProxy support, runWebFetch() never passes it, so requests stay in STRICT mode and direct-connect to the fake-ip address instead of routing through the proxy.

Fix
When a proxy env var is detected:

  • Pass useEnvProxy: true to switch to TRUSTED_ENV_PROXY mode, which uses EnvHttpProxyAgent
  • Pass policy: { allowRfc2544BenchmarkRange: true } to unblock the SSRF guard for the fake-ip range

Testing
Tested locally with Clash fake-ip mode enabled — web_fetch works correctly.

Related: #31176

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: XS labels Mar 28, 2026
@greptile-apps

greptile-apps Bot commented Mar 28, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes web_fetch failures in proxy environments using fake-ip mode (Clash, Surge, etc.) by passing useEnvProxy: true and policy: { allowRfc2544BenchmarkRange: true } to fetchWithWebToolsNetworkGuard when a proxy env var is detected. The change is minimal and well-targeted.

Key findings:

  • The proxy detection uses hasProxyEnvConfigured(), which returns true for ALL_PROXY/all_proxy — but as the project's own docs in proxy-env.ts note, EnvHttpProxyAgent ignores ALL_PROXY. This creates a scenario where the SSRF guard is relaxed for the RFC 2544 range (198.18.0.0/15) without actual proxy routing taking effect, turning a formerly-blocked direct connection into an unblocked one. Using hasEnvHttpProxyConfigured() would align the policy relaxation with what EnvHttpProxyAgent actually supports.

Confidence Score: 4/5

Safe to merge after addressing the ALL_PROXY/policy-relaxation mismatch, which can silently bypass the SSRF guard for the RFC 2544 range.

One P1 finding: the SSRF policy relaxation is gated on hasProxyEnvConfigured() which includes ALL_PROXY, but EnvHttpProxyAgent ignores ALL_PROXY. This causes an unintended SSRF guard bypass for 198.18.0.0/15 when only ALL_PROXY is set. Switching to hasEnvHttpProxyConfigured() is a one-line fix and resolves it cleanly.

src/agents/tools/web-fetch.ts — proxy detection helper at line 539

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

Comment:
**SSRF policy relaxed when `ALL_PROXY` is set but not actually used**

`hasProxyEnvConfigured()` returns `true` for `ALL_PROXY`/`all_proxy`, but the project's own docs in `proxy-env.ts` state: _"ALL_PROXY is ignored by EnvHttpProxyAgent."_ This means when only `ALL_PROXY` is configured (no `HTTP_PROXY`/`HTTPS_PROXY`):

1. `useProxy` is `true` → `allowRfc2544BenchmarkRange: true` is passed, relaxing the SSRF guard for 198.18.0.0/15.
2. `EnvHttpProxyAgent` doesn't route through the proxy for `ALL_PROXY`-only configs.
3. The request goes **direct** to the fake-ip range — which is now unblocked.

Before this PR, the SSRF guard would have correctly blocked 198.18.0.0/15 in an `ALL_PROXY`-only environment. After this PR, the guard is silently bypassed.

The policy relaxation (and the `useEnvProxy` flag) should be conditioned on `hasEnvHttpProxyConfigured()` instead, which only returns `true` when `http_proxy`/`https_proxy`/`HTTP_PROXY`/`HTTPS_PROXY` is set — exactly what `EnvHttpProxyAgent` actually uses:

```suggestion
    const useProxy = hasEnvHttpProxyConfigured();
    const result = await fetchWithWebToolsNetworkGuard({
      url: params.url,
      maxRedirects: params.maxRedirects,
      timeoutSeconds: params.timeoutSeconds,
      // When a proxy is configured (e.g. Clash fake-ip mode), enable env proxy
      // routing and allow the RFC 2544 benchmark range (198.18.0.0/15) in the
      // SSRF guard. Without useEnvProxy, requests stay in STRICT mode and
      // direct-connect to the fake-ip address instead of going through the proxy.
      useEnvProxy: useProxy,
      policy: useProxy ? { allowRfc2544BenchmarkRange: true } : undefined,
```

You'll also need to update the import on line 5 from `hasProxyEnvConfigured` to `hasEnvHttpProxyConfigured`.

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

Reviews (1): Last reviewed commit: "fix(web-fetch): enable env proxy routing..." | Re-trigger Greptile

Comment thread src/agents/tools/web-fetch.ts Outdated
Comment on lines +539 to +549
const useProxy = hasProxyEnvConfigured();
const result = await fetchWithWebToolsNetworkGuard({
url: params.url,
maxRedirects: params.maxRedirects,
timeoutSeconds: params.timeoutSeconds,
// When a proxy is configured (e.g. Clash fake-ip mode), enable env proxy
// routing and allow the RFC 2544 benchmark range (198.18.0.0/15) in the
// SSRF guard. Without useEnvProxy, requests stay in STRICT mode and
// direct-connect to the fake-ip address instead of going through the proxy.
useEnvProxy: useProxy,
policy: useProxy ? { allowRfc2544BenchmarkRange: true } : undefined,

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.

P1 SSRF policy relaxed when ALL_PROXY is set but not actually used

hasProxyEnvConfigured() returns true for ALL_PROXY/all_proxy, but the project's own docs in proxy-env.ts state: "ALL_PROXY is ignored by EnvHttpProxyAgent." This means when only ALL_PROXY is configured (no HTTP_PROXY/HTTPS_PROXY):

  1. useProxy is true → allowRfc2544BenchmarkRange: true is passed, relaxing the SSRF guard for 198.18.0.0/15.
  2. EnvHttpProxyAgent doesn't route through the proxy for ALL_PROXY-only configs.
  3. The request goes direct to the fake-ip range — which is now unblocked.

Before this PR, the SSRF guard would have correctly blocked 198.18.0.0/15 in an ALL_PROXY-only environment. After this PR, the guard is silently bypassed.

The policy relaxation (and the useEnvProxy flag) should be conditioned on hasEnvHttpProxyConfigured() instead, which only returns true when http_proxy/https_proxy/HTTP_PROXY/HTTPS_PROXY is set — exactly what EnvHttpProxyAgent actually uses:

Suggested change
const useProxy = hasProxyEnvConfigured();
const result = await fetchWithWebToolsNetworkGuard({
url: params.url,
maxRedirects: params.maxRedirects,
timeoutSeconds: params.timeoutSeconds,
// When a proxy is configured (e.g. Clash fake-ip mode), enable env proxy
// routing and allow the RFC 2544 benchmark range (198.18.0.0/15) in the
// SSRF guard. Without useEnvProxy, requests stay in STRICT mode and
// direct-connect to the fake-ip address instead of going through the proxy.
useEnvProxy: useProxy,
policy: useProxy ? { allowRfc2544BenchmarkRange: true } : undefined,
const useProxy = hasEnvHttpProxyConfigured();
const result = await fetchWithWebToolsNetworkGuard({
url: params.url,
maxRedirects: params.maxRedirects,
timeoutSeconds: params.timeoutSeconds,
// When a proxy is configured (e.g. Clash fake-ip mode), enable env proxy
// routing and allow the RFC 2544 benchmark range (198.18.0.0/15) in the
// SSRF guard. Without useEnvProxy, requests stay in STRICT mode and
// direct-connect to the fake-ip address instead of going through the proxy.
useEnvProxy: useProxy,
policy: useProxy ? { allowRfc2544BenchmarkRange: true } : undefined,

You'll also need to update the import on line 5 from hasProxyEnvConfigured to hasEnvHttpProxyConfigured.

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

Comment:
**SSRF policy relaxed when `ALL_PROXY` is set but not actually used**

`hasProxyEnvConfigured()` returns `true` for `ALL_PROXY`/`all_proxy`, but the project's own docs in `proxy-env.ts` state: _"ALL_PROXY is ignored by EnvHttpProxyAgent."_ This means when only `ALL_PROXY` is configured (no `HTTP_PROXY`/`HTTPS_PROXY`):

1. `useProxy` is `true` → `allowRfc2544BenchmarkRange: true` is passed, relaxing the SSRF guard for 198.18.0.0/15.
2. `EnvHttpProxyAgent` doesn't route through the proxy for `ALL_PROXY`-only configs.
3. The request goes **direct** to the fake-ip range — which is now unblocked.

Before this PR, the SSRF guard would have correctly blocked 198.18.0.0/15 in an `ALL_PROXY`-only environment. After this PR, the guard is silently bypassed.

The policy relaxation (and the `useEnvProxy` flag) should be conditioned on `hasEnvHttpProxyConfigured()` instead, which only returns `true` when `http_proxy`/`https_proxy`/`HTTP_PROXY`/`HTTPS_PROXY` is set — exactly what `EnvHttpProxyAgent` actually uses:

```suggestion
    const useProxy = hasEnvHttpProxyConfigured();
    const result = await fetchWithWebToolsNetworkGuard({
      url: params.url,
      maxRedirects: params.maxRedirects,
      timeoutSeconds: params.timeoutSeconds,
      // When a proxy is configured (e.g. Clash fake-ip mode), enable env proxy
      // routing and allow the RFC 2544 benchmark range (198.18.0.0/15) in the
      // SSRF guard. Without useEnvProxy, requests stay in STRICT mode and
      // direct-connect to the fake-ip address instead of going through the proxy.
      useEnvProxy: useProxy,
      policy: useProxy ? { allowRfc2544BenchmarkRange: true } : undefined,
```

You'll also need to update the import on line 5 from `hasProxyEnvConfigured` to `hasEnvHttpProxyConfigured`.

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

@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: e5e0dac48d

ℹ️ 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.ts Outdated
@@ -535,10 +536,17 @@ async function runWebFetch(params: WebFetchRuntimeParams): Promise<Record<string
let release: (() => Promise<void>) | null = null;
let finalUrl = params.url;
try {
const useProxy = hasProxyEnvConfigured();

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.

P1 Badge Gate trusted proxy mode on HTTP(S)_PROXY, not ALL_PROXY

hasProxyEnvConfigured() returns true for ALL_PROXY, but this path enables useEnvProxy with EnvHttpProxyAgent (which does not use ALL_PROXY) and simultaneously relaxes SSRF checks with allowRfc2544BenchmarkRange. In environments where only ALL_PROXY is set, web_fetch can therefore allow direct 198.18.0.0/15 targets without actually routing through a trusted proxy, weakening the guard the change is trying to preserve. This should be gated on HTTP(S) proxy vars that EnvHttpProxyAgent actually honors (for example via hasEnvHttpProxyConfigured("https")).

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

👍

@sunkinux
sunkinux force-pushed the fix-fake-ip-proxy-routing branch from e5e0dac to 5d38de2 Compare March 28, 2026 19:10
@sunkinux

Copy link
Copy Markdown
Contributor Author

Update: Why this PR is needed despite #31176 being merged

My previous PR (#31176) added allowRfc2544BenchmarkRange: true to WEB_TOOLS_TRUSTED_NETWORK_SSRF_ POLICY, but that only affected the trusted endpoint path. The default web_fetch path didn't actually route requests through the proxy— it stayed in STRICT mode and direct-connected to the fake-ip address.

I should have caught this during testing back then. Sorry for the extra round! This PR properly fixes it by:

  1. Passing useEnvProxy: true (already supported by fetchWithWebToolsNetworkGuard but never used by web_fetch)
  2. Gating both the proxy mode and SSRF allowance on hasEnvHttpProxyConfigured() (per Greptile's feedback, to match what EnvHttpProxyAgent actually supports)

Tested locally with Clash fake-ip mode — web_fetch works correctly now.

@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: 182d9c5660

ℹ️ 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.ts Outdated
Comment on lines +547 to +548
const envProxyConfigured = hasEnvHttpProxyConfigured();
const allowRfc2544 = envProxyConfigured || params.allowFakeIp;

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.

P1 Badge Detect env proxy using the request URL protocol

hasEnvHttpProxyConfigured() defaults to HTTPS semantics, so this marks proxy mode as enabled for http:// fetches when only HTTPS_PROXY is set. In that case runWebFetch also enables allowRfc2544BenchmarkRange, but EnvHttpProxyAgent does not use HTTPS_PROXY for HTTP targets (see src/infra/net/proxy-env.ts + tests), so those HTTP requests can still go direct while the SSRF guard is relaxed. Please derive proxy availability from parsedUrl.protocol (e.g. pass "http" for http: URLs) before setting useEnvProxy and allowRfc2544.

Useful? React with 👍 / 👎.

@sunkinux
sunkinux requested a review from a team as a code owner March 28, 2026 22:01
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation channel: bluebubbles Channel integration: bluebubbles channel: matrix Channel integration: matrix channel: telegram Channel integration: telegram gateway Gateway runtime cli CLI command changes scripts Repository scripts commands Command implementations extensions: minimax extensions: synthetic extensions: xiaomi size: XL and removed size: XS labels Mar 28, 2026

@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: 7e2326b952

ℹ️ 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.ts Outdated
@@ -535,10 +544,20 @@ async function runWebFetch(params: WebFetchRuntimeParams): Promise<Record<string
let release: (() => Promise<void>) | null = null;
let finalUrl = params.url;
try {
const envProxyConfigured = hasEnvHttpProxyConfigured();
const allowRfc2544 = envProxyConfigured || params.allowFakeIp;

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.

P1 Badge Don't relax RFC2544 guard for NO_PROXY-bypassed hosts

allowRfc2544 is turned on whenever any HTTP(S) proxy env var exists, but that does not mean this URL is actually proxied. EnvHttpProxyAgent respects NO_PROXY / no_proxy exclusions (see src/infra/net/proxy-fetch.ts), so excluded hosts can still be fetched directly while the SSRF policy has already been loosened to allow 198.18.0.0/15. In environments that set both proxy vars and NO_PROXY (common in corp setups), this creates a path where a URL matching NO_PROXY can bypass the proxy and still bypass the RFC2544 block; the guard should only be relaxed when the specific request is guaranteed to route through the trusted proxy (or via explicit allowFakeIp).

Useful? React with 👍 / 👎.

     - Add tools.web.fetch.allowFakeIp config option
     - When enabled, allows RFC 2544 benchmark range (198.18.0.0/15) in SSRF guard
     - TUN mode users no longer need to set HTTP_PROXY environment variables
     - Works alongside existing hasEnvHttpProxyConfigured() check
   Address Codex review feedback: derive proxy availability from the request
   URL protocol to match EnvHttpProxyAgent semantics. For http:// URLs, only
   HTTP_PROXY is checked; for https:// URLs, HTTPS_PROXY takes precedence.
@sunkinux
sunkinux force-pushed the fix-fake-ip-proxy-routing branch from 7e2326b to 82f36fd Compare March 28, 2026 22:25
@openclaw-barnacle openclaw-barnacle Bot removed docs Improvements or additions to documentation channel: bluebubbles Channel integration: bluebubbles channel: matrix Channel integration: matrix labels Mar 28, 2026
@openclaw-barnacle openclaw-barnacle Bot added size: S and removed channel: telegram Channel integration: telegram gateway Gateway runtime cli CLI command changes scripts Repository scripts commands Command implementations extensions: minimax extensions: synthetic extensions: xiaomi size: XL labels Mar 28, 2026

@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: 82f36fdf32

ℹ️ 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.ts Outdated
Comment on lines 550 to 553
const protocol = parsedUrl.protocol.replace(":", "") as "http" | "https";
const envProxyConfigured = hasEnvHttpProxyConfigured(protocol);
const allowRfc2544 = envProxyConfigured || params.allowFakeIp;
const result = await fetchWithWebToolsNetworkGuard({

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.

P1 Badge Recompute proxy gating after protocol-changing redirects

runWebFetch computes envProxyConfigured/allowRfc2544 once from the initial URL protocol, then applies that policy to the whole fetch. If a request starts as HTTPS (with only HTTPS_PROXY set) and redirects to an HTTP URL in 198.18.0.0/15, the redirect hop can go direct because EnvHttpProxyAgent does not proxy HTTP via HTTPS_PROXY, while RFC2544 is still unblocked from the initial decision. This creates a mixed-protocol redirect path where the SSRF relaxation outlives the proxy guarantee; proxy eligibility (and RFC2544 allowance) needs to be evaluated per hop.

Useful? React with 👍 / 👎.

   Remove automatic proxy env var detection to avoid security issues:
   - NO_PROXY exclusion bypassing proxy but still relaxing SSRF
   - Protocol-changing redirects keeping SSRF relaxed after proxy stops

   Only relax RFC 2544 SSRF guard when user explicitly sets allowFakeIp: true.
   This keeps the security model simple and explicit.

   Addresses Codex review feedback.

@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: ff5883bd80

ℹ️ 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.ts Outdated
// When tools.web.fetch.allowFakeIp is true, allow the RFC 2544 range
// (198.18.0.0/15) in the SSRF guard for proxy fake-ip compatibility
// (e.g., Clash TUN mode). Users must explicitly enable this config option.
useEnvProxy: true,

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.

P1 Badge Gate trusted proxy mode behind explicit fake-IP opt-in

This line forces web_fetch into trusted_env_proxy mode whenever proxy env vars exist, even when allowFakeIp is false. In that mode, untrusted URLs are no longer dispatched with DNS pinning and instead rely on proxy-side resolution, which weakens the original SSRF model (e.g., split-horizon/proxy-only DNS can differ from local precheck results) and regresses the prior strict behavior for normal untrusted fetches. useEnvProxy should only be enabled when the operator explicitly opts into that trust model (such as fake-IP compatibility), not by default for all requests.

Useful? React with 👍 / 👎.

   Gate trusted_env_proxy mode behind explicit allowFakeIp opt-in to avoid
   weakening SSRF for normal untrusted fetches.

   Addresses Codex review feedback.

@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: 74ab91feee

ℹ️ 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".

// 3. trusted_env_proxy mode trusts proxy-side DNS, weakening SSRF for normal fetches
// This keeps the security model simple: both SSRF relaxation and trusted proxy mode
// require explicit opt-in via allowFakeIp: true.
const allowRfc2544 = params.allowFakeIp;

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.

P1 Badge Partition web_fetch cache by fake-IP security mode

allowFakeIp now changes the network security posture (useEnvProxy plus allowRfc2544BenchmarkRange), but runWebFetch still caches by URL/extract/maxChars only and returns cache hits before any SSRF guard runs. That means content fetched once with allowFakeIp=true can be replayed to later calls with allowFakeIp=false in the same process (for example, different tool instances or config reloads), effectively bypassing the stricter policy for RFC2544-resolving targets. Add a security-mode discriminator (at least allowFakeIp) to the cache key, or avoid caching responses obtained under the relaxed mode.

Useful? React with 👍 / 👎.

   Add allowFakeIp to cache key to prevent relaxed-mode content from
   polluting strict-mode cache. Without this, content fetched with
   allowFakeIp=true could be replayed to later calls with allowFakeIp=false,
   bypassing stricter SSRF policy.

   Addresses Codex review feedback.
@sunkinux

Copy link
Copy Markdown
Contributor Author

Update: Final Solution / 最终方案

English

This PR provides a simple and secure solution for fake-ip proxy compatibility (Clash TUN mode, Surge, etc.):

Configuration (Required)

  {
    "tools": {
      "web": {
        "fetch": {
          "allowFakeIp": true
        }
      }
    }
  }

How it works:
When allowFakeIp: true is set:

  • Enables useEnvProxy mode (trusts proxy-side DNS resolution)
  • Allows RFC 2544 benchmark range (198.18.0.0/15) in SSRF guard
  • Compatible with Clash/Surge fake-ip DNS

Security model:
| allowFakeIp | useEnvProxy | SSRF Mode |
|-------------|-------------|--- --------|
| false (default) | false | Strict |
| true | true | Relaxed + trusted proxy |

Why only config-based:
After Codex security review, we removed all automatic proxy detection to avoid:

  1. NO_PROXY exclusions bypassing proxy but still relaxing SSRF
  2. Protocol-changing redirects keeping SSRF relaxed after proxy stops
  3. trusted_env_proxy mode weakening SSRF for normal fetches

────────────────────────────────────────────────────────────────────────────────

中文

此 PR 为 fake-ip 代理兼容性(Clash TUN 模式、Surge 等)提供了简洁安全的解决方案:

配置(必须)

  {
    "tools": {
      "web": {
        "fetch": {
          "allowFakeIp": true
        }
      }
    }
  }

工作原理:
当设置 allowFakeIp: true 时:

  • 启用 useEnvProxy 模式(信任代理端 DNS 解析)
  • 允许 RFC 2544 基准范围 (198.18.0.0/15) 在 SSRF 防护中
  • 兼容 Clash/Surge fake-ip DNS

安全模型:
| allowFakeIp | useEnvProxy | SSRF 模式 |
|-------------|-------------|--- --------|
| false (默认) | false | 严格 |
| true | true | 放宽 + 信任代理 |

为什么只基于配置:
经过 Codex 安全审查,我们移除了所有自动代理检测,以避免:

  1. NO_PROXY 排除项绕过代理但仍然放宽 SSRF
  2. 协议变更的重定向在代理停止后仍保持 SSRF 放宽
  3. trusted_env_proxy 模式削弱普通请求的 SSRF 保护

────────────────────────────────────────────────────────────────────────────────

Related: #31176 (trusted endpoint path only)

@smallmj

smallmj commented Apr 11, 2026

Copy link
Copy Markdown

@sunkinux Are you still planning to push this PR forward? It's been 14 days and it's now 7000+ commits behind main. Happy to help rebase if you need it, or I can create a separate PR with just the useEnvProxy fix if you'd prefer to close yours.

@smallmj

smallmj commented Apr 11, 2026

Copy link
Copy Markdown

@sunkinux This PR (#58034) looks like it covers the same issue as your #56564. Are you planning to close #56564 in favor of this one, or keep both open?

@sunkinux

Copy link
Copy Markdown
Contributor Author

close in favor of #58034

@sunkinux sunkinux closed this Apr 12, 2026
@sunkinux

sunkinux commented Apr 12, 2026 via email

Copy link
Copy Markdown
Contributor Author

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