fix(gateway): trusted-proxy auth rejected when bind=loopback#20097
fix(gateway): trusted-proxy auth rejected when bind=loopback#20097mbelinky merged 1 commit intoopenclaw:mainfrom
Conversation
Additional Comments (1)
The test in It should be updated to instead assert that loopback + trusted-proxy succeeds when Prompt To Fix With AIThis is a comment left during a code review.
Path: src/gateway/server-runtime-config.ts
Line: 105-111
Comment:
**Existing test will fail after this change**
The test in `src/gateway/server-runtime-config.test.ts` (line 33) — `"should reject loopback binding with trusted-proxy auth mode"` — still expects this configuration to throw `"gateway auth mode=trusted-proxy makes no sense with bind=loopback"`. Since the throw was removed, this test will now fail.
It should be updated to instead assert that loopback + trusted-proxy **succeeds** when `trustedProxies` is configured (and still rejects when `trustedProxies` is empty).
How can I resolve this? If you propose a fix, please make it concise. |
e89e22e to
108645a
Compare
|
@greptileai review |
108645a to
2e95d49
Compare
|
@greptileai review |
|
The test has been updated in the latest push — |
33d937a to
3cfb225
Compare
|
@greptileai review |
3cfb225 to
8de62f1
Compare
Problem
Gateway refuses to start with
bind=loopback+auth.mode=trusted-proxy, throwing:This blocks a valid deployment pattern: reverse proxy (cloudflared, nginx, Caddy) running on the same host, connecting to the gateway via loopback while adding authentication headers.
Users are forced to use
bind=lan, unnecessarily exposing the gateway port to the local network.Root Cause
Two hardcoded restrictions:
server-runtime-config.ts: throws on loopback + trusted-proxyconfigure.gateway.ts: silently overrides bind from loopback to lanWhy This Is Safe
The trusted-proxy auth mode validates identity via HTTP headers (not IP origin) and checks
req.socket.remoteAddressagainstgateway.trustedProxies. On loopback, the remote address is127.0.0.1— users configuretrustedProxies: ["127.0.0.1"]to allow it. The existingtrustedProxies.length === 0check is preserved, so misconfiguration is still caught.Fix
Remove the loopback restriction. Keep the trustedProxies-must-be-configured check.
Closes #20073
Greptile Summary
Removes two hardcoded restrictions that blocked
trusted-proxyauth whenbind=loopback: a hard error inserver-runtime-config.tsand a silentbindoverride to"lan"inconfigure.gateway.ts. This unblocks a valid deployment pattern where a reverse proxy (e.g. cloudflared, nginx, Caddy) runs on the same host and connects to the gateway via loopback while adding authentication headers.trustedProxiesto be non-empty is preserved, preventing misconfiguration.req.socket.remoteAddressis127.0.0.1, so users must configuretrustedProxies: ["127.0.0.1"]for the auth to work — this is validated at both config time and runtime.trustedProxies.Confidence Score: 5/5
Last reviewed commit: 3cfb225