diff --git a/src/main/ipc/mobile.test.ts b/src/main/ipc/mobile.test.ts index 2c043fed9..85b7007d8 100644 --- a/src/main/ipc/mobile.test.ts +++ b/src/main/ipc/mobile.test.ts @@ -59,6 +59,42 @@ describe('registerMobileHandlers', () => { }) }) + it('excludes proxy fake-ip addresses so pairing defaults to LAN (#10404)', async () => { + networkInterfacesMock.mockReturnValue({ + utun4: [ + { family: 'IPv4', internal: false, address: '198.18.0.1' }, + { family: 'IPv4', internal: false, address: '198.19.255.254' } + ], + en0: [ + { family: 'IPv4', internal: false, address: '192.168.50.238' }, + { family: 'IPv4', internal: false, address: '198.17.255.254' }, + { family: 'IPv4', internal: false, address: '198.20.0.1' } + ] + }) + const createMobilePairingOffer = vi.fn().mockResolvedValue({ + available: true, + pairingUrl: 'orca://pair#lan', + endpoint: 'ws://192.168.50.238:6768', + deviceId: 'mobile-lan', + connectionMode: 'automatic' + }) + + registerMobileHandlers({ createMobilePairingOffer } as never) + + expect(handlers.get('mobile:listNetworkInterfaces')?.()).toEqual({ + interfaces: [ + { name: 'en0', address: '192.168.50.238' }, + { name: 'en0', address: '198.17.255.254' }, + { name: 'en0', address: '198.20.0.1' } + ] + }) + + await handlers.get('mobile:getPairingQR')?.(null, {}) + expect(createMobilePairingOffer).toHaveBeenCalledWith( + expect.objectContaining({ address: '192.168.50.238' }) + ) + }) + it('includes IPv6 addresses (ranked after IPv4) and excludes link-local IPv6', () => { networkInterfacesMock.mockReturnValue({ en0: [ diff --git a/src/main/ipc/mobile.ts b/src/main/ipc/mobile.ts index fd46171a0..8d70a0fbc 100644 --- a/src/main/ipc/mobile.ts +++ b/src/main/ipc/mobile.ts @@ -26,6 +26,10 @@ function isUsableIPv6Address(address: string): boolean { return !/^fe[89ab][0-9a-f]:/i.test(address) } +function isProxyFakeIpIPv4Address(address: string): boolean { + return /^198\.(?:18|19)\./.test(address) +} + // Why: the WebSocket transport advertises 0.0.0.0 as its endpoint, which isn't // connectable from a mobile device. We enumerate all non-internal IPv4 and // (non-link-local) IPv6 addresses so the user can choose which one to advertise @@ -44,6 +48,10 @@ function getNetworkInterfaces(): NetworkInterface[] { continue } if (addr.family === 'IPv4') { + // 198.18.0.0/15 proxy fake IPs are only routable inside the desktop proxy. + if (isProxyFakeIpIPv4Address(addr.address)) { + continue + } result.push({ name, address: addr.address }) } else if (addr.family === 'IPv6' && isUsableIPv6Address(addr.address)) { result.push({ name, address: addr.address })