Skip to content

fix(secrets): exec can't reach local HTTP servers with the secret egress proxy enabled - #160974

Merged
steipete merged 5 commits into
mainfrom
steipete/egress-loopback-no-proxy
Sep 29, 2026
Merged

steipete merged 5 commits into
mainfrom
steipete/egress-loopback-no-proxy

Conversation

@steipete

@steipete steipete commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes local HTTP fixture and development-server requests failing with 502 when Gateway-hosted exec children use the secret egress proxy.

User Impact

Children using ordinary HTTP proxy forwarding can reach literal loopback HTTP origins while remaining subject to grant authentication, the traffic allowlist, refusal audit, and upload limits. Lockdown still refuses unbound loopback destinations, and localhost HTTPS secret substitution continues to work. No configuration or child-environment changes are required.

Why This Change Was Made

The maintainer decision is to keep loopback under proxy policy. This replaces the earlier NO_PROXY overlay, which bypassed both localhost HTTPS substitution and lockdown enforcement, with a narrow exception at the proxy boundary.

Only direct plain-HTTP requests to localhost, 127.0.0.0/8, or ::1 use HTTP forwarding. Eligibility is determined from the literal target, never DNS answers. The shared request owner retains authentication, destination policy, resource ownership, reservation/timeout limits, and audit. Its sentinel resolver refuses cleartext substitution in URLs, headers, fixed-length bodies, and streamed bodies. CONNECT and HTTPS retain their existing handling.

Evidence

Production LOC: +14 -> 0 (before +38/-24; after +47/-47 against merge base 6f4c801c18f911625c971fa6cb7c3bd4de1d5e87, excluding tests and test-support paths). The cleanup is confined to the two proxy implementation files.

Basic proxy authentication now returns validated token bytes directly, removing the intermediate password handoff without changing validation. Buffered allocation now uses the length already validated by admission, removing the private wrapper that repeated those bounds.

Cleanup revalidation: 132 focused tests passed in 199.21s wall, including the real-child loopback forwarding and lockdown regressions. Core typechecking, selected test-type graphs (agents-tools: 16.2s; gateway-root: 17.8s), core-lane typed lint, oxfmt, and diff checks passed. Fresh Codex autoreview at P1 is scoped-clean. Tests and model-facing text are unchanged; prompt snapshots are not applicable.

  • Focused proxy and exec-environment proof: 132 tests passed across 7 files, 476.16s wall including cold worker compilation. The existing localhost HTTPS substitution, CONNECT/bypass, WebSocket, revocation, buffering, and timeout tests passed.
  • New HTTP cases exercise real http.createServer origins for localhost, IPv4, and IPv6; non-loopback refusals; HTTP sentinel refusal; authentication; allowlisted/bound/bypass hosts; and lockdown.
  • Real child proof starts Node's HTTP client with the actual grant environment and NODE_USE_ENV_PROXY=1. It receives 200 and loopback-ok; the origin observes a different connection from the child's proxy connection, and audit records the forward. Under allowedHosts: [], the child receives the exact 403 remediation, audit records host-not-allowed, and the origin receives no request. Node's HTTP client exercises absolute-form forwarding; fetch can use CONNECT, and curl ignores uppercase HTTP_PROXY.
  • Regression control: with only the production fix stashed, both proxy files matched recorded origin/main revision 6c92ece5beeab4f1b975394c1ec62270dc9dfbfd. The child test failed with AssertionError: expected 502 to be 200; its lockdown counterpart failed with AssertionError: expected 502 to be 403. This control took 307.16s wall. An earlier full baseline run also failed all three loopback-forwarding cases (expected 200/body, received 502/refusal).
  • Candidate HTTP-file timing: 15 tests passed, 160.02s wall for the final file alone after lint cleanup (102.11s Vitest duration; 97% transform, 1% tests).
  • Gates: pnpm tsgo:core, targeted test types (agents-tools and gateway-root), formatting, and diff checks passed; the native core-scoped type-aware lint command passed with no diagnostics (the root-tsconfig form could not get past its extension-declaration preparation timeout). The full changed-scope gate was interrupted after eleven passing checks at 400.02s, before config-doc validation completed; it is not a full gate pass. The work-order time-budget exception applies to that unfinished run. The completed checks include conflict markers, line-cap/suppression/assertion ratchets, changelog attribution, Doctor registry, both wildcard-export guards, duplicate coverage, dependency pins, and formatting. The original proxy-boundary fix passed independent Codex review through P2; the subsequent production-LOC cleanup passed the fresh P1 review recorded above.
  • Optional full-Gateway proof is blocked before Gateway startup, not passing. The gated synthetic-provider test attempts real agent → exec → curl forwarding. The normal live harness first rejected the operator auth database's older schema before test collection (89.04s wall). A supported empty-home/state retry reached candidate freshness preparation, then stopped at UpdatePreMutationError: Runtime artifacts changed, but the affected Gateway is running or its offline state could not be verified. (94.88s wall; 18.032s test). No runtime-publication guard was bypassed and no operator state or Gateway was modified. The required real-child proof above passed.
Commands and timing scope
node scripts/run-vitest.mjs \
  src/secrets/egress-proxy/proxy-server.http.test.ts \
  src/secrets/egress-proxy/proxy-server.test.ts \
  src/secrets/egress-proxy/proxy-forward.test.ts \
  src/secrets/egress-proxy/proxy-server.lifecycle.test.ts \
  src/secrets/egress-proxy/proxy-server.websocket.test.ts \
  src/secrets/egress-proxy/proxy-worker.test.ts \
  src/agents/bash-tools.exec.store-env.test.ts --maxWorkers=1

node scripts/run-vitest.mjs src/secrets/egress-proxy/proxy-server.http.test.ts --maxWorkers=1
# Pre-fix control, production fix stashed:
node scripts/run-vitest.mjs src/secrets/egress-proxy/proxy-server.http.test.ts --maxWorkers=1 -t 'routes a real child through the proxy'

pnpm tsgo:core
# Native core lint, same source config selected by check-changed:
node scripts/run-oxlint.mjs --tsconfig config/tsconfig/oxlint.core.json src/secrets/egress-proxy/proxy-server.ts src/secrets/egress-proxy/proxy-forward.ts src/secrets/egress-proxy/proxy-server.http.test.ts src/secrets/egress-proxy/proxy-server.test.ts src/secrets/egress-proxy/registry.ts src/agents/bash-tools.exec-runtime.ts src/agents/bash-tools.exec.store-env.test.ts src/gateway/gateway-egress-loopback.live.test.ts
node scripts/run-tsgo-core-test-shards.mjs --changed-paths-json '["src/secrets/egress-proxy/proxy-server.http.test.ts","src/secrets/egress-proxy/proxy-server.test.ts","src/agents/bash-tools.exec.store-env.test.ts","src/gateway/gateway-egress-loopback.live.test.ts"]'

# Optional Gateway attempt; the retry used command-local empty HOME/state:
node --import ./scripts/tsx.mjs scripts/test-live.mts -- src/gateway/gateway-egress-loopback.live.test.ts --maxWorkers=1

# Final broad gate: interrupted after eleven passing checks, not a full pass.
node scripts/check-changed.mjs

The proxy shard passed 125 tests; the unchanged/restored exec-environment suite passed 7. Cold worker compilation dominates wall time (83% transform in the candidate proxy shard), rather than real timers or polling in the new HTTP tests. No new per-test Gateway boot, worker pin, or test timeout is added to the unit suite. CI timing is not yet available for the replacement head.

The interrupted changed-gate tail (SIGINT during the lint-cleanup edit window, not a config-doc mismatch):

   1.36s  ok         format changed files
   4.21s  failed:130  config docs baseline
[check:changed] FAILED (exit 130)
real 400.02

Gateway-hosted exec grants set HTTPS_PROXY/HTTP_PROXY and NODE_USE_ENV_PROXY without NO_PROXY, so proxy-aware clients tunneled loopback HTTP through the egress proxy, which refuses plain HTTP. Overlay the grant with NO_PROXY/no_proxy that keep existing host entries and add localhost, 127.0.0.1, and ::1.
@clawsweeper

clawsweeper Bot commented Sep 29, 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 agents Agent runtime and tooling size: XS labels Sep 29, 2026
@github-actions

github-actions Bot commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

⚠️ Security sensitive changes

This maintainer PR changes sensitive security components. This comment is informational because the PR author has repository Maintain or Admin access.

  • Current SHA: 44d9a4e5f73a39297872abca0f5872503f3b4d7f
  • Maintainer: @steipete
  • Repository role: admin

These security sensitive changes were made:

  • src/secrets/egress-proxy/proxy-forward.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.
  • src/secrets/egress-proxy/proxy-server.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.

Carefully review these changes before merging.

@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. 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 Sep 29, 2026
@clawsweeper

clawsweeper Bot commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 29, 2026, 6:28 AM ET / 10:28 UTC (Revision 4).

ClawSweeper review

What this changes

The branch lets Gateway-hosted exec children reach literal-loopback HTTP servers through the secret egress proxy, updates the security documentation, and adds proxy and opt-in Gateway tests.

Merge readiness

✅ Ready for maintainer review

Current main still refuses plain HTTP through the secret egress proxy, so this PR remains useful. The final branch keeps the new loopback path under proxy authentication and destination policy; this review found no discrete blocking defect.

Priority: P2
Reviewed head: 44d9a4e5f73a39297872abca0f5872503f3b4d7f

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) The focused proxy change has convincing real-child boundary proof, negative security cases, and no supported blocking finding.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): The changed proxy owner is exercised by a real Node child and local HTTP server: the reported after-fix result is 200 with body and audit, while lockdown gives 403 without reaching the origin. The optional full-Gateway test did not start; no stored-data contract changes.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): The changed proxy owner is exercised by a real Node child and local HTTP server: the reported after-fix result is 200 with body and audit, while lockdown gives 403 without reaching the origin. The optional full-Gateway test did not start; no stored-data contract changes.
Evidence reviewed 10 items Current main still refuses the requested traffic: The fetched main revision rejects non-HTTPS direct proxy requests and has no loopback HTTP exception.
Introduced forwarding boundary: The new exception is limited to direct plain-HTTP requests for normalized literal loopback hosts; destination policy is checked before forwarding.
Final effect retains grant ownership: The HTTP upstream request uses the existing owned-resource path, whose send and socket boundaries check whether the process grant remains active.
Findings None None.
Security None None.

How this fits together

Gateway-hosted exec gives each child process a proxy credential and secret sentinels. The local egress proxy authenticates requests, applies destination and secret rules, then forwards eligible traffic to the requested server.

flowchart LR
  A[Exec child] --> B[Proxy credential]
  B --> C[Local egress proxy]
  C --> D{Destination and secret rules}
  D --> E[Loopback HTTP server]
  D --> F[HTTPS server]
  D --> G[Refusal and audit]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +7, Tests +521, Docs 0. Total +528 across 6 files.

View PR surface stats
Area Files Added Removed Net
Source 2 46 39 +7
Tests 3 522 1 +521
Docs 1 2 2 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 6 570 42 +528

Review metrics

Metric Value Why it matters
Production and test delta production +7 net lines; tests +521 net lines The production growth is tied to one forwarding path and most added code is behavioral proof; the PR body's zero-net production figure does not match the pinned introduced diff.

Technical review

Best possible solution:

Keep the proxy-owned loopback exception with its existing grant, allowlist, revocation, and sentinel controls, and preserve the documented cleartext limits.

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

Yes. Current main unconditionally refuses direct plain HTTP, and the PR reports a real-child control receiving 502 before the change versus 200 afterward.

Is this the best way to solve the issue?

Yes. The final branch places the exception in the proxy's existing authorization and forwarding owner; the earlier environment bypass identified in review was removed.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 876334dc7f7f.

Labels

Label changes:

  • add rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster. Replaced prior rating: 🐚 platinum hermit.
  • remove rating: 🐚 platinum hermit: Current PR rating is rating: 🦞 diamond lobster, so this older rating label is no longer current.

Label justifications:

  • P2: This restores a limited local-development workflow for users who enable the secret egress proxy.
  • merge-risk: 🚨 security-boundary: The intentional HTTP exception expands what an authenticated grant can forward; the documented tradeoff remains subject to existing policy and sentinel refusal.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster. Replaced prior rating: 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The changed proxy owner is exercised by a real Node child and local HTTP server: the reported after-fix result is 200 with body and audit, while lockdown gives 403 without reaching the origin. The optional full-Gateway test did not start; no stored-data contract changes.
  • proof: sufficient: Contributor real behavior proof is sufficient. The changed proxy owner is exercised by a real Node child and local HTTP server: the reported after-fix result is 200 with body and audit, while lockdown gives 403 without reaching the origin. The optional full-Gateway test did not start; no stored-data contract changes.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Vincent Koc: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
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.

Workflow

  • 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.

History

Review history (3 earlier review cycles)
  • reviewed 2026-09-29T05:10:34.952Z sha 89665e8 :: needs real behavior proof before merge. :: [P1] Preserve HTTPS loopback secret substitution | [P1] Keep configured loopback traffic restrictions effective
  • reviewed 2026-09-29T08:21:33.391Z sha 8bdc0cd :: needs changes before merge. :: [P3] Qualify the earlier non-HTTPS security warning
  • reviewed 2026-09-29T08:45:12.893Z sha e08031b :: needs maintainer review before merge. :: none

Replace the NO_PROXY overlay with literal-loopback HTTP forwarding inside the
proxy. Keep authentication, destination policy, audit, upload limits, and
sentinel refusal on the shared forwarding path so localhost HTTPS substitution
and lockdown retain their existing behavior.

Cover actual child-process forwarding and lockdown, preserve HTTPS coverage,
and document the cleartext exception. The optional gated Gateway proof remains
blocked by runtime artifact publication on this host; real-child proof passes.
@openclaw-barnacle openclaw-barnacle Bot added size: L and removed agents Agent runtime and tooling size: XS labels Sep 29, 2026
@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 Sep 29, 2026
@clawsweeper clawsweeper Bot removed the merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. label Sep 29, 2026
Decode Basic proxy authorization directly to validated token bytes, removing
the intermediate password handoff while preserving every authentication check.
Remove the private allocation wrapper whose length checks duplicate buffered
request admission.

Production delta for the complete PR is now zero (+47/-47), down from +14.
The earlier buffered-path guard already bounds the length, but static analysis cannot see it across the branch; keep the explicit check beside Buffer.allocUnsafeSlow (restores the pre-cleanup helper).
@steipete

Copy link
Copy Markdown
Contributor Author

Landing qualification: CI run 36554990288, attempt 1, fails src/agents/subagents/registry/subagent-control.publication.test.ts > revalidates the session after held publication preparation permits retirement with SessionDeliveryGenerationUnavailableError. The coordinator reproduced the same failure on current main (1 failed / 9 passed); this PR does not change that file or its session/subagent owner. The remaining cancelled jobs were stopped by the successful PR fail-fast monitor after this failure. Landing uses the explicitly authorized native pre-existing-failure exception; cancelled coverage is not claimed as passing.

@steipete
steipete merged commit 8b5c5dd into main Sep 29, 2026
115 of 214 checks passed
@steipete
steipete deleted the steipete/egress-loopback-no-proxy branch September 29, 2026 10:53
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via explicitly authorized admin squash with attributed pre-existing CI failures.

MarMarLabs added a commit to MarMarLabs/openclaw that referenced this pull request Sep 29, 2026
74 upstream commits, including a batch of core and Feishu test removals
(openclaw#161136) and the secret egress proxy fix for local HTTP servers
(openclaw#160974).

One conflict, in extensions/feishu/src/reply-dispatcher.test.ts, where
openclaw#161136 removed or shortened tests next to ones this branch edited. Test
curation follows main. Tests this branch did not change take upstream's
form, so the removed ones stay removed and the shortened ones take the
new shape.

"keeps oversized auto mode markdown final text on the chunked card path"
stays, since this branch changed its chunk limit so a fence fits. It moves
to reply-dispatcher.markdown-tables.test.ts, the sibling this branch keeps
its fence and table tests in, because keeping it in reply-dispatcher.test.ts
grew that over-cap file past the line-cap baseline, and the helper it used
there was removed. Its assertions are unchanged and read the mock calls
directly, in that file's style.

For the receipt loss test, openclaw#161136 kept only the text case, which is the
same as this branch's text row, so upstream's version is taken and the
card row this branch edited goes with it. "falls back to post mode for 6
tables with explicit renderMode=card" is kept once, in
reply-dispatcher.markdown-tables.test.ts where this branch moved the table
limit tests, rather than in both files. The two other tests moved there
that openclaw#161136 removed, the five table static card case and the six table
post case with streaming off, are removed from the moved copy as well,
together with the useNonStreamingAutoAccount helper only they used.
test/vitest/vitest.extension-database-workers-paths.mjs merged cleanly and
keeps this branch's outbound.handoff.test.ts entry.

Neither side changed the generated config baseline in this range.
build:docker ran in a separate detached checkout of this commit outside the
nested node_modules install. Regenerating there left every file as it was
(core 2475, channel 3788, plugin 4444), and the three generated-file checks
pass there.

Upstream deleted 26 test files in this range. None of them were added or
changed by this branch.

Feishu: 105 files and 1749 tests in the extension project, 17 files and
309 tests in the database-workers project, lower than the previous merge
because of openclaw#161136. The forwarder test and the routing guards pass, 431
tests. tsgo:core, tsgo:extensions, tsgo:extensions:test, tsgo:test:root,
the line-cap, max-lines and assertion-safety ratchets against
upstream/main, oxlint and oxfmt on the 43 changed code files all pass.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 30, 2026
…ess proxy enabled (openclaw#160974)

* fix(secrets): keep loopback direct under the secret egress proxy

Gateway-hosted exec grants set HTTPS_PROXY/HTTP_PROXY and NODE_USE_ENV_PROXY without NO_PROXY, so proxy-aware clients tunneled loopback HTTP through the egress proxy, which refuses plain HTTP. Overlay the grant with NO_PROXY/no_proxy that keep existing host entries and add localhost, 127.0.0.1, and ::1.

* fix(secrets): allow loopback HTTP through the secret egress proxy

Replace the NO_PROXY overlay with literal-loopback HTTP forwarding inside the
proxy. Keep authentication, destination policy, audit, upload limits, and
sentinel refusal on the shared forwarding path so localhost HTTPS substitution
and lockdown retain their existing behavior.

Cover actual child-process forwarding and lockdown, preserve HTTPS coverage,
and document the cleartext exception. The optional gated Gateway proof remains
blocked by runtime artifact publication on this host; real-child proof passes.

* docs(secrets): qualify the non-HTTPS egress warning for loopback HTTP

* refactor(secrets): fund loopback forwarding with nearby cleanup

Decode Basic proxy authorization directly to validated token bytes, removing
the intermediate password handoff while preserving every authentication check.
Remove the private allocation wrapper whose length checks duplicate buffered
request admission.

Production delta for the complete PR is now zero (+47/-47), down from +14.

* fix(secrets): keep the buffered body bound next to its allocation

The earlier buffered-path guard already bounds the length, but static analysis cannot see it across the branch; keep the explicit check beside Buffer.allocUnsafeSlow (restores the pre-cleanup helper).
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 merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. 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. security-sensitive-changed size: L 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.

2 participants