#8571: fix: support system proxy in web_fetch SSRF dispatcher
stale
Cluster:
SSRF Protection Enhancements
### Description
This Pull Request fixes an issue where the `web_fetch` tool fails in restricted network environments that require a system proxy (e.g., Clash, corporate proxies).
### Problem
The `createPinnedDispatcher` function in `src/infra/net/ssrf.ts` was hardcoded to use a standard `undici.Agent`. This agent performs direct IP connections to prevent SSRF but ignores the standard Node.js proxy environment variables (`HTTPS_PROXY`, `HTTP_PROXY`). In environments where direct outgoing connections are blocked, `web_fetch` would consistently fail with `TypeError: fetch failed`.
### Solution
Updated `createPinnedDispatcher` to check for proxy environment variables. If a proxy is configured, it now returns a `undici.ProxyAgent`, allowing `web_fetch` to respect the system proxy while maintaining the required dispatcher architecture.
### Changes
- Updated imports in `src/infra/net/ssrf.ts` to include `ProxyAgent` from `undici`.
- Modified `createPinnedDispatcher` to prefer `ProxyAgent` if `HTTPS_PROXY` or `HTTP_PROXY` is set.
Verified this fix on a production instance behind a local proxy.
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
This PR updates `src/infra/net/ssrf.ts` to honor system proxy environment variables in `createPinnedDispatcher` by returning an `undici.ProxyAgent` when a proxy is configured, otherwise falling back to the existing pinned `undici.Agent` (with `connect.lookup` set to the pinned resolver). This is intended to make `web_fetch` work in restricted egress environments that require a proxy.
Key concern: the proxy branch changes the security model—requests will be routed through the proxy and DNS/connection pinning via `pinned.lookup` no longer applies to the ultimate destination—so SSRF protections may be weakened unless destination validation is enforced elsewhere in the fetch path.
<h3>Confidence Score: 2/5</h3>
- This PR is not safe to merge as-is if SSRF protections must hold in proxy-required deployments.
- While the change likely fixes connectivity behind proxies, switching to `ProxyAgent` bypasses the pinned DNS/connection behavior that existed specifically to mitigate SSRF; without additional destination enforcement, this can materially weaken security in environments where the proxy can reach internal networks. Minor env-var coverage issues also remain (missing `https_proxy`).
- src/infra/net/ssrf.ts (proxy branch in createPinnedDispatcher)
<!-- greptile_other_comments_section -->
<sub>(2/5) Greptile learns from your feedback when you react with thumbs up/down!</sub>
<!-- /greptile_comment -->
Most Similar PRs
#16144: fix: respect HTTP_PROXY/HTTPS_PROXY in SSRF-protected fetch (#2102)
by battman21 · 2026-02-14
85.0%
#16897: fix(tools): route web_search requests through HTTP proxy env vars
by battman21 · 2026-02-15
79.6%
#2657: fix: use TLS 1.2 for gemini-cli and google-antigravity OAuth reques...
by PrentissLiu · 2026-01-27
74.9%
#19525: security: add SSRF validation for external URLs
by Mozzzaic · 2026-02-17
74.5%
#15923: feat: add proxy support for web_search tool
by Shuai-DaiDai · 2026-02-14
73.7%
#8228: fix(link-understanding): block private IPs and internal hostnames i...
by yubrew · 2026-02-03
72.9%
#22644: feat(web-fetch): add allowPrivateNetwork config for web_fetch
by qingxuecc · 2026-02-21
72.5%
#14509: feat: setup and configure proxy system
by montelli99 · 2026-02-12
72.0%
#19660: fix: respect HTTP_PROXY/HTTPS_PROXY env vars for undici fetch
by 88plug · 2026-02-18
72.0%
#8305: fix(browser): add SSRF protection to browser navigation
by yubrew · 2026-02-03
71.9%