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 into
main fromrefs/pull/9066/headopened View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:M
- apps/desktop/src/backend/DesktopBackendConfiguration.ts line 643Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -639,3 +607,19 @@639607 : Option.getOrElse(distroIp, () => "127.0.0.1");640608 const httpBaseUrl = new URL(`http://${rendererHost}:${input.port}`);641609610+ // When the user opted into network access, bind to 0.0.0.0 inside WSL so the611+ // backend is reachable both via WSL2's automatic localhost forwarding612+ // (wslhost: Windows 127.0.0.1 -> WSL 127.0.0.1) AND via the distro's eth0 IP613+ // directly from Windows. wslhost forwarding is unreliable on some Windows614+ // hosts: the desktop's readiness probe and the renderer's saved-env-style615+ // fetch both saw "Failed to fetch" when the backend only bound to 127.0.0.1616+ // inside WSL. Binding to 0.0.0.0 plus advertising the WSL IP as the617+ // renderer-visible URL avoids that dependency.618+ // In local-only mode the Connections panel promises "limited to this619+ // machine", so the wildcard bind is not acceptable: it also answers on every620+ // other distro interface — including tailscale0 when Tailscale runs inside621+ // the distro — which exposed local-only backends to the whole tailnet.622+ // Instead, bind exactly the address the renderer is told to use: the distro623+ // IP in NAT mode (reachable from Windows without depending on flaky wslhost624+ // forwarding) or loopback in mirrored mode.625+ const wslBindHost = input.networkAccessible ? "0.0.0.0" : rendererHost;
github-actions[bot](GitHub profile, opens in a new tab) removed labelssize:M
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
- apps/desktop/src/backend/DesktopServerExposure.ts line 465OutdatedResolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -446,3 +451,15 @@446451 },447452 );448453454+ // The desktop protocol registers its proxy target once during bootstrap,455+ // before any backend run resolves its renderer-visible URL. The pool's456+ // onReady reports that resolved URL here so the protocol can follow it —457+ // a wsl-only primary reports the distro IP, which differs from the458+ // loopback URL the exposure advertises.459+ const resolvedBackendOriginRef = yield* Ref.make<Option.Option<URL>>(Option.none());460+ const backendProxyOrigin: Effect.Effect<URL> = Effect.gen(function* () {461+ const resolved = yield* Ref.get(resolvedBackendOriginRef);462+ return Option.isSome(resolved) ? resolved.value : (yield* Ref.get(stateRef)).httpBaseUrl;463+ });464+ const noteResolvedBackendOrigin = (origin: URL): Effect.Effect<void> =>465+ Ref.set(Option.some(origin), resolvedBackendOriginRef);
- apps/desktop/src/app/DesktopApp.ts lines 186 to 194OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -178,6 +178,17 @@178178 const rendererTarget = environment.isDevelopment179179 ? Option.getOrThrow(environment.devServerUrl)180180 : backendConfig.httpBaseUrl;181+ // Follow the backend's resolved renderer-visible URL once a run becomes182+ // ready: a wsl-only primary reports its distro IP, which the loopback183+ // target registered here cannot reach without the wildcard bind. Only184+ // local-only packaged runs need the live override; development loads from185+ // the dev server and network-accessible runs keep the loopback target.186+ const proxyOriginContext = yield* Effect.context<DesktopServerExposure.DesktopServerExposure>();187+ const runProxyOriginSync = Effect.runSyncWith(proxyOriginContext);181188 yield* electronProtocol.registerDesktopProtocol({182189 scheme: ElectronProtocol.getDesktopScheme(environment.isDevelopment),183190 targetOrigin: rendererTarget,191+ ...(environment.isDevelopment || serverExposureState.mode !== "local-only"192+ ? {}193+ : {194+ getTargetOrigin: (): URL => runProxyOriginSync(serverExposure.backendProxyOrigin),apps/desktop/src/backend/DesktopServerExposure.ts line 465OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -446,3 +451,15 @@446451 },447452 );448453454+ // The desktop protocol registers its proxy target once during bootstrap,455+ // before any backend run resolves its renderer-visible URL. The pool's456+ // onReady reports that resolved URL here so the protocol can follow it —457+ // a wsl-only primary reports the distro IP, which differs from the458+ // loopback URL the exposure advertises.459+ const resolvedBackendOriginRef = yield* Ref.make<Option.Option<URL>>(Option.none());460+ const backendProxyOrigin: Effect.Effect<URL> = Effect.gen(function* () {461+ const resolved = yield* Ref.get(resolvedBackendOriginRef);462+ return Option.isSome(resolved) ? resolved.value : (yield* Ref.get(stateRef)).httpBaseUrl;463+ });464+ const noteResolvedBackendOrigin = (origin: URL): Effect.Effect<void> =>465+ Ref.set(Option.some(origin), resolvedBackendOriginRef);
github-actions[bot](GitHub profile, opens in a new tab) removed labelssize:L
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:M
juliusmarminge added labelsmacroscope-review
- @@ -657,3 +625,19 @@657625 : Option.getOrElse(distroIp, () => "127.0.0.1");658626 const httpBaseUrl = new URL(`http://${rendererHost}:${input.port}`);659627628+ // When the user opted into network access, bind to 0.0.0.0 inside WSL so the629+ // backend is reachable both via WSL2's automatic localhost forwarding630+ // (wslhost: Windows 127.0.0.1 -> WSL 127.0.0.1) AND via the distro's eth0 IP631+ // directly from Windows. wslhost forwarding is unreliable on some Windows632+ // hosts: the desktop's readiness probe and the renderer's saved-env-style633+ // fetch both saw "Failed to fetch" when the backend only bound to 127.0.0.1634+ // inside WSL. Binding to 0.0.0.0 plus advertising the WSL IP as the635+ // renderer-visible URL avoids that dependency.636+ // In local-only mode the Connections panel promises "limited to this637+ // machine", so the wildcard bind is not acceptable: it also answers on every638+ // other distro interface — including tailscale0 when Tailscale runs inside639+ // the distro — which exposed local-only backends to the whole tailnet.640+ // Instead, bind exactly the address the renderer is told to use: the distro641+ // IP in NAT mode (reachable from Windows without depending on flaky wslhost642+ // forwarding) or loopback in mirrored mode.643+ const wslBindHost = input.networkAccessible ? "0.0.0.0" : rendererHost;
dlowzzxx(GitHub profile, opens in a new tab) closed this
Sign in to join this conversation.


cursor[bot](GitHub profile, opens in a new tab) reviewed