Skip to content
TypeScript

fix(server): omit Windows host-only adapters from LAN routes (#25217)

maria15b58ffd31e7
diff --git a/apps/server/src/environment/DirectEndpoints.test.ts b/apps/server/src/environment/DirectEndpoints.test.ts
index 08b16959e86..f4ab607fe0a 100644
--- a/apps/server/src/environment/DirectEndpoints.test.ts
+++ b/apps/server/src/environment/DirectEndpoints.test.ts
@@ -86,12 +86,12 @@ const vpnInterface = (address: string) => [
},
];
-const virtualInterface = (address: string) => [
+const virtualInterface = (address: string, mac = "02:42:ac:11:00:01") => [
{
address,
netmask: "255.255.0.0",
family: "IPv4" as const,
- mac: "02:42:ac:11:00:01",
+ mac,
internal: false,
cidr: `${address}/16`,
},
@@ -99,7 +99,14 @@ const virtualInterface = (address: string) => [
describe("resolveBoundEndpoints", () => {
it("lists every external IPv4 address for a wildcard bind, tagging the tailnet one", () => {
- expect(resolveBoundEndpoints({ host: "0.0.0.0", port: 3773, interfaces: INTERFACES })).toEqual([
+ expect(
+ resolveBoundEndpoints({
+ platform: "linux",
+ host: "0.0.0.0",
+ port: 3773,
+ interfaces: INTERFACES,
+ }),
+ ).toEqual([
{ kind: "lan", httpBaseUrl: "http://192.168.1.10:3773/" },
{ kind: "tailnet", httpBaseUrl: "http://100.101.102.103:3773/" },
]);
@@ -115,13 +122,46 @@ describe("resolveBoundEndpoints", () => {
bridge100: virtualInterface("192.168.64.1"),
vmbr0: virtualInterface("192.168.1.20"),
};
- expect(resolveBoundEndpoints({ host: "0.0.0.0", port: 3773, interfaces })).toEqual([
+ expect(
+ resolveBoundEndpoints({ platform: "linux", host: "0.0.0.0", port: 3773, interfaces }),
+ ).toEqual([
{ kind: "lan", httpBaseUrl: "http://192.168.1.10:3773/" },
{ kind: "tailnet", httpBaseUrl: "http://100.101.102.103:3773/" },
{ kind: "lan", httpBaseUrl: "http://192.168.1.20:3773/" },
]);
});
+ it("omits Windows host-only adapters without excluding guest NICs or explicit binds", () => {
+ const interfaces = {
+ ...INTERFACES,
+ "VirtualBox-Host-Only-Netzwerk": virtualInterface("192.168.56.1", "0A:00:27:00:01:01"),
+ "Ethernet 2": virtualInterface("192.168.150.1", "00:50:56:c0:00:01"),
+ "Renamed network": virtualInterface("192.168.151.1", "00:50:56:c0:00:08"),
+ guest1: virtualInterface("192.168.1.30", "08:00:27:5e:1a:22"),
+ guest2: virtualInterface("192.168.1.31", "00:50:56:2b:8c:01"),
+ guest3: virtualInterface("192.168.1.32", "00:0c:29:4f:8e:35"),
+ guest4: virtualInterface("192.168.1.33", "00:50:56:80:8c:01"),
+ };
+ const input = { host: "0.0.0.0", port: 3773, interfaces };
+ const retained = [
+ { kind: "lan", httpBaseUrl: "http://192.168.1.10:3773/" },
+ { kind: "tailnet", httpBaseUrl: "http://100.101.102.103:3773/" },
+ ...[30, 31, 32, 33].map((last) => ({
+ kind: "lan",
+ httpBaseUrl: `http://192.168.1.${last}:3773/`,
+ })),
+ ];
+ expect(resolveBoundEndpoints({ ...input, platform: "win32" })).toEqual(retained);
+ for (const platform of ["linux", "darwin"] as const) {
+ expect(resolveBoundEndpoints({ ...input, platform })).toHaveLength(retained.length + 3);
+ }
+ for (const host of ["192.168.56.1", "192.168.150.1", "192.168.151.1"]) {
+ expect(resolveBoundEndpoints({ ...input, platform: "win32", host })).toEqual([
+ { kind: "lan", httpBaseUrl: `http://${host}:3773/` },
+ ]);
+ }
+ });
+
it("tags only addresses on Tailscale's interface as tailnet, not other VPNs in its range", () => {
const interfaces = {
en0: INTERFACES.en0,
@@ -129,7 +169,9 @@ describe("resolveBoundEndpoints", () => {
CloudflareWARP: vpnInterface("100.96.0.1"),
utun7: vpnInterface("100.85.0.1"),
};
- expect(resolveBoundEndpoints({ host: "0.0.0.0", port: 3773, interfaces })).toEqual([
+ expect(
+ resolveBoundEndpoints({ platform: "linux", host: "0.0.0.0", port: 3773, interfaces }),
+ ).toEqual([
{ kind: "lan", httpBaseUrl: "http://192.168.1.10:3773/" },
{ kind: "tailnet", httpBaseUrl: "http://100.70.1.2:3773/" },
{ kind: "lan", httpBaseUrl: "http://100.96.0.1:3773/" },
@@ -139,19 +181,27 @@ describe("resolveBoundEndpoints", () => {
it("never reports a host name, which can resolve to another machine per client", () => {
for (const host of ["server.local", "devbox", "devbox.home.arpa"]) {
- expect(resolveBoundEndpoints({ host, port: 3773, interfaces: INTERFACES })).toEqual([]);
+ expect(
+ resolveBoundEndpoints({ platform: "linux", host, port: 3773, interfaces: INTERFACES }),
+ ).toEqual([]);
}
});
it("never reports a public address, which would carry the credential over plain HTTP", () => {
expect(
- resolveBoundEndpoints({ host: "203.0.113.20", port: 3773, interfaces: INTERFACES }),
+ resolveBoundEndpoints({
+ platform: "linux",
+ host: "203.0.113.20",
+ port: 3773,
+ interfaces: INTERFACES,
+ }),
).toEqual([]);
});
it("reports only the tailnet address on a cloud VM, whose private network no client shares", () => {
expect(
resolveBoundEndpoints({
+ platform: "linux",
host: "0.0.0.0",
port: 3773,
interfaces: INTERFACES,
@@ -162,7 +212,12 @@ describe("resolveBoundEndpoints", () => {
it("never reports an IPv4-mapped host, which can name the client's own loopback", () => {
expect(
- resolveBoundEndpoints({ host: "::ffff:127.0.0.1", port: 3773, interfaces: INTERFACES }),
+ resolveBoundEndpoints({
+ platform: "linux",
+ host: "::ffff:127.0.0.1",
+ port: 3773,
+ interfaces: INTERFACES,
+ }),
).toEqual([]);
});
});
diff --git a/apps/server/src/environment/DirectEndpoints.ts b/apps/server/src/environment/DirectEndpoints.ts
index 99e33b98f97..dc8b843d98a 100644
--- a/apps/server/src/environment/DirectEndpoints.ts
+++ b/apps/server/src/environment/DirectEndpoints.ts
@@ -14,6 +14,7 @@ import * as ChildProcessSpawner from "effect/process/ChildProcessSpawner";
import * as NodeNet from "node:net";
import * as NodeOS from "node:os";
+import * as HostProcess from "@t3tools/shared/HostProcess";
import { isTailnetHost } from "@t3tools/shared/hostClassification";
import * as ServerConfig from "../config.ts";
@@ -49,7 +50,11 @@ const isTailscaleInterface = (
/^tailscale/i.test(name) ||
entries.some((entry) => entry.family === "IPv6" && isTailnetHost(entry.address));
+// Windows adapter names are mutable; Linux bridges can inherit these MACs.
+const WINDOWS_HOST_ADAPTER_MAC = /^(0a:00:27|00:50:56:c0:00):/i;
+
export function resolveBoundEndpoints(input: {
+ readonly platform: NodeJS.Platform;
readonly host: string | undefined;
readonly port: number;
readonly interfaces: NetworkInterfacesMap;
@@ -67,7 +72,10 @@ export function resolveBoundEndpoints(input: {
.flatMap(([name, entries]) => (VIRTUAL_INTERFACE.test(name) ? [] : (entries ?? [])))
.filter(
(entry) =>
- !entry.internal && entry.family === "IPv4" && isAdvertisableAddress(entry.address),
+ !entry.internal &&
+ entry.family === "IPv4" &&
+ isAdvertisableAddress(entry.address) &&
+ !(input.platform === "win32" && WINDOWS_HOST_ADAPTER_MAC.test(entry.mac)),
)
.map((entry) => entry.address)
: [input.host!].filter(isAdvertisableAddress);
@@ -111,6 +119,7 @@ export const make = Effect.gen(function* () {
const config = yield* ServerConfig.ServerConfig;
const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
const httpClient = yield* HttpClient.HttpClient;
+ const platform = yield* HostProcess.Platform;
// Only the service default listens on every interface without being asked,
// so only it checks once whether it runs in a cloud. The check starts now so
// the first client does not wait for its timeout.
@@ -122,6 +131,7 @@ export const make = Effect.gen(function* () {
const resolve = Effect.gen(function* () {
const endpoints = [
...resolveBoundEndpoints({
+ platform,
host: config.host,
port: config.port,
interfaces: NodeOS.networkInterfaces(),