Skip to content

skip DNS pinning when routing through env proxy in trusted mode - #46318

Closed
extrasmall0 wants to merge 2 commits into
openclaw:mainfrom
extrasmall0:fix/web-tools-proxy-dns
Closed

extrasmall0 wants to merge 2 commits into
openclaw:mainfrom
extrasmall0:fix/web-tools-proxy-dns

Conversation

@extrasmall0

Copy link
Copy Markdown
Contributor

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

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.

@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: 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".

Comment on lines 195 to +200
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 {

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 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-apps

greptile-apps Bot commented Mar 14, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes a real operational issue: fetchWithSsrFGuard was calling resolvePinnedHostnameWithPolicy (a local DNS lookup) before checking whether to delegate to EnvHttpProxyAgent, causing EAI_AGAIN failures in proxy-only container environments where the container has no direct DNS access. Moving the canUseTrustedEnvProxy guard ahead of the DNS step is the right approach, and the new test cleanly demonstrates the fix.

Key concern — SSRF policy enforcement is now silently bypassed in proxy mode:

  • resolvePinnedHostnameWithPolicy previously ran unconditionally, so its SSRF checks applied even when TRUSTED_ENV_PROXY was active. Those checks include (a) hostnameAllowlist enforcement and (b) blocking of localhost, metadata.google.internal, *.internal, and private/legacy IP literals.
  • After this change, both checks are skipped entirely for TRUSTED_ENV_PROXY. A caller passing mode: TRUSTED_ENV_PROXY together with policy: { hostnameAllowlist: ['api.example.com'] } will now find their allowlist silently ignored — any URL will be forwarded to the proxy without validation.
  • If this bypass is intentional (proxy is the sole enforcement boundary), it should be documented on GuardedFetchOptions.policy/withTrustedEnvProxyGuardedFetchMode and covered by a test confirming the behaviour. If hostnameAllowlist should remain enforceable through a proxy, the allowlist check needs to be decoupled from resolvePinnedHostnameWithPolicy and applied before the proxy branch.

Confidence Score: 3/5

  • Safe to merge if TRUSTED_ENV_PROXY mode is never combined with a policy, but the silent SSRF policy bypass warrants review before landing.
  • The core DNS-skip fix is correct and well-tested. The concern is that the refactor inadvertently removes hostnameAllowlist and blocked-hostname enforcement for TRUSTED_ENV_PROXY mode — checks that were previously active as a side effect of the unconditional resolvePinnedHostnameWithPolicy call. Whether this is intentional or an oversight is unclear from the PR description, and there is no test covering the policy-bypass scenario.
  • Pay close attention to src/infra/net/fetch-guard.ts lines 195–208 — specifically whether callers ever combine TRUSTED_ENV_PROXY with a non-empty policy.
Prompt To Fix All 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.

Last reviewed commit: 1ba3c92

Comment on lines 195 to 208
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);
}
}

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.

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.

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.

Deniable9570 pushed a commit to Deniable9570/openclaw that referenced this pull request Mar 26, 2026
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
@extrasmall0

Copy link
Copy Markdown
Contributor Author

Closing stale PR — will revisit if still relevant. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

1 participant