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>
This commit is contained in:
Wooseong Kim
2026-07-28 14:14:13 -07:00
committed by GitHub
co-authored by Brennan Benson
parent 6d4e335001
commit 55947a3557
2 changed files with 44 additions and 0 deletions
+36
View File
@@ -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: [
+8
View File
@@ -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 })