Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(desktop): honor local-only exposure in the WSL backend bind host #9066

Closeddlowzzxx(GitHub profile, opens in a new tab)wants to merge 1 commit intomain fromrefs/pull/9066/headopened View on GitHub

Fixes #9056.

Problem

With the WSL backend enabled, resolveWslStartConfig hardcoded a 0.0.0.0 bind regardless of the resolved DesktopServerExposure mode. With Network access off, the Connections panel states "Limited to this machine", but the WSL backend actually answers on every distro interface — including tailscale0 when Tailscale runs inside the distro, which exposes the backend to the entire tailnet with the toggle off (repro and curl evidence in the issue). The Windows primary already binds 127.0.0.1 in local-only mode via resolveDesktopServerExposure; only the WSL path diverged.

Change

  • Pass the primary's resolved exposure mode into resolveWslStartConfig as networkAccessible, read from DesktopServerExposure.getState at both call sites (the wsl-only primary and the resolveWsl secondary).
  • In network-accessible mode the behavior is unchanged (0.0.0.0, for the reasons documented in the original comment — readiness probe and renderer reachability without depending on wslhost forwarding).
  • In local-only mode, bind exactly the address the renderer is already told to use: the distro IP in NAT mode (reachable from Windows without depending on flaky wslhost forwarding, so the readiness-probe regression that motivated the wildcard bind does not come back) or loopback in mirrored mode. A wildcard bind is no longer possible while the UI claims "limited to this machine".

No UI changes, so no screenshots are attached.

Tests

  • resolveWsl wildcards the WSL bind only when network access is enabled — guards the unchanged 0.0.0.0 behavior in network-accessible mode.
  • resolveWsl binds the advertised distro IP when exposure is local-only — local-only + NAT binds the advertised host instead of the wildcard.
  • resolveWsl binds loopback in mirrored mode when exposure is local-only — mirrored mode keeps loopback.

Verification: focused suite apps/desktop/src/backend/DesktopBackendConfiguration.test.ts — 34 passed; tsgo --noEmit on @t3tools/desktop reports no errors in the touched files; oxfmt --check clean on both files.


Note

Medium Risk Changes WSL listen addresses and desktop protocol proxy targets, which affect reachability and local-only network exposure guarantees on Windows/WSL.

Overview Fixes local-only server exposure for WSL-backed desktops: the WSL backend no longer always binds 0.0.0.0, which could expose it on distro interfaces (e.g. Tailscale) while the UI still says “limited to this machine.”

WSL bind host now follows the primary’s exposure mode via networkAccessible from DesktopServerExposure.getState: network-accessible keeps 0.0.0.0; local-only binds the same address the renderer uses (distro IP in NAT, 127.0.0.1 in mirrored mode).

Because local-only WSL primaries advertise a non-loopback URL, the custom app:// protocol can follow the backend once it’s ready: DesktopServerExposure adds backendProxyOrigin / noteResolvedBackendOrigin, the backend pool records the resolved origin on onReady, packaged local-only bootstrap passes targetOriginOverride into ElectronProtocol, and the handler consults that override per request.

Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 749286ce90bd2a2027378f98d114986b1a07c0d3. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).

Note

Fix WSL backend bind host to honor local-only exposure mode

  • WSL backend now binds to 0.0.0.0 only when exposure mode is network-accessible; in local-only mode it binds to the distro IP (NAT) or loopback (mirrored), preventing unintended exposure on other interfaces. See DesktopBackendConfiguration.ts.
  • Adds backendProxyOrigin and noteResolvedBackendOrigin to DesktopServerExposure so the protocol proxy can follow a live backend-reported origin instead of a static loopback URL. See DesktopServerExposure.ts.
  • Extends proxyRequest in ElectronProtocol.ts with an optional getTargetOrigin callback; the protocol handler reads a dynamic target origin per request.
  • When a backend becomes ready, the backend pool calls noteResolvedBackendOrigin with the backend's httpBaseUrl before opening the main window. See DesktopBackendPool.ts.
  • Risk: resolveWsl now requires a networkAccessible flag; any caller not passing it will fail to compile. The DesktopServerExposure interface change requires all stubs to implement backendProxyOrigin and noteResolvedBackendOrigin.
📊 Macroscope summarized f8444a1. 1 file reviewed, 2 issues evaluated, 1 issue filtered, 1 comment posted

🗂️ Filtered Issues

apps/desktop/src/backend/DesktopBackendConfiguration.ts — 1 comment posted, 2 evaluated, 1 filtered
  • line 643: getDistroIp obtains its result from hostname -I, which returns a non-loopback distro address, so the isLocalHostIpv4 branch cannot detect mirrored WSL networking in production. Mirrored mode mirrors the Windows LAN interfaces into WSL; the selected address can therefore be a LAN address, and local-only mode binds the backend to it here. This exposes a backend that the UI labels local-only to the LAN instead of binding 127.0.0.1 for mirrored networking. [ Already posted ]

Summary by CodeRabbit

  • Bug Fixes
    • Improved WSL backend network binding to respect the selected server exposure mode.
    • Local-only connections now bind to the appropriate local or distro address instead of being exposed on all network interfaces.
    • Network-accessible connections continue to support wildcard binding.
    • Improved handling for mirrored-mode environments using loopback addresses.
    1. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched

    2. macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      Approvability

      Verdict: Not approved

      Macroscope's review found this PR not approvable — This production WSL change alters listening addresses for the default local-only mode, and an unresolved high-severity finding indicates that a LAN or Tailscale address may still be selected, leaving the backend externally reachable. The test addition is harness-only, but the runtime exposure and security impact warrant human review.

      Not approved because:

      • 1 blocking correctness issue found at or above your repo's Minimum Blocking Severity
      Adjust the Minimum Blocking Severity for this repo — including turning it Off — in [Settings](https://app.macroscope.com/pingdotgg/settings#Repos). You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    3. Pushed 8b4639934 addressing the review findings:

      • Protocol origin (Cursor, high): the desktop protocol's proxy target now follows the backend's resolved renderer-visible URL. DesktopServerExposure records the URL the pool reports on readiness (noteResolvedBackendOrigin / backendProxyOrigin), and the protocol consults it per request for local-only packaged runs. A wsl-only primary serving from its distro IP is therefore reachable on the app:// origin without depending on the wildcard bind; development and network-accessible runs keep today's exact target.
      • Readiness-probe behavior is unchanged — the probe already used the WSL config's advertised URL.

      New test: follows the live target override once the backend resolves its URL. Focused suites (protocol 7, backend configuration 34, pool, window, wsl backend) pass; tsgo --noEmit and oxfmt --check clean on touched files.

    4. Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

      Fix All in Cursor ❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the [Cursor dashboard](https://www.cursor.com/dashboard/bugbot). Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 8b46399341df0021639b9a5d794601902d78bf66. Configure [here](https://www.cursor.com/dashboard/bugbot).
    5. Pushed 749286ce9 addressing both findings:

      • Ref.set order (Cursor high, Macroscope): corrected to Ref.set(resolvedBackendOriginRef, Option.some(origin)) — the write now lands on the ref.
      • Runtime bridging (Macroscope): the registration input is now targetOriginOverride?: Effect.Effect<URL> and ElectronProtocol bridges it to a synchronous read itself via a context captured once in its layer — the escape lives at the Electron boundary, and DesktopApp just passes the effect for local-only packaged runs.

      Protocol suite 7/7 including the override test (now driving the override through a Ref-backed Effect), backend configuration 34/34, tsgo and oxfmt clean on touched files.

    6. Review Change StackReview Change Stack

      No actionable comments were generated in the recent review. 🎉

      ℹ️ Recent review info
      ⚙️ Run configuration

      Configuration used: Path: .coderabbit.yaml

      Review profile: CHILL

      Plan: Advanced

      Run ID: e5b3e267-446a-4391-be48-49c4fdb665a7

      📥 Commits

      Reviewing files that changed from the base of the PR and between f328db30da063a7bce9a9d038fc583d3ff83673a and f8444a1695d1a651cce0fd4e7733068786591cf8.

      📒 Files selected for processing (2)
      • apps/desktop/src/backend/DesktopBackendConfiguration.test.ts
      • apps/desktop/src/backend/DesktopBackendConfiguration.ts

      Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.


      📝 Walkthrough

      Walkthrough

      WSL startup now selects its bind host from the server exposure mode. Network-accessible mode uses 0.0.0.0; local-only mode uses the resolved renderer host. Tests cover distro and loopback addresses.

      Changes

      WSL bind host selection

      Layer / File(s)Summary
      Exposure mode plumbing
      apps/desktop/src/backend/DesktopBackendConfiguration.ts
      The configuration reads serverExposure.getState().mode, converts it to networkAccessible, and passes the value through both WSL configuration paths.
      Conditional WSL binding and validation
      apps/desktop/src/backend/DesktopBackendConfiguration.ts, apps/desktop/src/backend/DesktopBackendConfiguration.test.ts
      WSL uses 0.0.0.0 for network-accessible mode and the resolved renderer host for local-only mode. Tests validate distro and loopback hosts, including the generated httpBaseUrl.

      Priority: ➖ Normal

      Estimated code review effort: 3 (Moderate) | ~20 minutes

      Change: Bug fix · Severity of issue fixed: Medium

      Suggested reviewers: juliusmarminge

      Merge Risk: ⚪ Minimal · up to f8444

      The updated binding behavior has no confirmed merge-blocking issue in the available evidence.

      🚥 Pre-merge checks | ✅ 4 | ❌ 1

      ❌ Failed checks (1 warning)

      Check nameStatusExplanationResolution
      Docstring Coverage⚠️ WarningDocstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 2 files.Write docstrings for the functions missing them to satisfy the coverage threshold.
      ✅ Passed checks (4 passed)
      Check nameStatusExplanation
      Title check✅ PassedThe title clearly and concisely describes the main change: making the WSL backend honor local-only exposure when selecting its bind host.
      Description check✅ PassedThe description explains the problem, the implementation, the security impact, and the test verification. It does not use the template headings exactly and omits the checklist, but it contains the req…
      Linked Issues check✅ PassedIssue #9056 requires the WSL backend bind to match the selected exposure mode. The change derives networkAccessible from DesktopServerExposure.getState. Network-accessible mode binds 0.0.0.0. Lo…
      Out of Scope Changes check✅ PassedThe protocol proxy changes remain connected to issue #9056. A local-only packaged WSL backend can use a distro IP in NAT mode, so the proxy must follow the backend's resolved origin. Recording that or…
      • Fix all pre-merge checks with AI
      ✨ Finishing Touches
      🧪 Generate unit tests (beta)
      • Create PR with unit tests

      Comment `@coderabbitai help` to get the list of available commands.
    7. juliusmarminge added labelsmacroscope-review

    8. @@ -657,3 +625,19 @@
      657625 : Option.getOrElse(distroIp, () => "127.0.0.1");
      658626 const httpBaseUrl = new URL(`http://${rendererHost}:${input.port}`);
      659627
      628+ // When the user opted into network access, bind to 0.0.0.0 inside WSL so the
      629+ // backend is reachable both via WSL2's automatic localhost forwarding
      630+ // (wslhost: Windows 127.0.0.1 -> WSL 127.0.0.1) AND via the distro's eth0 IP
      631+ // directly from Windows. wslhost forwarding is unreliable on some Windows
      632+ // hosts: the desktop's readiness probe and the renderer's saved-env-style
      633+ // fetch both saw "Failed to fetch" when the backend only bound to 127.0.0.1
      634+ // inside WSL. Binding to 0.0.0.0 plus advertising the WSL IP as the
      635+ // renderer-visible URL avoids that dependency.
      636+ // In local-only mode the Connections panel promises "limited to this
      637+ // machine", so the wildcard bind is not acceptable: it also answers on every
      638+ // other distro interface — including tailscale0 when Tailscale runs inside
      639+ // the distro — which exposed local-only backends to the whole tailnet.
      640+ // Instead, bind exactly the address the renderer is told to use: the distro
      641+ // IP in NAT mode (reachable from Windows without depending on flaky wslhost
      642+ // forwarding) or loopback in mirrored mode.
      643+ const wslBindHost = input.networkAccessible ? "0.0.0.0" : rendererHost;
      macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      🟠 High backend/DesktopBackendConfiguration.ts:643

      Local-only WSL backends bind to an externally reachable address when getDistroIp returns a Tailscale or other non-WSL interface first, so the backend is reachable beyond the local machine. Because wslBindHost uses rendererHost directly, select the WSL vEthernet/eth0 address or reject non-WSL private addresses before using it here.

      🤖 Copy this AI Prompt to have your agent fix this:
      In file @apps/desktop/src/backend/DesktopBackendConfiguration.ts around line 643:
      
      Local-only WSL backends bind to an externally reachable address when `getDistroIp` returns a Tailscale or other non-WSL interface first, so the backend is reachable beyond the local machine. Because `wslBindHost` uses `rendererHost` directly, select the WSL vEthernet/`eth0` address or reject non-WSL private addresses before using it here.

Sign in to join this conversation.