Skip to content

fix(secrets): Node fetch in exec can't reach local HTTP servers with the secret egress proxy on - #186765

Merged
steipete merged 6 commits into
openclaw:mainfrom
ericcurtin:fix/egress-connect-loopback-http
Nov 5, 2026
Merged

steipete merged 6 commits into
openclaw:mainfrom
ericcurtin:fix/egress-connect-loopback-http

Conversation

@ericcurtin

@ericcurtin ericcurtin commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Closes #181524

What Problem This Solves

Fixes: stock Node 24 fetch from Gateway-hosted exec fails with UND_ERR_SOCKET when secret egress is enabled and the destination is a permitted loopback HTTP service. The repair also closes a CONNECT peer that ends without sending protocol bytes, instead of retaining its socket until the process grant is revoked.

User Impact

Exec can reach local Ollama, llama.cpp and similar HTTP servers through the authenticated proxy. Traffic policy, process revocation, audit and the prohibition on plaintext secret substitution remain enforced. No proxy bypass or new configuration is required. Thanks @ericcurtin for the original diagnosis and CONNECT support; their commits are preserved.

Why This Change Was Made

Node 24.22.1 (Undici 7.30.1) tunnels ordinary HTTP through CONNECT. Node 26.12.1 (Undici 8.12.2) uses direct proxy requests, which already worked. The proxy now classifies literal-loopback tunnel bytes and hands plaintext or TLS to the existing forwarding owner.

Both plaintext and TLS inner URLs are pinned to the CONNECT scheme, host and port before forwarding or secret substitution. Absolute and network-path origin changes are refused, and a forged Host cannot select the destination. Plaintext sentinels and WebSocket upgrades remain refused. The sniff has a 30-second deadline, removes its listeners/timer, and rechecks current grant authority immediately before either handoff. An empty read is a distinct EOF result and destroys the peer; it is never handed to the HTTP parser. Non-loopback and configured bypass policies remain unchanged.

Upstream routing still honors Gateway HTTP_PROXY/HTTPS_PROXY and NO_PROXY. The docs now explicitly say that a loopback HTTP address routed through an upstream proxy refers to that proxy's loopback interface. No secrets are substituted onto that cleartext route.

This source remains subject to the repository's security-sensitive review policy. Maintainer security approval is still required.

Evidence

Checksum-verified nodejs.org runtimes on macOS arm64, stock global fetch, real proxy process grants, and shared Ollama:

Runtime Main: version / embedding Final source: version / embedding
Node 24.22.1 UND_ERR_SOCKET (105 / 10 ms) 200 (464 / 165 ms), one finite 768-dimensional vector
Node 26.12.1 200 / 200 in the prior baseline proof 200 (19 / 18 ms), one finite 768-dimensional vector

Diagnostics confirm Node 24 uses CONNECT and both runtimes connect to the injected proxy. A prior isolated Gateway run on port 20453 used a real qwen2.5:7b agent turn to invoke stock Node 24.22.1 through exec: main failed /api/version and /api/embed; the repaired build returned 200 and a finite 768-dimensional nomic-embed-text vector. That Gateway proof is reused: the EOF follow-up changes only empty-peer handling, and the successful plaintext/TLS handoffs are unchanged. The final-source proxy probes above recheck stock fetch after that follow-up. Shared Ollama was neither restarted nor unloaded.

The EOF regression uses a raw socket: authenticated CONNECT 127.0.0.1:9, await 200, end(), then observe the proxy peer's end/close event and assert it was destroyed. It failed on commit 3bed05ce26cf14feb3ca5f3a7e0a8c8eb2a978f4 with expected false to be true; it contains no timers, sleeps or polling. It shares the existing reset/recovery test. Earlier origin/deadline/authority regressions also failed against the original contributor implementation before passing with the repair.

Validation: all 96 proxy, lifecycle and WebSocket tests passed on Node 24.22.1 (132.63s wrapper wall time; 94.97s Vitest) and Node 26.12.1 (94.18s wrapper; 84.58s Vitest). Summed case times stayed under five seconds per file. The final EOF regression failed against the prior production code in 68.49s, with the intended destroyed=false assertion, and the exact final production bytes were restored. All eight EOF/Basic-header cases passed in the final targeted rerun (66.31s wrapper wall time). Core and test types, scoped lint, format, baseline ratchets and the line-cap check pass. A one-line test-file cap overflow was corrected without removing coverage. Codex branch-mode autoreview of 15bec5ab81c2e1f4a10060d6551e37b8ec225264..0d16d58c5c85ed71217bb4a0eeceff08db093ea9 is scoped-clean at P0–P2 (0.88), with no accepted/actionable findings. The approved review scope excludes explicit source-context files; that scope limitation is retained.

The first CI run found five Bun-only test setup failures: Bun delivers HTTP connections without calling the JavaScript net.Server.emit method observed by the fixture. The fixture now captures real peer sockets through their public listener registrations, preserving the EOF/deadline/revocation assertions. The same five cases failed locally before the correction and passed afterward on the pinned Bun fork (15.30s), Node 24.22.1 (46.28s), and Node 26.12.1 (62.67s). Production code is unchanged by this test-only follow-up. Final-head CI passed all 33 selected jobs. ClawSweeper reviewed this final head with no actionable findings and 5/6 patch/proof scores; its only merge hold is maintainer security approval.

Production LOC: +108/-31 (net +77); test LOC: +472/-473 (net -1). The production growth implements protocol classification, origin pinning and bounded authority-safe handoff. The EOF follow-up adds one production line net; test cleanup uses standard promisified server closes to keep the complete regression change within the existing test-line budget. No baselines or ceilings were raised. The contributor branch incorporates main via a merge, without rebasing or replacing their commits.

Limitations and follow-up: a client that starts an HTTP header and then stalls can still retain its grant's socket until revocation, for plaintext and decrypted TLS. Node's header-timeout sweep starts on listening, while these per-tunnel servers receive sockets without listening. Simply assigning headersTimeout does not start that sweep, and an inactivity timeout would also change active request/upgrade semantics; that needs a separate lifecycle fix. GET //v1/models is parsed as a network-path URL and returns 400 in both tunnel modes; the TLS refusal is unchanged by this EOF follow-up. Clients should send /v1/models. Live proof covers macOS arm64, not Linux or Windows. No release or deployment is included.

@clawsweeper

clawsweeper Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime size: M labels Oct 28, 2026
@github-actions

github-actions Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

✅ Maintainer security changes approved

A maintainer approved this revision with an explicit security approval comment.

A later push requires a fresh approval comment for an external contributor's PR.

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 28, 2026
@clawsweeper

clawsweeper Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge.

What this changes

This PR supports permitted loopback HTTP inside CONNECT tunnels while preserving destination binding, secret refusal, and process revocation.

Example: Node 24.22.1 fetches http://127.0.0.1:11434/api/version through Gateway-hosted exec with secret egress enabled.

  • Before: The proxy sends plaintext tunnel traffic to its TLS handler, causing UND_ERR_SOCKET.
  • After: The authenticated tunnel uses HTTP forwarding and returns 200 when traffic policy permits the destination.

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) A focused repair with shipped-entry-point proof, meaningful negative boundary coverage, and no actionable findings; enforced approval and unfinished CI remain workflow gates.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): Supplied live output covers a real Gateway agent executing stock Node 24 fetch against permitted Ollama version and embedding endpoints, with failure on main and successful repaired responses; final-source Node 24/26 probes preserve that result. Production-path socket regressions cover forbidden origins, missing or revoked authority, plaintext sentinels, and cleanup before upstream delivery. The latest fixture-only revision leaves production bytes unchanged. Live coverage is macOS arm64.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Gateway-hosted Node 24 fetch cannot reach an otherwise permitted local HTTP service when secret egress is enabled.
Reason: This restores an existing documented capability across a real client transport, following the established proxy-policy direction and the feature owner's repair work.

Merge readiness

⛔ Blocked before merge - 1 item remains

Keep open: this PR fixes a current-main transport bug, with no actionable introduced defect found; current-head maintainer security approval remains enforced.

Priority: P2
Reviewed head: 0d16d58c5c85ed71217bb4a0eeceff08db093ea9

Before merge

  • Await maintainer action - A maintainer must complete security review and approve revision 0d16d58 through the enforced security-sensitive approval gate.

Findings

None.

Agent review details

How this fits together

The Gateway-owned secret-egress worker receives authenticated subprocess proxy requests, checks process and destination authority, and forwards permitted HTTP or HTTPS traffic without exposing protected credentials to the subprocess.

flowchart TD
  A[Gateway exec subprocess] --> B[Authenticated proxy]
  B --> C[CONNECT destination policy]
  C --> D[Loopback protocol detection]
  D --> E[HTTP or TLS request parser]
  E --> F[Shared forwarding and secret policy]
  F --> G[Permitted upstream service]
Loading

Technical review

Best possible solution:

Retain the proxy-owned CONNECT repair and merge after current-head security approval and required checks succeed.

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

The credential-free reproduction in #181524 and current-main TLS-only CONNECT dispatch establish the failure path; this read-only review ran no target code.

Is this the best way to solve the issue?

The patch repairs protocol dispatch at the existing proxy boundary, reuses forwarding policy, and preserves the earlier decision against a loopback bypass.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 97b24c9d15d5.

Provenance checked

  • Loopback HTTP forwarding keeps the original intent (8b5c5dd: Permit local HTTP through the proxy while retaining authentication, destination policy, audit, upload limits, and sentinel refusal.)
  • TLS and WebSocket request handling keeps the original intent (fix: support autoreview through managed secret egress #143354: Reuse authenticated forwarding and resource ownership for WebSocket handshakes and frames.)
  • Split TLS and HTTP endpoint keeps the original intent (69213b3: Compose TLS and HTTP servers to preserve actual TLS handling on the supported Bun runtime.)
  • Gateway environment proxy routing keeps the original intent (e6a1ed1: Honor Gateway HTTP_PROXY, HTTPS_PROXY, and NO_PROXY without changing destination authorization.)
  • CONNECT origin resolution changes intended behavior with a stated reason (7ac87c0: The prior handler resolved inner requests against the CONNECT destination; this PR explicitly explains and tests stricter origin pinning before forwarding or substitution.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit b9c6789 adds src/secrets/egress-proxy/proxy-server.ts:442 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: b9c6789560bc; files: src/secrets/egress-proxy/proxy-server.ts)
  • Jason (Json): Raw commit 0762f59 adds src/secrets/egress-proxy/proxy-server.ts:444 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: 0762f596752f; files: src/secrets/egress-proxy/proxy-server.ts)
  • Vincent Koc: Raw commit f84727d adds src/secrets/egress-proxy/proxy-forward.ts:239 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: f84727d39df1; files: src/secrets/egress-proxy/proxy-forward.ts)

PR surface

Source +77, Tests -1, Docs 0. Total +76 across 7 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 3 108 31 +77
Tests 3 472 473 -1
Docs 1 2 2 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 7 582 506 +76

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Review metrics

Metric Value Why it matters
Production versus test LOC Production +108/-31; tests +472/-473 Production growth provides protocol classification, origin pinning, and bounded handoff; fixture consolidation keeps test growth nonpositive.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: The bug blocks Node 24 fetch to permitted local HTTP services in Gateway-hosted exec when optional secret egress is enabled.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: ⏳ waiting on maintainer: Only explicit maintainer approvals or decisions remain; merge is still blocked.
  • proof: sufficient: Contributor real behavior proof is sufficient.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

History

Review history (3 earlier review cycles)
  • reviewed 2026-10-28T13:17:44.134Z sha 241972c :: needs real behavior proof before merge. :: none
  • reviewed 2026-10-29T23:06:05.166Z sha e136708 :: blocked before merge. :: none
  • reviewed 2026-11-05T07:47:43.731Z sha 02502ab :: blocked before merge. :: none

Reviewed November 5, 2026, 2:59 AM ET / 07:59 UTC (Revision 4).

@ericcurtin

Copy link
Copy Markdown
Contributor Author

Fixed the baseline ratchets (e136708) and added proof to the body. @clawsweeper re-review @steipete @joshavant PTAL when you get a chance. Thank you!

@ericcurtin

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: ⏳ waiting on maintainer Only explicit maintainer approvals or decisions remain; merge is still blocked. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 29, 2026
@ericcurtin

Copy link
Copy Markdown
Contributor Author

@vincentkoc @obviyus PTAL when you get a chance. It needs /allow-security-sensitive-change from a maintainer. Thank you!

steipete and others added 3 commits November 4, 2026 22:49
Keep Node 24 fetch working through the secret egress proxy without allowing
inner request targets to escape either plaintext or TLS tunnel origins.
Bound protocol detection and check current process authority before handoff.

Exercise stock Node fetch and raw tunnel requests, including origin changes,
plaintext sentinel refusal, idle peers and revocation during protocol sniffing.
Consolidate existing proxy fixtures without increasing the test-line budget.

Co-authored-by: Eric Curtin <[email protected]>
Distinguish an empty protocol read from plaintext so ended sockets never
enter the tunnel HTTP parser. Preserve origin pinning and grant checks.

Extend the raw-socket reset regression with authenticated CONNECT/200/EOF
and clarify upstream proxy routing for literal loopback HTTP destinations.
Keep test growth nonpositive by simplifying server cleanup fixtures.
@steipete

steipete commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Nov 5, 2026
@steipete

steipete commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Nov 5, 2026
@steipete

steipete commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

/allow-security-sensitive-change

@steipete
steipete merged commit 6769a69 into openclaw:main Nov 5, 2026
131 of 134 checks passed
@steipete

steipete commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

Merged via squash.

steipete added a commit that referenced this pull request Nov 5, 2026
#186765 moved the only external caller behind createRequestServer, so the unused export fails the deadcode scan. Keep the function and drop the export.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 6, 2026
…the secret egress proxy on (openclaw#186765)

* fix(secrets): Node fetch to local HTTP fails with the egress proxy

* test(secrets): fold CONNECT tunnel tests into proxy-server.test, drop type assertion

* fix(secrets): pin and bound loopback CONNECT tunnels

Keep Node 24 fetch working through the secret egress proxy without allowing
inner request targets to escape either plaintext or TLS tunnel origins.
Bound protocol detection and check current process authority before handoff.

Exercise stock Node fetch and raw tunnel requests, including origin changes,
plaintext sentinel refusal, idle peers and revocation during protocol sniffing.
Consolidate existing proxy fixtures without increasing the test-line budget.

Co-authored-by: Eric Curtin <[email protected]>

* fix(secrets): release CONNECT peers that end before sending bytes

Distinguish an empty protocol read from plaintext so ended sockets never
enter the tunnel HTTP parser. Preserve origin pinning and grant checks.

Extend the raw-socket reset regression with authenticated CONNECT/200/EOF
and clarify upstream proxy routing for literal loopback HTTP destinations.
Keep test growth nonpositive by simplifying server cleanup fixtures.

* test(secrets): observe CONNECT peers across Node and Bun

---------

Co-authored-by: Peter Steinberger <[email protected]>
Co-authored-by: Eric Curtin <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 6, 2026
openclaw#186765 moved the only external caller behind createRequestServer, so the unused export fails the deadcode scan. Keep the function and drop the export.
maplel pushed a commit to maplel/openclaw that referenced this pull request Nov 24, 2026
Adapt source 6769a69 (openclaw#186765). Preserve existing proxy authority, original controls and TLS resume companion; restore source tunnel controls and isolate sibling fixture proxy environment. Exact test allocation: 380 LF. Node24-specific fetch remains unqualified; current-parent proof follows.

(cherry picked from commit 6769a69)

Co-authored-by: Peter Steinberger <[email protected]>
Co-authored-by: RomneyDa <[email protected]>
(cherry picked from commit c9046c0b902ca80ae264f2dec1d52453892ea2dc)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation gateway Gateway runtime P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. security-sensitive-changed size: XL status: ⏳ waiting on maintainer Only explicit maintainer approvals or decisions remain; merge is still blocked.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Secret egress proxy closes Node fetch CONNECT tunnels to loopback HTTP (UND_ERR_SOCKET)

2 participants