diff --git a/apps/server/src/environment/DirectEndpoints.test.ts b/apps/server/src/environment/DirectEndpoints.test.ts index 09ecc1ee8c8c9..1338d25b15748 100644 --- a/apps/server/src/environment/DirectEndpoints.test.ts +++ b/apps/server/src/environment/DirectEndpoints.test.ts @@ -198,6 +198,24 @@ describe("resolveBoundEndpoints", () => { } }); + it("omits Windows hotspot adapters and 198.18.0.0/15 VPN tunnels from a wildcard bind", () => { + const interfaces = { + ...INTERFACES, + "Local Area Connection* 2": virtualInterface("192.168.137.1"), + "LAN-Verbindung* 10": virtualInterface("192.168.137.2"), + utun40: virtualInterface("198.19.2.2"), + }; + expect( + resolveBoundEndpoints({ platform: "win32", 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/" }, + ]); + expect( + resolveBoundEndpoints({ platform: "darwin", host: "198.19.2.2", port: 3773, interfaces }), + ).toEqual([{ kind: "lan", httpBaseUrl: "http://198.19.2.2:3773/" }]); + }); + it("tags only addresses on Tailscale's interface as tailnet, not other VPNs in its range", () => { const interfaces = { en0: INTERFACES.en0, diff --git a/apps/server/src/environment/DirectEndpoints.ts b/apps/server/src/environment/DirectEndpoints.ts index c39ca1d85484e..3457c578639f7 100644 --- a/apps/server/src/environment/DirectEndpoints.ts +++ b/apps/server/src/environment/DirectEndpoints.ts @@ -28,6 +28,7 @@ import { isLoopbackHost, isPrivateNetworkAddress, isVirtualInterface, + isVpnTunnelAddress, WINDOWS_HOST_ADAPTER_MAC, } from "../startupAccess.ts"; @@ -81,6 +82,7 @@ export function resolveBoundEndpoints(input: { !entry.internal && entry.family === "IPv4" && isAdvertisableAddress(entry.address) && + !isVpnTunnelAddress(entry.address) && !(input.platform === "win32" && WINDOWS_HOST_ADAPTER_MAC.test(entry.mac)), ) .map((entry) => entry.address) diff --git a/apps/server/src/startupAccess.test.ts b/apps/server/src/startupAccess.test.ts index c36c29e5f1278..c3953306cfd0d 100644 --- a/apps/server/src/startupAccess.test.ts +++ b/apps/server/src/startupAccess.test.ts @@ -71,6 +71,16 @@ it("prefers a LAN address over a tailnet one for a private-network pairing URL", ).toBe("http://192.168.1.42:3773"); }); +it("skips a VPN tunnel address for a private-network pairing URL", () => { + expect( + resolveHeadlessConnectionString("0.0.0.0", 3773, { + interfaces: { utun40: [ipv4("198.19.2.2")], en0: [ipv4("192.168.1.42")] }, + privateNetworkOnly: true, + platform: "darwin", + }), + ).toBe("http://192.168.1.42:3773"); +}); + it("skips Windows VirtualBox and VMware host-only adapters for a private-network listener", () => { expect( resolveHeadlessConnectionString("0.0.0.0", 3773, { diff --git a/apps/server/src/startupAccess.ts b/apps/server/src/startupAccess.ts index ce1b8be41938f..d0ed00b2cbec9 100644 --- a/apps/server/src/startupAccess.ts +++ b/apps/server/src/startupAccess.ts @@ -43,13 +43,12 @@ export const isLoopbackHost = (host: string | undefined): boolean => { }; /** - * Container and VM networks (Docker, libvirt, VMware, VirtualBox, Hyper-V, and - * macOS's `bridge100`+) have private addresses only this machine reaches. A - * host bridge such as `br0` or Proxmox's `vmbr0` carries the LAN address, so - * it stays listed. + * Container and VM networks, macOS's `bridge100`+, and Windows' hidden virtual + * adapters such as the hotspot's localized `Local Area Connection* 2` reach only + * this machine's guests or tethered devices. A host bridge such as `br0` carries the LAN. */ const VIRTUAL_INTERFACE = - /^(docker|br-|veth|virbr|vmnet|vboxnet|vEthernet|podman|cni|flannel|cali|lxcbr|lxdbr|bridge[1-9]\d\d)/; + /^(docker|br-|veth|virbr|vmnet|vboxnet|vEthernet|podman|cni|flannel|cali|lxcbr|lxdbr|bridge[1-9]\d\d)|\* \d+$/; // VirtualBox and VMware host-only adapters on Windows. Their names are mutable; Linux bridges can inherit these MACs. export const WINDOWS_HOST_ADAPTER_MAC = /^(0a:00:27|00:50:56:c0:00):/i; @@ -73,6 +72,9 @@ export const isPrivateNetworkAddress = (address: string): boolean => { return NodeNet.isIPv4(ipv4) && !ipv4.startsWith("169.254.") && isPrivateNetworkHost(ipv4); }; +/** VPN and proxy clients put their tunnels in 198.18.0.0/15 (RFC 2544), which is never a LAN. */ +export const isVpnTunnelAddress = (address: string): boolean => /^198\.1[89]\./.test(address); + /** * A private-network listener binds every interface but serves only * connections that stay on loopback, a LAN, or the tailnet. Both ends must be @@ -160,6 +162,7 @@ const resolveHeadlessConnectionHost = ( isIpv4Family(entry.family) && (!privateNetworkOnly || (isPrivateNetworkAddress(entry.address) && + !isVpnTunnelAddress(entry.address) && !(platform === "win32" && WINDOWS_HOST_ADAPTER_MAC.test(entry.mac)))), ); // A tailnet or other CGNAT address reaches fewer devices than the LAN one.