diff --git a/controller/lib/captive_portal.py b/controller/lib/captive_portal.py index e204a1f1..285ac8f5 100644 --- a/controller/lib/captive_portal.py +++ b/controller/lib/captive_portal.py @@ -16,6 +16,7 @@ logger = logging.getLogger(__name__) # wildcard would break the hotspot's forwarding of everything else to the WROLPi's uplink. PROBE_HOSTS = ( 'captive.apple.com', # iOS / macOS + 'captive.g.aaplimg.com', # the CDN name captive.apple.com aliases to 'connectivitycheck.gstatic.com', # Android 'connectivitycheck.android.com', # Android (older) 'www.msftconnecttest.com', # Windows 10+ @@ -88,8 +89,11 @@ def render_dnsmasq_config(ip: str) -> str: '# Captive portal: captive-portal probe hostnames resolve to this WROLPi.', '# Only these names are hijacked so the hotspot still forwards everything else.', ] - lines.extend(f'address=/{host}/{ip}' for host in PROBE_HOSTS) - lines.append(f'address=/{FRIENDLY_NAME}/{ip}') + for host in (*PROBE_HOSTS, FRIENDLY_NAME): + # `address=` only answers A/AAAA. Phones also ask for the HTTPS record type, and a + # forwarded answer leads them to the real host; `local=` never forwards any type. + lines.append(f'local=/{host}/') + lines.append(f'address=/{host}/{ip}') return '\n'.join(lines) + '\n' diff --git a/controller/test/test_captive_portal.py b/controller/test/test_captive_portal.py index 1a77ec5f..46e2ae5b 100644 --- a/controller/test/test_captive_portal.py +++ b/controller/test/test_captive_portal.py @@ -41,6 +41,15 @@ class TestRenderDnsmasqConfig: assert f'address=/{host}/10.42.0.1' in config assert f'address=/{FRIENDLY_NAME}/10.42.0.1' in config + def test_probe_hosts_are_never_forwarded(self): + """iOS asks for the HTTPS record type too; a forwarded answer leads it to the real Apple.""" + config = render_dnsmasq_config('10.42.0.1') + for host in (*PROBE_HOSTS, FRIENDLY_NAME): + assert f'local=/{host}/' in config + + def test_apple_cdn_alias_is_a_probe_host(self): + assert 'captive.g.aaplimg.com' in PROBE_HOSTS + def test_no_wildcard(self): """A wildcard would break the hotspot's Internet passthrough.""" assert '/#/' not in render_dnsmasq_config('10.42.0.1')