fix(net): respect HTTP proxy env vars in web_fetch SSRF dispatcher#25573
Open
makew0rld wants to merge 3 commits intoopenclaw:mainfrom
Open
fix(net): respect HTTP proxy env vars in web_fetch SSRF dispatcher#25573makew0rld wants to merge 3 commits intoopenclaw:mainfrom
makew0rld wants to merge 3 commits intoopenclaw:mainfrom
Conversation
When HTTP_PROXY/HTTPS_PROXY env vars are set, createPinnedDispatcher now returns an undici EnvHttpProxyAgent instead of a plain Agent. This allows web_fetch (and all fetchWithSsrFGuard callers) to route through the configured proxy. DNS pinning is skipped when proxying since the proxy handles resolution; SSRF hostname/IP pre-checks still run beforehand. Related openclaw#2102 Related openclaw#8534 Supersedes openclaw#24625 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
15 tasks
Use delete for undefined env vars instead of assigning undefined (which would set them to the string "undefined"). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2 tasks
|
This pull request has been automatically marked as stale due to inactivity. |
Author
|
This is not outdated, I just need a review and merge. |
Pass proxyTunnel: false to EnvHttpProxyAgent so plain HTTP targets use proper absolute-URI style proxying (GET http://host/path) instead of CONNECT tunneling. Some proxies reject CONNECT for non-TLS traffic. HTTPS targets still correctly use CONNECT regardless of this flag. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
web_fetch(and allfetchWithSsrFGuardcallers) ignoreHTTP_PROXY/HTTPS_PROXYenv vars becausecreatePinnedDispatchercreates a plain undiciAgentthat overrides the global dispatcher, bypassing all proxy settings.web_fetchat all, even when proxy env vars are correctly configured and work for other HTTP clients (e.g., Anthropic API calls, curl).createPinnedDispatchernow detects proxy env vars and returns an undiciEnvHttpProxyAgent(which readsHTTP_PROXY,HTTPS_PROXY,NO_PROXYautomatically) instead of a plainAgent. Added 4 tests covering all env var variants.resolvePinnedHostnameWithPolicystill run before the dispatcher is created. The non-proxy code path (plainAgentwith DNS pinning) is untouched.web_searchbarefetch()calls are not in scope.This is a resubmission of #24625, which was closed via automated stale-fix triage because #2102 was closed as NOT_PLANNED. The bug is still present on current main —
createPinnedDispatcherstill creates a plainAgentwith no proxy awareness.Change Type (select all)
Scope (select all touched areas)
Linked Issue/PR
User-visible / Behavior Changes
web_fetch(and other tools usingfetchWithSsrFGuard) now route through the user's configured HTTP proxy whenHTTP_PROXY/HTTPS_PROXY(or lowercase variants) env vars are set.NO_PROXYis also respected viaEnvHttpProxyAgent.Security Impact (required)
NoNoYes— when proxy env vars are set,web_fetchHTTP requests are routed through the proxy instead of directly. This is user-initiated behavior (requires explicit proxy env var configuration).NoNoresolvePinnedHostnameWithPolicystill execute before the dispatcher is created, maintaining protection against requests to private/internal addresses. The proxy path only activates when the user has explicitly configured proxy env vars.Repro + Verification
Environment
HTTP_PROXY=http://proxy:8080,HTTPS_PROXY=http://proxy:8080Proxy setup
For systemd-managed OpenClaw (e.g. gateway running as a service), env vars can be set globally via a drop-in override:
Then add:
Then
sudo systemctl daemon-reload && sudo systemctl restart openclaw-gateway.Steps
HTTP_PROXY/HTTPS_PROXYenv vars pointing to a proxy server (via systemd override, shell, etc.)web_fetchto fetch any URLExpected
Request is routed through the configured proxy.
Actual (before fix)
Request bypasses proxy — the custom undici
Agentdispatcher overrides global proxy settings.Evidence
EnvHttpProxyAgentis used when proxy env vars are set, and plainAgentwhen notweb_fetchrequests now appear in proxy logsHuman Verification (required)
web_fetchsuccessfully routes through proxy on a VM withHTTPS_PROXYset via systemd override; all existing SSRF tests pass (36 tests across 3 test files)http_proxy), missing env vars (falls back to plainAgent), mixed env var configurationsNO_PROXYexclusion behavior (delegated to undici'sEnvHttpProxyAgentimplementation),web_searchtool (uses barefetch(), out of scope)Compatibility / Migration
Yes— no behavior change when proxy env vars are not setNo— reads existing standard env varsNoFailure Recovery (if this breaks)
HTTP_PROXY/HTTPS_PROXYenv vars to fall back to plainAgent(existing behavior)src/infra/net/ssrf.tsweb_fetchfailing with connection errors when proxy env vars are set but proxy is unreachableRisks and Mitigations
AI-assisted: This PR was developed with Claude Code (Opus). Fully tested on a real proxy setup. I understand what the code does.
Greptile Summary
Adds proxy environment variable support to
web_fetchand allfetchWithSsrfGuardcallers by detectingHTTP_PROXY/HTTPS_PROXYenv vars increatePinnedDispatcherand returning anEnvHttpProxyAgentinstead of a plain undiciAgentwhen proxy configuration is detected.createPinnedDispatcher(src/infra/net/ssrf.ts:341-358) to check proxy env vars via newhasProxyEnvhelper and conditionally returnEnvHttpProxyAgentresolvePinnedHostnameWithPolicystill execute before dispatcher creation, maintaining security boundaryConfidence Score: 4/5
resolvePinnedHostnameWithPolicyexecute before the proxy dispatcher is created. The main trade-off is DNS pinning bypass when proxying, but this is an acceptable security posture for user-configured proxy scenarios. Tests adequately cover the proxy detection logic.Last reviewed commit: 1db58db
(3/5) Reply to the agent's comments like "Can you suggest a fix for this @greptileai?" or ask follow-up questions!