Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions apps/server/src/environment/DirectEndpoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,12 @@ import {

import * as ServerConfig from "../config.ts";
import * as ServerEnvironment from "./ServerEnvironment.ts";
import { isLoopbackHost, isPrivateNetworkAddress, isVirtualInterface } from "../startupAccess.ts";
import {
isLoopbackHost,
isPrivateNetworkAddress,
isVirtualInterface,
WINDOWS_HOST_ADAPTER_MAC,
} from "../startupAccess.ts";

type NetworkInterfacesMap = ReturnType<typeof NodeOS.networkInterfaces>;

Expand Down Expand Up @@ -52,9 +57,6 @@ 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;
Expand Down
14 changes: 14 additions & 0 deletions apps/server/src/startupAccess.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,20 @@ it("prefers a LAN address over a tailnet one for a private-network pairing URL",
).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, {
interfaces: {
"VirtualBox Host-Only Network": [{ ...ipv4("192.168.56.1"), mac: "0a:00:27:00:00:0a" }],
"VMware Network Adapter VMnet8": [{ ...ipv4("192.168.159.1"), mac: "00:50:56:c0:00:08" }],
"Wi-Fi": [{ ...ipv4("192.168.1.20"), mac: "3c:22:fb:12:34:56" }],
},
privateNetworkOnly: true,
platform: "win32",
}),
).toBe("http://192.168.1.20:3773");
});

it("skips NixOS container and systemd-nspawn veths for a private-network pairing URL", () => {
expect(
resolveHeadlessConnectionString("0.0.0.0", 3773, {
Expand Down
7 changes: 6 additions & 1 deletion apps/server/src/startupAccess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ export const isLoopbackHost = (host: string | undefined): boolean => {
const VIRTUAL_INTERFACE =
/^(docker|br-|veth|virbr|vmnet|vboxnet|vEthernet|podman|cni|flannel|cali|lxcbr|lxdbr|bridge[1-9]\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;

/**
* systemd-nspawn's `ve-*`/`vz-*` and NixOS containers' `vb-*` name host-side
* veths after the machine. Windows aliases are user-renameable, so these
Expand Down Expand Up @@ -155,7 +158,9 @@ const resolveHeadlessConnectionHost = (
(entry) =>
!entry.internal &&
isIpv4Family(entry.family) &&
(!privateNetworkOnly || isPrivateNetworkAddress(entry.address)),
(!privateNetworkOnly ||
(isPrivateNetworkAddress(entry.address) &&
!(platform === "win32" && WINDOWS_HOST_ADAPTER_MAC.test(entry.mac)))),
);
// A tailnet or other CGNAT address reaches fewer devices than the LAN one.
const externalIpv4 = privateNetworkOnly
Expand Down
Loading