Skip to content

fix(gateway): use loopback for self-connections regardless of bind mode#22056

Open
usedhonda wants to merge 2 commits intoopenclaw:mainfrom
usedhonda:fix/bind-lan-self-connection-loopback
Open

fix(gateway): use loopback for self-connections regardless of bind mode#22056
usedhonda wants to merge 2 commits intoopenclaw:mainfrom
usedhonda:fix/bind-lan-self-connection-loopback

Conversation

@usedhonda
Copy link

@usedhonda usedhonda commented Feb 20, 2026

Problem

Closes #22047

bind: "lan" causes the browser tool (and any Gateway self-connection) to fail with a SECURITY ERROR after the plaintext ws:// block introduced in #20803.

Two commits are in conflict:

Result: agents running on the same host as the Gateway hit SECURITY ERROR: Gateway URL "ws://192.168.x.x" uses plaintext ws:// to a non-loopback address.

Fix

localUrl in buildGatewayConnectionDetails() always uses ws(s)://127.0.0.1:<port> regardless of bind mode.

bind controls which interface the server listens on — it should not affect the connection URL for agents on the same host. LAN/tailnet IPs are still available in lanIPv4 / tailnetIPv4 for display purposes (QR codes, urlSource labels, onboarding hints).

Changes

  • src/gateway/call.ts: localUrl simplified to ws(s)://127.0.0.1:${localPort}
  • src/gateway/call.test.ts: updated test names and assertions to reflect new behavior

Tests

✓ src/gateway/call.test.ts (29 tests) 167ms

All 29 tests passing.

Greptile Summary

Fixes a regression where bind: "lan" caused browser tools and Gateway self-connections to fail with SECURITY ERROR due to a conflict between two previous commits. The fix ensures agents on the same host always connect via 127.0.0.1 regardless of bind mode, since bind controls which interface the server listens on, not the connection URL for local agents. LAN/tailnet IPs remain available for display purposes (QR codes, onboarding hints).

  • Modified buildGatewayConnectionDetails() in src/gateway/call.ts to always use ws(s)://127.0.0.1 for localUrl, removing the conditional logic that previously used LAN/tailnet IPs based on bind mode
  • Updated all related tests in src/gateway/call.test.ts to reflect the new behavior, converting tests that expected SECURITY ERROR exceptions into tests that verify loopback connections succeed
  • All 29 tests passing, confirming the fix resolves the security error while maintaining proper functionality

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • The fix correctly resolves a clear regression caused by conflicting commits. The change is well-contained, maintains backward compatibility for all use cases, and actually improves security by ensuring local agents always use loopback addresses. All 29 tests pass, including updated tests that specifically verify the new behavior works correctly for all bind modes (loopback, lan, tailnet) with and without TLS. The implementation is simple, well-commented, and aligns with the security principle that ws:// to non-loopback addresses should be blocked.
  • No files require special attention

Last reviewed commit: e97ebcf

(2/5) Greptile learns from your feedback when you react with thumbs up/down!

When bind=lan or bind=tailnet, buildGatewayConnectionDetails() was
generating localUrl with the LAN/tailnet IP (e.g. ws://192.168.x.x).
The security check added in openclaw#20803 then rejected these as plaintext
ws:// to non-loopback addresses.

Root cause: bind mode controls which interface the *server* listens on,
but was incorrectly also driving the *client* connection URL for agents
running on the same host.

Fix: localUrl now always uses ws://127.0.0.1 (loopback). LAN and
tailnet IPs remain available in lanIPv4/tailnetIPv4 for display
purposes (QR codes, onboarding hints, urlSource labels) but are no
longer used as the actual connection target.

Fixes openclaw#22047
@openclaw-barnacle openclaw-barnacle bot added gateway Gateway runtime size: XS labels Feb 20, 2026
@kesor
Copy link
Contributor

kesor commented Feb 20, 2026

Related: #20289 (comment)

@HenryLoenwind
Copy link
Contributor

The real fix would be to fix the anti-ws code to properly check if the address is that of a local interface, not do simple pattern matching for 3 known things, of which one isn't even nailed down to be local. See my comment on #20803.

@openclaw-barnacle
Copy link

This pull request has been automatically marked as stale due to inactivity.
Please add updates or it will be closed.

@openclaw-barnacle openclaw-barnacle bot added the stale Marked as stale due to inactivity label Feb 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gateway Gateway runtime size: S stale Marked as stale due to inactivity

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Regression: bind=lan breaks browser tool self-connection due to #20803 security check

3 participants