Skip to content

fix(gateway): trusted-proxy auth rejected when bind=loopback#20097

Merged
mbelinky merged 1 commit intoopenclaw:mainfrom
xinhuagu:fix/trusted-proxy-loopback
Feb 20, 2026
Merged

fix(gateway): trusted-proxy auth rejected when bind=loopback#20097
mbelinky merged 1 commit intoopenclaw:mainfrom
xinhuagu:fix/trusted-proxy-loopback

Conversation

@xinhuagu
Copy link
Contributor

@xinhuagu xinhuagu commented Feb 18, 2026

Problem

Gateway refuses to start with bind=loopback + auth.mode=trusted-proxy, throwing:

gateway auth mode=trusted-proxy makes no sense with bind=loopback

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:

  1. server-runtime-config.ts: throws on loopback + trusted-proxy
  2. configure.gateway.ts: silently overrides bind from loopback to lan

Why This Is Safe

The trusted-proxy auth mode validates identity via HTTP headers (not IP origin) and checks req.socket.remoteAddress against gateway.trustedProxies. On loopback, the remote address is 127.0.0.1 — users configure trustedProxies: ["127.0.0.1"] to allow it. The existing trustedProxies.length === 0 check 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-proxy auth when bind=loopback: a hard error in server-runtime-config.ts and a silent bind override to "lan" in configure.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.

  • The existing safety check requiring trustedProxies to be non-empty is preserved, preventing misconfiguration.
  • On loopback, req.socket.remoteAddress is 127.0.0.1, so users must configure trustedProxies: ["127.0.0.1"] for the auth to work — this is validated at both config time and runtime.
  • Tests are updated to reflect the new behavior and a new test case covers loopback + trusted-proxy with empty trustedProxies.

Confidence Score: 5/5

  • This PR is safe to merge — it removes an unnecessary restriction while preserving all security validations.
  • The change is minimal and well-scoped: two restriction blocks removed, safety checks (trustedProxies must be configured) preserved. The auth flow in auth.ts validates remoteAddress against trustedProxies at request time, so security is not degraded. Tests are comprehensive and cover both the happy path and misconfiguration case. No other code paths depend on the removed restrictions.
  • No files require special attention

Last reviewed commit: 3cfb225

@openclaw-barnacle openclaw-barnacle bot added gateway Gateway runtime commands Command implementations size: XS trusted-contributor labels Feb 18, 2026
Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 files reviewed, 2 comments

Edit Code Review Agent Settings | Greptile

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Feb 18, 2026

Additional Comments (1)

src/gateway/server-runtime-config.ts
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).

Prompt To Fix With AI
This 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.

@xinhuagu xinhuagu force-pushed the fix/trusted-proxy-loopback branch from e89e22e to 108645a Compare February 18, 2026 14:41
@xinhuagu
Copy link
Contributor Author

@greptileai review

@xinhuagu xinhuagu force-pushed the fix/trusted-proxy-loopback branch from 108645a to 2e95d49 Compare February 18, 2026 15:09
@xinhuagu
Copy link
Contributor Author

@greptileai review

@xinhuagu
Copy link
Contributor Author

The test has been updated in the latest push — should reject loopback binding with trusted-proxy auth mode is now should allow loopback binding with trusted-proxy auth mode (asserts success). Also added a new test should reject loopback trusted-proxy without trustedProxies configured to cover the empty-trustedProxies case. CI is green ✅

@xinhuagu xinhuagu force-pushed the fix/trusted-proxy-loopback branch from 33d937a to 3cfb225 Compare February 18, 2026 15:43
@xinhuagu
Copy link
Contributor Author

@greptileai review

@mbelinky mbelinky force-pushed the fix/trusted-proxy-loopback branch from 3cfb225 to 8de62f1 Compare February 20, 2026 17:51
@mbelinky mbelinky merged commit 9c52497 into openclaw:main Feb 20, 2026
10 checks passed
@mbelinky
Copy link
Contributor

Merged via squash.

Thanks @xinhuagu!

rodrigogs pushed a commit to rodrigogs/openclaw that referenced this pull request Feb 20, 2026
…w#20097)

Merged via /review-pr -> /prepare-pr -> /merge-pr.

Prepared head SHA: 8de62f1
Co-authored-by: xinhuagu <562450+xinhuagu@users.noreply.github.com>
Co-authored-by: mbelinky <132747814+mbelinky@users.noreply.github.com>
Reviewed-by: @mbelinky
Hansen1018 added a commit to Hansen1018/openclaw that referenced this pull request Feb 21, 2026
…w#20097)

Merged via /review-pr -> /prepare-pr -> /merge-pr.

Prepared head SHA: 8de62f1
Co-authored-by: xinhuagu <562450+xinhuagu@users.noreply.github.com>
Co-authored-by: mbelinky <132747814+mbelinky@users.noreply.github.com>
Reviewed-by: @mbelinky
vincentkoc pushed a commit that referenced this pull request Feb 21, 2026
Merged via /review-pr -> /prepare-pr -> /merge-pr.

Prepared head SHA: 8de62f1
Co-authored-by: xinhuagu <562450+xinhuagu@users.noreply.github.com>
Co-authored-by: mbelinky <132747814+mbelinky@users.noreply.github.com>
Reviewed-by: @mbelinky
dgarson pushed a commit to dgarson/clawdbot that referenced this pull request Feb 21, 2026
…w#20097)

Merged via /review-pr -> /prepare-pr -> /merge-pr.

Prepared head SHA: 8de62f1
Co-authored-by: xinhuagu <562450+xinhuagu@users.noreply.github.com>
Co-authored-by: mbelinky <132747814+mbelinky@users.noreply.github.com>
Reviewed-by: @mbelinky
mmyyfirstb pushed a commit to mmyyfirstb/openclaw that referenced this pull request Feb 21, 2026
…w#20097)

Merged via /review-pr -> /prepare-pr -> /merge-pr.

Prepared head SHA: 8de62f1
Co-authored-by: xinhuagu <562450+xinhuagu@users.noreply.github.com>
Co-authored-by: mbelinky <132747814+mbelinky@users.noreply.github.com>
Reviewed-by: @mbelinky
obviyus pushed a commit to guirguispierre/openclaw that referenced this pull request Feb 22, 2026
…w#20097)

Merged via /review-pr -> /prepare-pr -> /merge-pr.

Prepared head SHA: 8de62f1
Co-authored-by: xinhuagu <562450+xinhuagu@users.noreply.github.com>
Co-authored-by: mbelinky <132747814+mbelinky@users.noreply.github.com>
Reviewed-by: @mbelinky
mreedr pushed a commit to mreedr/openclaw-custom that referenced this pull request Feb 24, 2026
…w#20097)

Merged via /review-pr -> /prepare-pr -> /merge-pr.

Prepared head SHA: 8de62f1
Co-authored-by: xinhuagu <562450+xinhuagu@users.noreply.github.com>
Co-authored-by: mbelinky <132747814+mbelinky@users.noreply.github.com>
Reviewed-by: @mbelinky
zooqueen pushed a commit to hanzoai/bot that referenced this pull request Mar 6, 2026
…w#20097)

Merged via /review-pr -> /prepare-pr -> /merge-pr.

Prepared head SHA: 8de62f1
Co-authored-by: xinhuagu <562450+xinhuagu@users.noreply.github.com>
Co-authored-by: mbelinky <132747814+mbelinky@users.noreply.github.com>
Reviewed-by: @mbelinky
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

commands Command implementations gateway Gateway runtime size: XS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Security]: Bind loopback and auth.mode trusted-proxy not working together

2 participants