Skip to content

rc-gateway: loopback-only second front for a same-host browser - #63

Merged
InfiniteInsight merged 1 commit into
mainfrom
rc-gateway/88-loopback-front
Oct 19, 2026
Merged

InfiniteInsight merged 1 commit into
mainfrom
rc-gateway/88-loopback-front

Conversation

@InfiniteInsight

Copy link
Copy Markdown
Owner

Closes InfiniteInsight/Qwen-Code-Remote#88

What

A second, loopback-only TLS front on the same port, behind --loopback-bind <host>
/ QWEN_RC_LOOPBACK_BIND. The public bind is untouched.

Why

Two tailscale nodes on one physical machine have no route between them. The
gateway binds the WSL tailnet address, so the browser on that same machine's
Windows side cannot reach it on either URL form, while the phone (a real third
peer) reaches both. Measured: TCP to the tailnet IP from Windows is
TcpTestSucceeded False with ping TimedOut, while Windows to WSL loopback is
TcpTestSucceeded True and a WSL listener printed GOT CONNECTION.

Why not --host 0.0.0.0

That also exposes the gateway on the LAN interface (192.168.0.158 here). Declined
by the operator. This change adds no network-reachable surface: a non-loopback
value is refused as a BindSecurityError before any side effect, and again inside
createHttp2Front.

Behaviour details

  • The extra socket binds first, so the listening callback reports a settled state.
  • A collision on it logs and leaves the public bind serving; it cannot take the
    gateway down.
  • Skipped when the primary already is that address, so a loopback gateway does not
    print a false failure every boot.

Security note, in the code and in a test

Reaching a front is what earns the peer attestation, so a local process gains the
ability to carry a peer address. It already had that: connecting to the gateway's
own bind address from this host is an ordinary local connect. forwardableHeaders
rewrites rather than copies the peer fields, so the address a client is given is
the one its own socket has. A case pre-seeds the peer header over the loopback path
to pin it.

Verification

  • src/tls/http2Front.loopback.test.ts, 4 cases, all pass.
  • Guard mutation-proved: neutering the isLoopbackHost check fails exactly
    refuses a second bind that is not loopback (1 failed | 3 passed), then restored.
  • tsc --noEmit clean.
  • Package suite: 2863 passed, 2 skipped; 231 files passed, 1 skipped.

…net address

Two tailscale nodes on one physical machine have no route between them, so a
gateway bound to the WSL tailnet address cannot be reached by the browser
running on that same machine's Windows side. Measured: TCP to the tailnet IP
fails from Windows while Windows to WSL loopback succeeds, which is why the
phone works and the laptop does not on either URL form.

Adds a second, loopback-only TLS front on the same port behind
--loopback-bind, so the public bind stays exactly as it is. A non-loopback
value is refused twice: as a BindSecurityError before any side effect, and
again inside the front. Widening the single bind to 0.0.0.0 was the alternative
and is deliberately not taken, since that also exposes the gateway on the LAN
interface.

The extra socket is bound before the public one so the listening callback
reports a settled state, and a collision on it logs without taking the public
bind down. It is skipped when the primary already is that address, so a
loopback gateway does not print a false failure every boot.

Closes InfiniteInsight/Qwen-Code-Remote#88
@InfiniteInsight
InfiniteInsight merged commit 5c53627 into main Oct 19, 2026
@InfiniteInsight
InfiniteInsight deleted the rc-gateway/88-loopback-front branch October 19, 2026 18:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant