Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion pkgs/lab-ops-hub/container/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 7 additions & 1 deletion pkgs/lab-ops-hub/src/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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("]")) {
Expand Down
12 changes: 12 additions & 0 deletions pkgs/lab-ops-hub/test/lib.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions pkgs/lab-ops-hub/test/test_container_validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
Loading