Repository navigation
skip DNS pinning when routing through env proxy in trusted mode - #46318
extrasmall0 wants to merge 2 commits into
Conversation
resolvePinnedHostnameWithPolicy runs before the proxy dispatcher is selected, so in proxy-only networks (no direct DNS) it fails with getaddrinfo EAI_AGAIN before EnvHttpProxyAgent gets a chance to handle the request. Move the trusted-env-proxy check ahead of DNS pinning so the proxy handles name resolution directly.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1ba3c92244
ℹ️ 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".
| if (canUseTrustedEnvProxy) { | ||
| // Skip DNS pinning when routing through an env proxy — the proxy | ||
| // handles name resolution, so a local lookup would fail in | ||
| // proxy-only environments (e.g. getaddrinfo EAI_AGAIN). | ||
| dispatcher = new EnvHttpProxyAgent(); | ||
| } else if (params.pinDns !== false) { | ||
| dispatcher = createPinnedDispatcher(pinned, params.dispatcherPolicy); | ||
| } else { |
There was a problem hiding this comment.
Keep SSRF policy checks when env proxy mode is enabled
When mode === TRUSTED_ENV_PROXY and proxy env vars are present, this branch now skips resolvePinnedHostnameWithPolicy(...) entirely, which also skips hostname allowlist and private/special-use host/IP validation (including redirect-hop revalidation) that used to run before every request. In proxy-enabled deployments, a trusted-mode request can now follow or initiate fetches to blocked/internal targets without raising SsrFBlockedError, so this change weakens SSRF protections rather than only disabling DNS pinning.
Useful? React with 👍 / 👎.
Greptile SummaryThis PR fixes a real operational issue: Key concern — SSRF policy enforcement is now silently bypassed in proxy mode:
Confidence Score: 3/5
Prompt To Fix All With AIThis is a comment left during a code review.
Path: src/infra/net/fetch-guard.ts
Line: 195-208
Comment:
**`hostnameAllowlist` and blocked-hostname enforcement silently bypassed in proxy mode**
Before this PR, `resolvePinnedHostnameWithPolicy` was called unconditionally, meaning two independent SSRF checks still fired even when `canUseTrustedEnvProxy` was true:
1. **`hostnameAllowlist` enforcement** (`ssrf.ts` line 307-309) — a `SsrFBlockedError` would be thrown for any hostname not matching the caller's allowlist.
2. **Blocked hostname / private-IP literal check** (`ssrf.ts` lines 311-313) — `localhost`, `metadata.google.internal`, `*.internal`, private IP literals, etc. were all blocked.
After this change, both checks are skipped entirely for `TRUSTED_ENV_PROXY` mode. Callers that combine `mode: TRUSTED_ENV_PROXY` with `policy: { hostnameAllowlist: [...] }` will now find their allowlist silently ignored — all URLs are forwarded to the proxy without any hostname validation. Similarly, a URL such as `http://metadata.google.internal/` (or an RFC-1918 literal) would previously have been rejected; it is now forwarded to the proxy.
If the intent is that the proxy itself is the sole enforcement boundary in this mode, this should at minimum be documented clearly on `GuardedFetchOptions.policy` and `withTrustedEnvProxyGuardedFetchMode`, and a test should be added showing that a `hostnameAllowlist` is **not** honoured in proxy mode (so that future maintainers understand this is intentional, not an omission). If the `hostnameAllowlist` is supposed to remain enforceable even through a proxy, the allowlist check needs to be lifted out of `resolvePinnedHostnameWithPolicy` and applied before the `canUseTrustedEnvProxy` branch.
How can I resolve this? If you propose a fix, please make it concise.Last reviewed commit: 1ba3c92 |
| if (canUseTrustedEnvProxy) { | ||
| // Skip DNS pinning when routing through an env proxy — the proxy | ||
| // handles name resolution, so a local lookup would fail in | ||
| // proxy-only environments (e.g. getaddrinfo EAI_AGAIN). | ||
| dispatcher = new EnvHttpProxyAgent(); | ||
| } else if (params.pinDns !== false) { | ||
| dispatcher = createPinnedDispatcher(pinned, params.dispatcherPolicy); | ||
| } else { | ||
| const pinned = await resolvePinnedHostnameWithPolicy(parsedUrl.hostname, { | ||
| lookupFn: params.lookupFn, | ||
| policy: params.policy, | ||
| }); | ||
| if (params.pinDns !== false) { | ||
| dispatcher = createPinnedDispatcher(pinned, params.dispatcherPolicy); | ||
| } | ||
| } |
There was a problem hiding this comment.
hostnameAllowlist and blocked-hostname enforcement silently bypassed in proxy mode
Before this PR, resolvePinnedHostnameWithPolicy was called unconditionally, meaning two independent SSRF checks still fired even when canUseTrustedEnvProxy was true:
hostnameAllowlistenforcement (ssrf.tsline 307-309) — aSsrFBlockedErrorwould be thrown for any hostname not matching the caller's allowlist.- Blocked hostname / private-IP literal check (
ssrf.tslines 311-313) —localhost,metadata.google.internal,*.internal, private IP literals, etc. were all blocked.
After this change, both checks are skipped entirely for TRUSTED_ENV_PROXY mode. Callers that combine mode: TRUSTED_ENV_PROXY with policy: { hostnameAllowlist: [...] } will now find their allowlist silently ignored — all URLs are forwarded to the proxy without any hostname validation. Similarly, a URL such as http://metadata.google.internal/ (or an RFC-1918 literal) would previously have been rejected; it is now forwarded to the proxy.
If the intent is that the proxy itself is the sole enforcement boundary in this mode, this should at minimum be documented clearly on GuardedFetchOptions.policy and withTrustedEnvProxyGuardedFetchMode, and a test should be added showing that a hostnameAllowlist is not honoured in proxy mode (so that future maintainers understand this is intentional, not an omission). If the hostnameAllowlist is supposed to remain enforceable even through a proxy, the allowlist check needs to be lifted out of resolvePinnedHostnameWithPolicy and applied before the canUseTrustedEnvProxy branch.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/infra/net/fetch-guard.ts
Line: 195-208
Comment:
**`hostnameAllowlist` and blocked-hostname enforcement silently bypassed in proxy mode**
Before this PR, `resolvePinnedHostnameWithPolicy` was called unconditionally, meaning two independent SSRF checks still fired even when `canUseTrustedEnvProxy` was true:
1. **`hostnameAllowlist` enforcement** (`ssrf.ts` line 307-309) — a `SsrFBlockedError` would be thrown for any hostname not matching the caller's allowlist.
2. **Blocked hostname / private-IP literal check** (`ssrf.ts` lines 311-313) — `localhost`, `metadata.google.internal`, `*.internal`, private IP literals, etc. were all blocked.
After this change, both checks are skipped entirely for `TRUSTED_ENV_PROXY` mode. Callers that combine `mode: TRUSTED_ENV_PROXY` with `policy: { hostnameAllowlist: [...] }` will now find their allowlist silently ignored — all URLs are forwarded to the proxy without any hostname validation. Similarly, a URL such as `http://metadata.google.internal/` (or an RFC-1918 literal) would previously have been rejected; it is now forwarded to the proxy.
If the intent is that the proxy itself is the sole enforcement boundary in this mode, this should at minimum be documented clearly on `GuardedFetchOptions.policy` and `withTrustedEnvProxyGuardedFetchMode`, and a test should be added showing that a `hostnameAllowlist` is **not** honoured in proxy mode (so that future maintainers understand this is intentional, not an omission). If the `hostnameAllowlist` is supposed to remain enforceable even through a proxy, the allowlist check needs to be lifted out of `resolvePinnedHostnameWithPolicy` and applied before the `canUseTrustedEnvProxy` branch.
How can I resolve this? If you propose a fix, please make it concise.web_fetch fails with getaddrinfo EAI_AGAIN behind HTTP proxy because fetchWithWebToolsNetworkGuard uses strict mode with DNS pinning, bypassing proxy env vars. Fix from openclaw#46306 root cause. 1. fetch-guard.ts: skip DNS pinning when routing through env proxy in TRUSTED_ENV_PROXY mode (proxy handles DNS) 2. web-fetch.ts: add useEnvProxy:true so web_fetch routes through configured env proxy Test: - fetch-guard.ssrf.test.ts: add DNS-pinning-skip test - web-fetch.ssrf.test.ts: stub proxy env vars in beforeEach Refs: openclaw#46306 openclaw#46318 openclaw#46538
|
Closing stale PR — will revisit if still relevant. Thanks! |
web_search and web_fetch fail with `getaddrinfo EAI_AGAIN` behind HTTP proxies even when the proxy env vars are correctly configured. The issue is that `fetchWithSsrFGuard` unconditionally runs `resolvePinnedHostnameWithPolicy` (a local DNS lookup) before checking whether it should delegate to `EnvHttpProxyAgent`. In proxy-only networks where the container has no direct DNS access, this lookup fails before the proxy gets involved.
Moved the trusted-env-proxy check ahead of the DNS pinning step so the proxy handles name resolution directly when `TRUSTED_ENV_PROXY` mode is active.
Added a test that verifies the DNS lookup function is never called when env proxy mode is active.
Fixes #46306