diff --git a/pkgs/lab-ops-hub/container/app.py b/pkgs/lab-ops-hub/container/app.py index 60ebbff3ac..540802be1e 100644 --- a/pkgs/lab-ops-hub/container/app.py +++ b/pkgs/lab-ops-hub/container/app.py @@ -299,7 +299,14 @@ def validate_crawl_url(raw): for c in host ): raise ValueError(f"refusing to crawl host with a forbidden character {host!r}") - if host == "localhost" or host.endswith(_BLOCKED_SUFFIXES): + # "home.arpa" needs the same equality arm as "localhost": the + # suffixes carry a leading dot, so the bare apex escapes them, but + # home.arpa is itself the RFC 8375 special-use name for the local + # home network — its subdomains are not the only local spellings + # (#608). (The other suffixes' bare labels — "local", "internal", + # "lan" — are ordinary single-label hostnames, not designated + # local names, and stay accepted.) + if host in ("localhost", "home.arpa") or host.endswith(_BLOCKED_SUFFIXES): raise ValueError(f"refusing to crawl local host {host}") try: ip = ipaddress.ip_address(host) diff --git a/pkgs/lab-ops-hub/src/lib.ts b/pkgs/lab-ops-hub/src/lib.ts index 3d851e5c0d..d7fa515ad7 100644 --- a/pkgs/lab-ops-hub/src/lib.ts +++ b/pkgs/lab-ops-hub/src/lib.ts @@ -166,7 +166,13 @@ export function validateCrawlUrl(raw: string): { ok: true; url: string } | { ok: if (!host.startsWith("[") && (host.length > 253 || host.split(".").some((label) => label.length > 63))) { return { ok: false, error: `refusing to crawl host with an overlong label or name ${host}` }; } - if (host === "localhost" || BLOCKED_HOST_SUFFIXES.some((s) => host.endsWith(s))) { + // "home.arpa" needs the same equality arm as "localhost": the + // suffixes carry a leading dot, so the bare apex escapes them, but + // home.arpa is itself the RFC 8375 special-use name for the local + // home network (#608). The other suffixes' bare labels ("local", + // "internal", "lan") are ordinary single-label hostnames, not + // designated local names, and stay accepted. + if (host === "localhost" || host === "home.arpa" || BLOCKED_HOST_SUFFIXES.some((s) => host.endsWith(s))) { return { ok: false, error: `refusing to crawl local host ${host}` }; } if (host.startsWith("[") && host.endsWith("]")) { diff --git a/pkgs/lab-ops-hub/test/lib.test.ts b/pkgs/lab-ops-hub/test/lib.test.ts index f097f40f77..e883128802 100644 --- a/pkgs/lab-ops-hub/test/lib.test.ts +++ b/pkgs/lab-ops-hub/test/lib.test.ts @@ -150,6 +150,18 @@ test("validateCrawlUrl refuses trailing-dot spellings of blocked hosts (#466)", assert.equal(validateCrawlUrl("http://example.com./").ok, true); }); +test("validateCrawlUrl refuses the bare home.arpa apex (#608)", () => { + // Every subdomain of home.arpa is refused via the ".home.arpa" + // suffix, but the apex itself is the RFC 8375 special-use name for + // the local home network — it needs the equality arm localhost has. + const blocked = ["http://home.arpa/", "http://home.arpa./", "http://HOME.ARPA/", "http://router.home.arpa/"]; + for (const u of blocked) { + assert.equal(validateCrawlUrl(u).ok, false, u); + } + // Controls: an ordinary public name still passes. + assert.equal(validateCrawlUrl("http://example.com/").ok, true); +}); + test("validateCrawlUrl refuses empty-label hosts (#511)", () => { // A second trailing dot defeats the one-dot strip (#466): "localhost.." // becomes "localhost." and misses the blocked-host checks. An interior diff --git a/pkgs/lab-ops-hub/test/test_container_validate.py b/pkgs/lab-ops-hub/test/test_container_validate.py index b4cbc4842f..01c696b3e8 100644 --- a/pkgs/lab-ops-hub/test/test_container_validate.py +++ b/pkgs/lab-ops-hub/test/test_container_validate.py @@ -128,6 +128,12 @@ def test_refuses_non_http_schemes_and_local_names(self): "http://printer.local/", "http://nas.internal/", "http://localhost./", + # The bare home.arpa apex is itself the RFC 8375 local + # name — the dotted suffix alone misses it (#608). + "http://home.arpa/", + "http://home.arpa./", + "http://HOME.ARPA/", + "http://router.home.arpa/", ): self.assertRefused(url)