From 55947a35576b0633ddb3e5832201824d33cd3715 Mon Sep 17 00:00:00 2001 From: Wooseong Kim <2222333+innocarpe@users.noreply.github.com> Date: Wed, 29 Jul 2026 06:14:13 +0900 Subject: [PATCH] fix(mobile): exclude proxy fake-ip addresses from pairing QR (#10498) * fix(mobile): exclude proxy fake-ip addresses from pairing QR Clash/mihomo TUN interfaces in 198.18.0.0/15 were enumerated as pairing candidates and could become the default QR endpoint. Phones then retry an unroutable address forever. Drop those addresses from the pickable list (#10404). * refactor(mobile): keep fake-ip filtering local * test(mobile): cover fake-ip range boundaries --------- Co-authored-by: Brennan Benson <79079362+brennanb2025@users.noreply.github.com> --- src/main/ipc/mobile.test.ts | 36 ++++++++++++++++++++++++++++++++++++ src/main/ipc/mobile.ts | 8 ++++++++ 2 files changed, 44 insertions(+) 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 })