Repository navigation
Conversation
Greptile SummaryThis PR fixes Key findings:
Confidence Score: 4/5Safe 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 AIThis 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 |
| 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, |
There was a problem hiding this 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):
useProxyistrue→allowRfc2544BenchmarkRange: trueis passed, relaxing the SSRF guard for 198.18.0.0/15.EnvHttpProxyAgentdoesn't route through the proxy forALL_PROXY-only configs.- 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:
| 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.There was a problem hiding this comment.
💡 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".
| @@ -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(); | |||
There was a problem hiding this comment.
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 👍 / 👎.
e5e0dac to
5d38de2
Compare
|
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:
Tested locally with Clash fake-ip mode — web_fetch works correctly now. |
There was a problem hiding this comment.
💡 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".
| const envProxyConfigured = hasEnvHttpProxyConfigured(); | ||
| const allowRfc2544 = envProxyConfigured || params.allowFakeIp; |
There was a problem hiding this comment.
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 👍 / 👎.
There was a problem hiding this comment.
💡 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".
| @@ -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; | |||
There was a problem hiding this comment.
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.
7e2326b to
82f36fd
Compare
There was a problem hiding this comment.
💡 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".
| const protocol = parsedUrl.protocol.replace(":", "") as "http" | "https"; | ||
| const envProxyConfigured = hasEnvHttpProxyConfigured(protocol); | ||
| const allowRfc2544 = envProxyConfigured || params.allowFakeIp; | ||
| const result = await fetchWithWebToolsNetworkGuard({ |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
💡 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".
| // 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, |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
💡 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; |
There was a problem hiding this comment.
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.
|
Update: Final Solution / 最终方案 EnglishThis 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:
Security model: Why only config-based:
──────────────────────────────────────────────────────────────────────────────── 中文此 PR 为 fake-ip 代理兼容性(Clash TUN 模式、Surge 等)提供了简洁安全的解决方案: 配置(必须) {
"tools": {
"web": {
"fetch": {
"allowFakeIp": true
}
}
}
}工作原理:
安全模型: 为什么只基于配置:
──────────────────────────────────────────────────────────────────────────────── Related: #31176 (trusted endpoint path only) |
|
@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. |
|
close in favor of #58034 |
|
ok,close in favor of #58034
Michael
***@***.***
|
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:
Testing
Tested locally with Clash fake-ip mode enabled — web_fetch works correctly.
Related: #31176