fix(gateway): allow local connections in trusted-proxy auth mode#54426
fix(gateway): allow local connections in trusted-proxy auth mode#54426t2wei wants to merge 1 commit intoopenclaw:mainfrom
Conversation
When gateway.auth.mode is "trusted-proxy", local direct connections (e.g. ACPX child processes connecting back to the gateway) are rejected because they lack the proxy user header. This breaks ACP functionality in any trusted-proxy deployment. The trusted-proxy branch in authorizeGatewayConnect() performs a hard early return without considering localDirect — even though the variable is already computed. Add a fallback that allows local direct connections when trusted-proxy auth fails, since these connections originate from processes spawned by the gateway itself.
Greptile SummaryThis PR fixes a regression in Key points:
Confidence Score: 4/5
Prompt To Fix All With AIThis is a comment left during a code review.
Path: src/gateway/auth.ts
Line: 401-403
Comment:
**Missing test coverage for new bypass path**
The new `localDirect` bypass in `trusted-proxy` mode has no corresponding test cases in `auth.test.ts`. This is a security-sensitive code path (it allows requests to skip authentication entirely), and the existing `describe("trusted-proxy auth", ...)` suite doesn't exercise it at all.
At minimum, tests should cover:
- A localhost connection without proxy headers is accepted with `{ method: "none", user: "local" }`.
- A proxied request (correct remote addr, missing user header, `host: localhost`) is still rejected (i.e., `isLocalDirectRequest` returns false for proxied traffic even when `host` is localish).
- The early-exit paths (`trusted_proxy_config_missing`, `trusted_proxy_no_proxies_configured`) still reject local connections (confirming they are intentionally excluded from the bypass).
How can I resolve this? If you propose a fix, please make it concise.Reviews (1): Last reviewed commit: "fix(gateway): allow local connections in..." | Re-trigger Greptile |
| if (localDirect) { | ||
| return { ok: true, method: "none", user: "local" }; | ||
| } |
There was a problem hiding this comment.
Missing test coverage for new bypass path
The new localDirect bypass in trusted-proxy mode has no corresponding test cases in auth.test.ts. This is a security-sensitive code path (it allows requests to skip authentication entirely), and the existing describe("trusted-proxy auth", ...) suite doesn't exercise it at all.
At minimum, tests should cover:
- A localhost connection without proxy headers is accepted with
{ method: "none", user: "local" }. - A proxied request (correct remote addr, missing user header,
host: localhost) is still rejected (i.e.,isLocalDirectRequestreturns false for proxied traffic even whenhostis localish). - The early-exit paths (
trusted_proxy_config_missing,trusted_proxy_no_proxies_configured) still reject local connections (confirming they are intentionally excluded from the bypass).
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/gateway/auth.ts
Line: 401-403
Comment:
**Missing test coverage for new bypass path**
The new `localDirect` bypass in `trusted-proxy` mode has no corresponding test cases in `auth.test.ts`. This is a security-sensitive code path (it allows requests to skip authentication entirely), and the existing `describe("trusted-proxy auth", ...)` suite doesn't exercise it at all.
At minimum, tests should cover:
- A localhost connection without proxy headers is accepted with `{ method: "none", user: "local" }`.
- A proxied request (correct remote addr, missing user header, `host: localhost`) is still rejected (i.e., `isLocalDirectRequest` returns false for proxied traffic even when `host` is localish).
- The early-exit paths (`trusted_proxy_config_missing`, `trusted_proxy_no_proxies_configured`) still reject local connections (confirming they are intentionally excluded from the bypass).
How can I resolve this? If you propose a fix, please make it concise.There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f45ff858ed
ℹ️ 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 (localDirect) { | ||
| return { ok: true, method: "none", user: "local" }; |
There was a problem hiding this comment.
Gate trusted-proxy local fallback to verified internal callers
Allowing localDirect to unconditionally return ok: true here turns any loopback request into authenticated access when trusted-proxy checks fail. localDirect is based on loopback/local-host heuristics, so a reverse proxy running on the same host can satisfy it (for example by forwarding with a local Host header and missing/stripped proxy headers), which lets external traffic bypass trusted-proxy identity/header enforcement entirely. This broadens auth bypass far beyond ACPX child processes and weakens trusted-proxy mode in common colocated-proxy deployments.
Useful? React with 👍 / 👎.
ACPX child processes connect back to the gateway via localhost without proxy headers, causing trusted_proxy_user_missing rejection. Add localDirect fallback in the trusted-proxy auth branch. Upstream PR: openclaw#54426 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
Closing this as duplicate or superseded after Codex automated review. Close #54426 as superseded by #69066. The PR addresses real trusted-proxy/internal-caller pain, but current main intentionally fails closed for loopback-source trusted-proxy requests, and #69066 is the open canonical design track for separating internal service identity from user auth rather than merging this broad localDirect bypass. Best possible solution: Close #54426 as superseded by #69066. Keep current main's fail-closed trusted-proxy loopback behavior, and pursue a first-class internal service identity or another explicitly gated fallback through the canonical trusted-proxy auth design track rather than merging this blanket localDirect method:none bypass. What I checked:
So I’m closing this here and keeping the remaining discussion on the canonical linked item. Codex Review notes: model gpt-5.5, reasoning high; reviewed against 6cd047e7c270. |
Summary
gateway.auth.modeistrusted-proxy, ACPX child processes connecting back to the gateway via localhost are rejected because they lack the proxy user header (e.g.x-amzn-oidc-data)authorizeGatewayConnect()trusted-proxy branch performs a hard early return without consideringlocalDirect, even though the variable is already computed at that pointFix
When trusted-proxy auth fails and the connection is a local direct request (
localDirect === true), fall through withmethod: "none"instead of rejecting. These connections originate from processes spawned by the gateway itself (ACPX/Codex CLI), so they are inherently trusted.Test plan
gateway.auth.mode: "trusted-proxy"behind a reverse proxy🤖 Generated with Claude Code