Skip to content

fix: strict guarded fetch fails before managed proxy DNS - #98951

Merged
joshavant merged 1 commit into
mainfrom
feature/issue-98925-managed-proxy-strict
Jul 2, 2026
Merged

joshavant merged 1 commit into
mainfrom
feature/issue-98925-managed-proxy-strict

Conversation

@momothemage

@momothemage momothemage commented Jul 2, 2026 •

Copy link
Copy Markdown
Contributor

Closes #98925

What Problem This Solves

Fixes an issue where users in managed proxy-only sandboxes could see strict/default guarded fetches fail before reaching the managed proxy when local DNS could not resolve, disagreed with, or rejected the target hostname.

Affected surfaces include guarded fetch callers that omit mode and therefore default to strict mode, such as channel/provider preflight and plugin HTTP paths described in #98925.

Why This Change Was Made

When OPENCLAW_PROXY_ACTIVE=1 and the HTTP(S) env proxy applies to the target URL, strict guarded fetch now keeps the pre-DNS hostname/IP-literal SSRF checks and dispatches through the managed env proxy without resolving the target locally. Direct strict mode and NO_PROXY targets still use DNS pinning, while exact configured local-origin bypass candidates still resolve/pin DNS so proxy.loopbackMode and loopback-only bypass policy remain enforced.

Provenance: current origin/main still called resolvePinnedHostnameWithPolicy() inside the strict managed-proxy branch before creating the env proxy dispatcher. The managed-proxy branch was introduced by #70044 and the configured-local-origin bypass path was later carried forward by #85707.

User Impact

Operators can rely on the managed proxy as the resolver/enforcement boundary for strict/default guarded fetches in proxy-only deployments. Google Chat, Mattermost, managed provider preflight, media, and web-tool paths no longer need caller-specific TRUSTED_ENV_PROXY workarounds just to avoid local DNS in active managed-proxy mode.

Security boundary note: this does not make ordinary strict mode proxy-aware just because proxy env vars exist. The proxy skip is limited to the OpenClaw managed proxy lifecycle, still respects whether the HTTP(S) env proxy applies to the URL, still blocks private IP literals/blocked hostnames before fetch, and still revalidates redirects.

Evidence

  • node scripts/run-vitest.mjs src/infra/net/fetch-guard.ssrf.test.ts src/infra/net/proxy-env.test.ts
  • node scripts/run-oxlint.mjs src/infra/net/fetch-guard.ts src/infra/net/configured-local-origin-bypass.ts src/infra/net/fetch-guard.ssrf.test.ts
  • pnpm exec oxfmt --check src/infra/net/fetch-guard.ts src/infra/net/configured-local-origin-bypass.ts src/infra/net/fetch-guard.ssrf.test.ts
  • git diff --check
  • codex review --base origin/main initially found a proxy.loopbackMode=block + NO_PROXY regression; fixed with an extra regression test and reran codex review --base origin/main, which reported no actionable regressions.
  • CI: Real behavior proof, Security High (network-ssrf-boundary), security-fast, check-lint, check-prod-types, check-test-types, check-guards, and the compact/check shards passed on PR fix: strict guarded fetch fails before managed proxy DNS #98951. Critical Quality (network-runtime-boundary) intentionally fast-failed because added test lines mention NO_PROXY; its log says boundary-sensitive lines require full CodeQL review, and the relevant full security checks passed.

Managed proxy-only behavior proof from a local CONNECT proxy setup:

{
  "proof": "strict managed-proxy guarded fetch skips local target DNS",
  "proxyUrl": "http://127.0.0.1:<ephemeral>",
  "managedFetch": {
    "status": 200,
    "body": "proxied-ok",
    "lookupCallsAfterManagedFetch": 0,
    "proxyEventsAfterManagedFetch": [
      {
        "type": "connect",
        "target": "proxy-only.example:80"
      },
      {
        "type": "tunnel-request",
        "requestLine": "GET /proxy-ok HTTP/1.1",
        "host": "host: proxy-only.example"
      }
    ]
  },
  "privateLiteral": {
    "blockedBeforeProxyDispatch": true,
    "proxyEventCountBefore": 2,
    "proxyEventCountAfter": 2
  },
  "redirectToPrivate": {
    "blockedAfterFirstProxyResponseBeforeSecondProxyDispatch": true,
    "proxyEventCountBefore": 2,
    "proxyEventCountAfter": 4,
    "redirectProxyEvents": [
      {
        "type": "connect",
        "target": "proxy-only.example:80"
      },
      {
        "type": "tunnel-request",
        "requestLine": "GET /redirect-to-private HTTP/1.1",
        "host": "host: proxy-only.example"
      }
    ]
  },
  "totalLookupCalls": 0
}

That proof used OPENCLAW_PROXY_ACTIVE=1, HTTP(S) proxy env vars pointing at a temporary local CONNECT proxy, an unresolvable target hostname (proxy-only.example), and a lookupFn that throws on any target DNS lookup. The successful 200 response and lookupCallsAfterManagedFetch: 0 show strict managed-proxy dispatch reached the proxy without local target DNS. The private literal and redirect checks show those unsafe targets were rejected before proxy dispatch.

AI-assisted: yes, implemented with Codex; I understand the changed guarded-fetch/proxy path and verified the security-sensitive cases above.

Additional Operator Proxy Policy Proof

To close the proxy-owned enforcement gap, I also ran a local operator-policy-equivalent CONNECT proxy proof. The proxy owns DNS for the target hostnames, maps test hostnames to public/private/link-local/loopback addresses, and rejects the CONNECT before opening a tunnel when the proxy-side resolved address is disallowed.

{
  "proof": "operator proxy policy resolves target and blocks private/link-local/loopback destinations after proxy-side DNS",
  "proxyUrl": "http://127.0.0.1:<ephemeral>",
  "proxyPolicy": {
    "resolver": "proxy-owned static DNS map for proof",
    "denyAfterResolution": [
      "127.0.0.0/8",
      "10.0.0.0/8",
      "169.254.0.0/16"
    ],
    "allowPublicExampleAddress": "93.184.216.34"
  },
  "publicAllowed": {
    "url": "http://policy-public.example/proxy-ok",
    "ok": true,
    "status": 200,
    "body": "proxied-policy-ok",
    "events": [
      {
        "type": "connect",
        "targetHost": "policy-public.example",
        "targetPort": "80",
        "proxyResolvedAddress": "93.184.216.34",
        "decision": "allow",
        "reason": "public-address"
      },
      {
        "type": "tunnel-request",
        "requestLine": "GET /proxy-ok HTTP/1.1",
        "host": "host: policy-public.example",
        "targetHost": "policy-public.example",
        "proxyResolvedAddress": "93.184.216.34",
        "decision": "allow",
        "reason": "public-address"
      }
    ],
    "lookupCallsAfter": 0
  },
  "loopbackDenied": {
    "url": "http://policy-loopback.example/private",
    "ok": false,
    "errorName": "TypeError",
    "errorMessage": "fetch failed",
    "events": [
      {
        "type": "connect",
        "targetHost": "policy-loopback.example",
        "targetPort": "80",
        "proxyResolvedAddress": "127.0.0.1",
        "decision": "deny",
        "reason": "loopback"
      }
    ],
    "lookupCallsAfter": 0
  },
  "privateDenied": {
    "url": "http://policy-private.example/private",
    "ok": false,
    "errorName": "TypeError",
    "errorMessage": "fetch failed",
    "events": [
      {
        "type": "connect",
        "targetHost": "policy-private.example",
        "targetPort": "80",
        "proxyResolvedAddress": "10.0.0.5",
        "decision": "deny",
        "reason": "rfc1918-private"
      }
    ],
    "lookupCallsAfter": 0
  },
  "linkLocalDenied": {
    "url": "http://policy-linklocal.example/metadata",
    "ok": false,
    "errorName": "TypeError",
    "errorMessage": "fetch failed",
    "events": [
      {
        "type": "connect",
        "targetHost": "policy-linklocal.example",
        "targetPort": "80",
        "proxyResolvedAddress": "169.254.169.254",
        "decision": "deny",
        "reason": "link-local-metadata"
      }
    ],
    "lookupCallsAfter": 0
  },
  "totalLookupCalls": 0
}

This proof is intentionally policy-equivalent rather than tied to a specific production proxy vendor: it demonstrates the required deployment contract for the strict managed-proxy branch. The proxy, not local DNS pinning, owns target DNS; after proxy-side DNS resolution, the proxy blocks loopback, RFC1918 private, and link-local/metadata targets before creating the tunnel, while public destinations still work through the same managed-proxy path.

@openclaw-barnacle openclaw-barnacle Bot added size: S maintainer Maintainer-authored PR labels Jul 2, 2026
@clawsweeper

clawsweeper Bot commented Jul 2, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed July 2, 2026, 5:24 PM ET / 21:24 UTC.

Summary
The PR changes strict guarded fetch managed-proxy routing so applicable managed proxy requests dispatch without local target DNS, while preserving configured local-origin bypass checks and SSRF regression tests.

PR surface: Source +22, Tests +111. Total +133 across 3 files.

Reproducibility: yes. Current main is source-reproducible because strict/default mode with OPENCLAW_PROXY_ACTIVE=1 and applicable proxy env reaches local DNS pinning before the env proxy dispatcher is created.

Review metrics: none identified.

Root-cause cluster
Relationship: fixed_by_candidate
Canonical: #98925
Summary: This PR is the candidate fix for the canonical strict/default guarded-fetch DNS-before-managed-proxy issue; related merged proxy work is provenance or partial overlap, not a replacement.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge readiness
Overall: 🐚 platinum hermit
Proof: 🦞 diamond lobster
Patch quality: 🐚 platinum hermit
Result: ready for maintainer review.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Rank-up moves:

  • none.

Risk before merge

  • [P1] Merging intentionally delegates final target DNS and resolved-IP/private-address enforcement to the active managed proxy for applicable strict/default guarded fetches; maintainers need to accept that security boundary.
  • [P1] The real behavior proof is strong policy-equivalent CONNECT proxy output, but a maintainer may still want production-proxy-specific proof before accepting the boundary change.

Maintainer options:

  1. Accept proxy-owned DNS enforcement (recommended)
    A maintainer/security owner can explicitly accept that applicable strict/default managed-proxy traffic relies on the active proxy for final DNS and resolved-IP enforcement.
  2. Ask for production-proxy proof
    Maintainers can require an additional redacted proof run against a real operator proxy policy if the local CONNECT proxy proof is not enough for this security boundary.
  3. Defer to the broader egress refactor
    Maintainers can pause this narrow PR if they want the broader HTTP egress redesign to own the full SSRF/proxy boundary instead.

Next step before merge

  • [P2] Protected maintainer labeling and the SSRF/managed-proxy boundary change make this a maintainer/security signoff item rather than an automated repair candidate.

Security
Needs attention: No supply-chain issue is apparent, but the patch intentionally changes the core SSRF/managed-proxy enforcement boundary and needs maintainer/security acceptance.

Review details

Best possible solution:

Land this shared fetch-guard fix after maintainer/security signoff accepts proxy-owned DNS enforcement for active managed-proxy strict/default traffic.

Do we have a high-confidence way to reproduce the issue?

Yes. Current main is source-reproducible because strict/default mode with OPENCLAW_PROXY_ACTIVE=1 and applicable proxy env reaches local DNS pinning before the env proxy dispatcher is created.

Is this the best way to solve the issue?

Mostly yes. The shared fetch guard is the right layer because many callers default to strict mode, and the PR preserves direct, NO_PROXY, configured-local-origin, loopback-mode, and redirect behavior; the remaining question is maintainer/security acceptance of proxy-owned enforcement.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 1a508d7915ef.

Label changes

Label justifications:

  • P1: The linked bug affects core guarded network fetches across managed-proxy channel and provider workflows in proxy-only deployments.
  • merge-risk: 🚨 security-boundary: The diff changes how strict SSRF DNS pinning and the managed proxy split DNS and private-IP enforcement responsibility.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The PR body includes after-fix live output showing managed-proxy dispatch succeeds with zero target DNS lookups and blocks private literal/redirect cases, plus proxy-side policy proof.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body includes after-fix live output showing managed-proxy dispatch succeeds with zero target DNS lookups and blocks private literal/redirect cases, plus proxy-side policy proof.
Evidence reviewed

PR surface:

Source +22, Tests +111. Total +133 across 3 files.

View PR surface stats
Area Files Added Removed Net
Source 2 38 16 +22
Tests 1 111 0 +111
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 149 16 +133

Security concerns:

  • [medium] Confirm proxy-owned DNS and IP enforcement — src/infra/net/fetch-guard.ts:539
    Applicable strict/default managed-proxy fetches no longer perform local resolved-IP checks before dispatch, so the active managed proxy must be accepted as the final DNS and private-IP enforcement boundary.
    Confidence: 0.9

What I checked:

  • Repository policy: Root AGENTS.md was read fully; its PR review, security-boundary, CODEOWNERS, and maintainer-review guidance applies to this network/security path. (AGENTS.md:6, 1a508d7915ef)
  • Live PR context: The PR is open, linked with closing syntax to the canonical bug, has the protected maintainer label, and targets head e9a39b1. (e9a39b1edf67)
  • Current main still reproduces from source: On current main, strict mode with active managed proxy still sets canUseManagedProxy and then resolves the target hostname locally before creating the env proxy dispatcher. (src/infra/net/fetch-guard.ts:505, 1a508d7915ef)
  • PR head changes the decision point: At PR head, canUseManagedProxy depends on active strict mode plus an applicable env HTTP(S) proxy or configured-local-origin bypass, and DNS resolution is limited to the configured-local-origin bypass sub-branch. (src/infra/net/fetch-guard.ts:514, e9a39b1edf67)
  • Pre-DNS SSRF checks remain available: The shared SSRF helper performs hostname allowlist and host/IP literal checks without DNS, while resolved-IP checks still occur in resolvePinnedHostnameWithPolicy when DNS pinning is used. (src/infra/net/ssrf.ts:581, 1a508d7915ef)
  • Configured local-origin bypass is preserved: The PR adds a helper that only asks for local DNS when the request is an exact configured loopback origin, preserving the loopback-mode and pinned-address proof path. (src/infra/net/configured-local-origin-bypass.ts:63, e9a39b1edf67)

Likely related people:

  • jesse-merhi: Merged proxy-routing history introduced the operator-managed proxy routing and touched fetch guard, proxy lifecycle, and network proxy docs that this PR depends on. (role: introduced managed proxy lifecycle; confidence: high; commits: 2633b1491413, 6921d9072e91; files: src/infra/net/fetch-guard.ts, src/infra/net/proxy/proxy-lifecycle.ts, docs/security/network-proxy.md)
  • Kaspre: Merged configured-local-origin and exact-origin SSRF trust work owns the loopback bypass behavior this PR must preserve. (role: recent managed-proxy loopback boundary contributor; confidence: high; commits: fd2a9adbe6b0, 44840007d42d; files: src/infra/net/configured-local-origin-bypass.ts, src/infra/net/fetch-guard.ts, src/infra/net/fetch-guard.ssrf.test.ts)
  • steipete: Recent history shows work on trusted env proxy opt-in, NO_PROXY/CIDR handling, proxy docs, and guarded-fetch helper documentation near this path. (role: recent guarded-fetch and proxy helper contributor; confidence: high; commits: 66336bf7c846, a95d7ab1c81b, a23a668d91b3; files: src/infra/net/fetch-guard.ts, src/infra/net/proxy-env.ts, docs/security/network-proxy.md)
  • cluster2600: Earlier merged work fixed the DNS-before-proxy ordering for explicit trusted env-proxy mode in the same guarded-fetch function. (role: adjacent trusted-proxy DNS-ordering contributor; confidence: medium; commits: 2a915fb22d15, d7c3210cd6f5; files: src/infra/net/fetch-guard.ts, src/infra/net/fetch-guard.ssrf.test.ts)
  • joshavant: Live PR timeline assigns this PR to joshavant, and merged proxy-routing history includes adjacent hardening contributions in the managed-proxy boundary. (role: assigned reviewer and adjacent proxy hardening contributor; confidence: medium; commits: 2633b1491413, 1a508d7915ef; files: src/infra/net/proxy/proxy-lifecycle.ts, .github/workflows/codeql-critical-quality.yml)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

How this review workflow works
  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. labels Jul 2, 2026
@momothemage

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jul 2, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

@momothemage

Copy link
Copy Markdown
Contributor Author

@clawsweeper review

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Jul 2, 2026
@momothemage

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@joshavant
joshavant force-pushed the feature/issue-98925-managed-proxy-strict branch from 0478a1d to e9a39b1 Compare July 2, 2026 21:19
@joshavant
joshavant merged commit cb6611d into main Jul 2, 2026
97 checks passed
@joshavant
joshavant deleted the feature/issue-98925-managed-proxy-strict branch July 2, 2026 21:29
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintainer Maintainer-authored PR merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: S status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fetchWithSsrFGuard strict mode resolves DNS locally before managed proxy

2 participants