@devries-cameron20 / t3code Mirror · read-only / commits / b9bbfda087
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 12:15 UTC

fix(server): NixOS container and systemd-nspawn veths are no longer advertised as LAN routes (#32140)

Co-authored-by: repparw <repparw@users.noreply.github.com> Co-authored-by: Julius Marminge <julius0216@outlook.com>

Ulises Britos committed Nov 15, 2026 at 01:23 UTC b9bbfda08713b2f68403ffd98f28a5e45d317ed7
5 files changed +78 -10
apps/server/src/cli/pair.ts
+6 -2
@@ -161,10 +161,14 @@ export class ServePortOccupiedError extends Schema.TaggedError<ServePortOccupied
161 }
162 }
163
164 -const resolveDirectPairingBaseUrl = (state: PersistedServerRuntimeState): string =>
164 +const resolveDirectPairingBaseUrl = (
165 + state: PersistedServerRuntimeState,
166 + platform: NodeJS.Platform,
167 +): string =>
168 state.devUrl ??
169 resolveHeadlessConnectionString(state.host, state.port, {
170 privateNetworkOnly: state.privateNetworkOnly,
171 + platform,
172 });
173
174 export class DevServerNotProxiableError extends Schema.TaggedError<DevServerNotProxiableError>()(
@@ -562,7 +566,7 @@ export const pairCommand = Command.make("pair", {
566 pairingBaseUrl = resolved.baseUrl;
567 notes.push(...resolved.notes);
568 } else {
565 - pairingBaseUrl = resolveDirectPairingBaseUrl(target.state);
569 + pairingBaseUrl = resolveDirectPairingBaseUrl(target.state, yield* HostProcess.Platform);
570 if (isLoopbackHost(new URL(pairingBaseUrl).hostname)) {
571 notes.push(
572 "This URL is only reachable from this machine. To reach it from your other devices, run `t3 up`, or re-run with --tailscale.",
apps/server/src/environment/DirectEndpoints.test.ts
+30
@@ -137,6 +137,36 @@ describe("resolveBoundEndpoints", () => {
137 ]);
138 });
139
140 + it("skips NixOS container and systemd-nspawn veths, which only this machine reaches", () => {
141 + const interfaces = {
142 + ...INTERFACES,
143 + "ve-jellyfin": virtualInterface("192.168.53.193"),
144 + "ve-qbittorrent": virtualInterface("192.168.55.225"),
145 + "vb-jellyfin": virtualInterface("192.168.100.1"),
146 + "vz-machine": virtualInterface("192.168.101.1"),
147 + };
148 + expect(
149 + resolveBoundEndpoints({ platform: "linux", host: "0.0.0.0", port: 3773, interfaces }),
150 + ).toEqual([
151 + { kind: "lan", httpBaseUrl: "http://192.168.1.10:3773/" },
152 + { kind: "tailnet", httpBaseUrl: "http://100.101.102.103:3773/" },
153 + ]);
154 + });
155 +
156 + it("keeps a Windows alias matching a Linux container prefix eligible", () => {
157 + const interfaces = {
158 + ...INTERFACES,
159 + "ve-office": virtualInterface("192.168.1.30"),
160 + };
161 + expect(
162 + resolveBoundEndpoints({ platform: "win32", host: "0.0.0.0", port: 3773, interfaces }),
163 + ).toEqual([
164 + { kind: "lan", httpBaseUrl: "http://192.168.1.10:3773/" },
165 + { kind: "tailnet", httpBaseUrl: "http://100.101.102.103:3773/" },
166 + { kind: "lan", httpBaseUrl: "http://192.168.1.30:3773/" },
167 + ]);
168 + });
169 +
170 it("omits Windows host-only adapters without excluding guest NICs or explicit binds", () => {
171 const interfaces = {
172 ...INTERFACES,
apps/server/src/environment/DirectEndpoints.ts
+4 -2
@@ -24,7 +24,7 @@ import {
24
25 import * as ServerConfig from "../config.ts";
26 import * as ServerEnvironment from "./ServerEnvironment.ts";
27 -import { isLoopbackHost, isPrivateNetworkAddress, VIRTUAL_INTERFACE } from "../startupAccess.ts";
27 +import { isLoopbackHost, isPrivateNetworkAddress, isVirtualInterface } from "../startupAccess.ts";
28
29 type NetworkInterfacesMap = ReturnType<typeof NodeOS.networkInterfaces>;
30
@@ -70,7 +70,9 @@ export function resolveBoundEndpoints(input: {
70 );
71 const addresses = isWildcardHost(input.host)
72 ? Object.entries(input.interfaces)
73 - .flatMap(([name, entries]) => (VIRTUAL_INTERFACE.test(name) ? [] : (entries ?? [])))
73 + .flatMap(([name, entries]) =>
74 + isVirtualInterface(name, input.platform) ? [] : (entries ?? []),
75 + )
76 .filter(
77 (entry) =>
78 !entry.internal &&
apps/server/src/startupAccess.test.ts
+19 -2
@@ -21,6 +21,7 @@ const ipv4 = (address: string, internal = false): NodeOS.NetworkInterfaceInfo =>
21 it("resolves wildcard hosts to a concrete external interface when one is available", () => {
22 const connectionString = resolveHeadlessConnectionString("0.0.0.0", 3773, {
23 interfaces: { en0: [ipv4("192.168.1.42")], lo0: [ipv4("127.0.0.1", true)] },
24 + platform: "linux",
25 });
26
27 expect(connectionString).toBe("http://192.168.1.42:3773");
@@ -34,16 +35,21 @@ it("skips public and container addresses for a private-network listener", () =>
35 eth1: [ipv4("10.0.0.5")],
36 };
37
37 - expect(resolveHeadlessConnectionString("0.0.0.0", 3773, { interfaces })).toBe(
38 + expect(resolveHeadlessConnectionString("0.0.0.0", 3773, { interfaces, platform: "linux" })).toBe(
39 "http://203.0.113.7:3773",
40 );
41 expect(
41 - resolveHeadlessConnectionString("0.0.0.0", 3773, { interfaces, privateNetworkOnly: true }),
42 + resolveHeadlessConnectionString("0.0.0.0", 3773, {
43 + interfaces,
44 + privateNetworkOnly: true,
45 + platform: "linux",
46 + }),
47 ).toBe("http://10.0.0.5:3773");
48 expect(
49 resolveHeadlessConnectionString("0.0.0.0", 3773, {
50 interfaces: { eth0: [ipv4("203.0.113.7")] },
51 privateNetworkOnly: true,
52 + platform: "linux",
53 }),
54 ).toBe("http://localhost:3773");
55 });
@@ -53,10 +59,21 @@ it("prefers a LAN address over a tailnet one for a private-network pairing URL",
59 resolveHeadlessConnectionString("0.0.0.0", 3773, {
60 interfaces: { tailscale0: [ipv4("100.101.102.103")], en0: [ipv4("192.168.1.42")] },
61 privateNetworkOnly: true,
62 + platform: "linux",
63 }),
64 ).toBe("http://192.168.1.42:3773");
65 });
66
67 +it("skips NixOS container and systemd-nspawn veths for a private-network pairing URL", () => {
68 + expect(
69 + resolveHeadlessConnectionString("0.0.0.0", 3773, {
70 + interfaces: { "ve-jellyfin": [ipv4("192.168.53.193")], eth0: [ipv4("192.168.0.18")] },
71 + privateNetworkOnly: true,
72 + platform: "linux",
73 + }),
74 + ).toBe("http://192.168.0.18:3773");
75 +});
76 +
77 it("targets the bound interface when the listener binds a specific address", () => {
78 const hostFor = (ip: string) =>
79 loopbackUrlHostForAddress(NetAddress.inetAddressFromIpStringUnsafe(ip, 3773));
apps/server/src/startupAccess.ts
+19 -4
@@ -7,6 +7,7 @@ import {
7 isSharedAddressSpaceHost,
8 isWildcardHost,
9 } from "@t3tools/shared/hostClassification";
10 +import * as HostProcess from "@t3tools/shared/HostProcess";
11 import { QrCode } from "@t3tools/shared/qrCode";
12 import { buildPairingAppLink } from "@t3tools/shared/remote";
13 import * as Effect from "effect/Effect";
@@ -44,9 +45,19 @@ export const isLoopbackHost = (host: string | undefined): boolean => {
45 * host bridge such as `br0` or Proxmox's `vmbr0` carries the LAN address, so
46 * it stays listed.
47 */
47 -export const VIRTUAL_INTERFACE =
48 +const VIRTUAL_INTERFACE =
49 /^(docker|br-|veth|virbr|vmnet|vboxnet|vEthernet|podman|cni|flannel|cali|lxcbr|lxdbr|bridge[1-9]\d\d)/;
50
51 +/**
52 + * systemd-nspawn's `ve-*`/`vz-*` and NixOS containers' `vb-*` name host-side
53 + * veths after the machine. Windows aliases are user-renameable, so these
54 + * prefixes only apply to Linux interface discovery.
55 + */
56 +const LINUX_CONTAINER_INTERFACE = /^(ve-|vb-|vz-)/;
57 +
58 +export const isVirtualInterface = (name: string, platform: NodeJS.Platform): boolean =>
59 + VIRTUAL_INTERFACE.test(name) || (platform === "linux" && LINUX_CONTAINER_INTERFACE.test(name));
60 +
61 /**
62 * Loopback or private-range IPv4 (LAN, tailnet, CGNAT), not link-local, in
63 * plain or IPv4-mapped IPv6 form.
@@ -86,6 +97,7 @@ const resolveHeadlessConnectionHost = (
97 host: string | undefined,
98 interfaces: NetworkInterfacesMap,
99 privateNetworkOnly: boolean,
100 + platform: NodeJS.Platform,
101 ): string => {
102 if (!host) {
103 return "localhost";
@@ -96,7 +108,7 @@ const resolveHeadlessConnectionHost = (
108 }
109
110 const interfaceEntries = Object.entries(interfaces).flatMap(([name, entries]) =>
99 - privateNetworkOnly && VIRTUAL_INTERFACE.test(name) ? [] : (entries ?? []),
111 + privateNetworkOnly && isVirtualInterface(name, platform) ? [] : (entries ?? []),
112 );
113 const externalIpv4Entries = interfaceEntries.filter(
114 (entry) =>
@@ -128,12 +140,14 @@ export const resolveHeadlessConnectionString = (
140 options: {
141 readonly interfaces?: NetworkInterfacesMap;
142 readonly privateNetworkOnly?: boolean | undefined;
131 - } = {},
143 + readonly platform: NodeJS.Platform;
144 + },
145 ): string => {
146 const connectionHost = resolveHeadlessConnectionHost(
147 host,
148 options.interfaces ?? NodeOS.networkInterfaces(),
149 options.privateNetworkOnly === true,
150 + options.platform,
151 );
152 return `http://${formatHostForUrl(connectionHost)}:${port}`;
153 };
@@ -196,10 +210,11 @@ export const issueHeadlessServeAccessInfo = Effect.fn("issueHeadlessServeAccessI
210 const serverConfig = yield* ServerConfig.ServerConfig;
211 const httpServer = yield* HttpServer.HttpServer;
212 const serverAuth = yield* EnvironmentAuth.EnvironmentAuth;
213 + const platform = yield* HostProcess.Platform;
214 const connectionString = resolveHeadlessConnectionString(
215 serverConfig.host,
216 resolveListeningPort(httpServer.address, serverConfig.port),
202 - { privateNetworkOnly: serverConfig.privateNetworkOnly },
217 + { privateNetworkOnly: serverConfig.privateNetworkOnly, platform },
218 );
219 const issued = yield* serverAuth.issueStartupPairingCredential();
220