Repository navigation
fix(sync): stop advertising hotspot and tunnel addresses as LAN #2461
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -249,7 +249,19 @@ function isTailscaleAddress(ipAddress: string): boolean { | |
| // this computer, so a phone that dials them just burns a connect attempt. | ||
| // Other `vEthernet (...)` adapters stay: with a Hyper-V External switch, or WSL | ||
| // in bridged mode, Windows moves the real LAN address onto one of them. | ||
| const VIRTUAL_ADAPTER_PATTERN = /^vEthernet \((WSL|Default Switch)|docker|^br-|virbr|vmnet|vboxnet/i; | ||
| // Windows names its hotspot and Wi-Fi Direct adapters "<localized name>* <n>" | ||
| // ("Local Area Connection* 2", "LAN-Verbindung* 10"); they carry the ICS | ||
| // gateway 192.168.137.1 and reach only this machine's tethered devices. | ||
| const VIRTUAL_ADAPTER_PATTERN = /^vEthernet \((WSL|Default Switch)|docker|^br-|virbr|vmnet|vboxnet|^virtualbox host-only|\* \d+$/i; | ||
|
|
||
| // VirtualBox (0a:00:27) and VMware (00:50:56:c0:00) host-only adapters use | ||
| // fixed MAC prefixes. Their Windows names are user-renameable ("VirtualBox | ||
| // Host-Only Network" is not matched above), so the MAC is the backstop. Linux | ||
| // bridges can inherit these MACs, so only Windows is checked. | ||
| const WINDOWS_HOST_ADAPTER_MAC = /^(0a:00:27|00:50:56:c0:00):/i; | ||
|
|
||
| /** VPN and proxy clients put their tunnels in 198.18.0.0/15 (RFC 2544), which is never a LAN. */ | ||
| const isVpnTunnelAddress = (address: string): boolean => /^198\.1[89]\./.test(address); | ||
|
|
||
| function readLocalNetworkMetadata(): LocalNetworkMetadata { | ||
| const interfaces = readNetworkInterfaces(); | ||
|
|
@@ -260,6 +272,8 @@ function readLocalNetworkMetadata(): LocalNetworkMetadata { | |
| const isLikelyTailscaleInterface = /tailscale|utun|tun/i.test(interfaceName); | ||
| for (const entry of entries ?? []) { | ||
| if (!entry || entry.internal || entry.family !== "IPv4") continue; | ||
| if (isVpnTunnelAddress(entry.address)) continue; | ||
| if (process.platform === "win32" && WINDOWS_HOST_ADAPTER_MAC.test(entry.mac)) continue; | ||
|
Comment on lines
+275
to
+276
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 Filtered addresses survive sync upgrades After an upgrade, Learn moreThe interface scan now rejects addresses that earlier versions saved in the local device row. ensureLocalDevice restores the stored LAN list when the scan returns an empty list and restores the stored tailnet IP when the scan returns null. touchLocalDevice repeats those fallbacks, and upsertDeviceRecord treats an explicit null tailnet IP as an omitted value. publishLanDiscovery and buildPairingConnectInfo use the resulting device row, so another refresh does not remove the rejected address. Example: A host on Wi-Fi has an Recommended fix: Make a successful local interface scan authoritative for the local row's LAN and tailnet fields, including an empty LAN list or explicit null tailnet IP. Preserve the existing merge behavior for peer updates that omit network fields. Extend the registry test to seed an old address and verify that refreshing the local row removes it from the pairing candidates. Was this helpful? React with 👍 or 👎 to provide feedback. |
||
| if (isLikelyTailscaleInterface || isTailscaleAddress(entry.address)) { | ||
| tailscale.push(entry.address); | ||
| } else { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,22 +23,37 @@ function makeProjectRoot(prefix: string): string { | |
| } | ||
|
|
||
| describe("deviceRegistryService", () => { | ||
| it("advertises real Hyper-V LAN adapters and filters host-only virtual networks", () => { | ||
| it("advertises real LAN adapters and filters host-only, hotspot and VPN addresses", () => { | ||
| // The MAC backstop is Windows-only, so pin the platform for every host. | ||
| const platform = Object.getOwnPropertyDescriptor(process, "platform"); | ||
| Object.defineProperty(process, "platform", { value: "win32", configurable: true }); | ||
| const networkInterfaces = vi.spyOn(os, "networkInterfaces").mockReturnValue({ | ||
| "vEthernet (WSL)": [{ address: "172.25.0.1", family: "IPv4", internal: false, netmask: "255.255.0.0", mac: "00:00:00:00:00:01", cidr: "172.25.0.1/16" }], | ||
| "vEthernet (Default Switch)": [{ address: "172.26.0.1", family: "IPv4", internal: false, netmask: "255.255.0.0", mac: "00:00:00:00:00:02", cidr: "172.26.0.1/16" }], | ||
| docker0: [{ address: "172.17.0.1", family: "IPv4", internal: false, netmask: "255.255.0.0", mac: "00:00:00:00:00:03", cidr: "172.17.0.1/16" }], | ||
| // Windows hotspot / Wi-Fi Direct adapters: ICS gateway, reach tethered devices only. | ||
| "Local Area Connection* 2": [{ address: "192.168.137.1", family: "IPv4", internal: false, netmask: "255.255.255.0", mac: "00:00:00:00:00:07", cidr: "192.168.137.1/24" }], | ||
| "LAN-Verbindung* 10": [{ address: "192.168.137.2", family: "IPv4", internal: false, netmask: "255.255.255.0", mac: "00:00:00:00:00:08", cidr: "192.168.137.2/24" }], | ||
| // RFC 2544 tunnels (Tailscale userspace, Clash/Mihomo Wintun) are never a LAN. | ||
| utun40: [{ address: "198.19.2.2", family: "IPv4", internal: false, netmask: "255.255.0.0", mac: "00:00:00:00:00:09", cidr: "198.19.2.2/16" }], | ||
| "VirtualBox Host-Only Network": [{ address: "192.168.56.1", family: "IPv4", internal: false, netmask: "255.255.0.0", mac: "0a:00:27:00:00:0a", cidr: "192.168.56.1/24" }], | ||
| "VMware Network Adapter VMnet8": [{ address: "192.168.159.1", family: "IPv4", internal: false, netmask: "255.255.255.0", mac: "00:50:56:c0:00:08", cidr: "192.168.159.1/24" }], | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The VMware fixture never exercises Prompt To Fix With AIThis is a comment left during a code review.
Path: apps/desktop/src/main/services/sync/deviceRegistryService.test.ts
Line: 40
Comment:
**VMware MAC check goes untested**
The VMware fixture never exercises `WINDOWS_HOST_ADAPTER_MAC`: its name contains `VMnet8`, so the existing name filter skips it first. A broken VMware MAC pattern would still pass this test. Give this fixture an unrelated name, as the test already does for VirtualBox, so it checks the promised renamed-adapter behavior.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time! |
||
| // A user-renamed VirtualBox adapter: only its MAC identifies it. | ||
| "Lab Only": [{ address: "192.168.56.2", family: "IPv4", internal: false, netmask: "255.255.0.0", mac: "0a:00:27:00:00:0b", cidr: "192.168.56.2/24" }], | ||
| "vEthernet (External)": [{ address: "192.168.1.25", family: "IPv4", internal: false, netmask: "255.255.255.0", mac: "00:00:00:00:00:04", cidr: "192.168.1.25/24" }], | ||
| en0: [{ address: "192.168.1.30", family: "IPv4", internal: false, netmask: "255.255.255.0", mac: "00:00:00:00:00:05", cidr: "192.168.1.30/24" }], | ||
| tailscale0: [{ address: "100.70.0.4", family: "IPv4", internal: false, netmask: "255.255.255.255", mac: "00:00:00:00:00:06", cidr: "100.70.0.4/32" }], | ||
| } as unknown as ReturnType<typeof os.networkInterfaces>); | ||
|
|
||
| const defaults = localSyncDeviceDefaults(); | ||
| networkInterfaces.mockRestore(); | ||
|
|
||
| expect(defaults.ipAddresses).toEqual(["192.168.1.25", "192.168.1.30"]); | ||
| expect(defaults.lastHost).toBe("192.168.1.25"); | ||
| expect(defaults.tailscaleIp).toBe("100.70.0.4"); | ||
| try { | ||
| const defaults = localSyncDeviceDefaults(); | ||
| expect(defaults.ipAddresses).toEqual(["192.168.1.25", "192.168.1.30"]); | ||
| expect(defaults.lastHost).toBe("192.168.1.25"); | ||
| expect(defaults.tailscaleIp).toBe("100.70.0.4"); | ||
| } finally { | ||
| networkInterfaces.mockRestore(); | ||
| if (platform) Object.defineProperty(process, "platform", platform); | ||
| } | ||
| }); | ||
|
|
||
| it("keeps a stable local device identity across restarts and bootstraps the cluster brain", async () => { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After an upgrade, an address such as
198.19.2.2previously saved fromutun40remains intailscaleIp. The new filter skips it, butensureLocalDeviceandtouchLocalDevicekeep the saved value when the fresh value is null—even when a real LAN address exists. Bonjour and pairing candidates then offer that unusable address to phones again.Remove excluded addresses from saved values too, and allow
upsertDeviceRecordto cleartailscaleIp.Prompt To Fix With AI