From 2160f1cd8720bdf88acb12cc566ca5d6703cb25e Mon Sep 17 00:00:00 2001 From: Muse Sweep Date: Wed, 21 Oct 2026 04:01:15 -0500 Subject: [PATCH 1/2] fix(lab-ops-hub): refuse trailing-dot spellings of blocked crawl hosts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit validateCrawlUrl (Worker) and validate_crawl_url (container) checked the host exactly as spelled, so the FQDN form with a DNS root dot — localhost., foo.localhost., printer.local. and, in Python where ip_address() rejects the dotted string, 127.0.0.1. / 169.254.169.254. — evaded every localhost/suffix/non-global-IP check while resolving to the same host. Both validators now strip a single trailing dot before the checks; public dotted names (example.com.) stay allowed. Redirect hops validate through the same functions, so they inherit the fix. Fixes #466 --- pkgs/lab-ops-hub/container/app.py | 6 ++++++ pkgs/lab-ops-hub/src/lib.ts | 6 +++++- pkgs/lab-ops-hub/test/lib.test.ts | 15 +++++++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/pkgs/lab-ops-hub/container/app.py b/pkgs/lab-ops-hub/container/app.py index 7137e76328..3f03b31e6e 100644 --- a/pkgs/lab-ops-hub/container/app.py +++ b/pkgs/lab-ops-hub/container/app.py @@ -31,6 +31,12 @@ def validate_crawl_url(raw): if u.scheme not in ("http", "https"): raise ValueError("only http: and https: URLs may be crawled") host = (u.hostname or "").lower() + # A single trailing dot is the DNS root dot (the FQDN spelling of the + # same host: "localhost." is "localhost", "127.0.0.1." is 127.0.0.1); + # strip it before the checks so the dotted spelling cannot evade + # them, matching the Worker's validateCrawlUrl (#466). + if host.endswith("."): + host = host[:-1] if not host: raise ValueError("url has no host") if host == "localhost" or host.endswith(_BLOCKED_SUFFIXES): diff --git a/pkgs/lab-ops-hub/src/lib.ts b/pkgs/lab-ops-hub/src/lib.ts index ff756435fe..d24a337c1e 100644 --- a/pkgs/lab-ops-hub/src/lib.ts +++ b/pkgs/lab-ops-hub/src/lib.ts @@ -72,7 +72,11 @@ export function validateCrawlUrl(raw: string): { ok: true; url: string } | { ok: } // WHATWG URL normalises integer/hex IPv4 forms (e.g. 2130706433, // 0x7f.1) to dotted-quad, and keeps IPv6 literals bracketed. - const host = u.hostname.toLowerCase(); + // A single trailing dot is the DNS root dot (the FQDN spelling of the + // same host: "localhost." is "localhost"); strip it before the checks + // so the dotted spelling cannot evade them (#466). + const rawHost = u.hostname.toLowerCase(); + const host = rawHost.endsWith(".") ? rawHost.slice(0, -1) : rawHost; if (!host) return { ok: false, error: "url has no host" }; if (host === "localhost" || BLOCKED_HOST_SUFFIXES.some((s) => host.endsWith(s))) { return { ok: false, error: `refusing to crawl local host ${host}` }; diff --git a/pkgs/lab-ops-hub/test/lib.test.ts b/pkgs/lab-ops-hub/test/lib.test.ts index 0b6af7a0bf..b4a330b430 100644 --- a/pkgs/lab-ops-hub/test/lib.test.ts +++ b/pkgs/lab-ops-hub/test/lib.test.ts @@ -41,6 +41,20 @@ test("validateCrawlUrl refuses loopback / private / link-local targets (#441)", } }); +test("validateCrawlUrl refuses trailing-dot spellings of blocked hosts (#466)", () => { + const blocked = [ + "http://localhost./", + "http://foo.localhost./", + "http://printer.local./", + "http://nas.internal./", + ]; + for (const u of blocked) { + assert.equal(validateCrawlUrl(u).ok, false, u); + } + // A public name keeps its fully-qualified spelling. + assert.equal(validateCrawlUrl("http://example.com./").ok, true); +}); + function stubFetcher(routes: Record) { const seen: string[] = []; const fetchFn = async (url: string): Promise => { @@ -73,6 +87,7 @@ test("fetchFollowingValidatedRedirects refuses redirects to non-public targets ( "http://192.168.1.1/", "https://[::1]/", "http://localhost:8787/", + "http://localhost./", "file:///etc/passwd", ]) { const { fetchFn, seen } = stubFetcher({ From f4e2c807ceb10e427d509e82ead463e1be5e4c56 Mon Sep 17 00:00:00 2001 From: Muse Sweep Date: Wed, 21 Oct 2026 04:04:32 -0500 Subject: [PATCH 2/2] style(lab-ops-hub): apply treefmt formatting to the #466 test --- pkgs/lab-ops-hub/test/lib.test.ts | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/pkgs/lab-ops-hub/test/lib.test.ts b/pkgs/lab-ops-hub/test/lib.test.ts index b4a330b430..bd98d7df71 100644 --- a/pkgs/lab-ops-hub/test/lib.test.ts +++ b/pkgs/lab-ops-hub/test/lib.test.ts @@ -42,12 +42,7 @@ test("validateCrawlUrl refuses loopback / private / link-local targets (#441)", }); test("validateCrawlUrl refuses trailing-dot spellings of blocked hosts (#466)", () => { - const blocked = [ - "http://localhost./", - "http://foo.localhost./", - "http://printer.local./", - "http://nas.internal./", - ]; + const blocked = ["http://localhost./", "http://foo.localhost./", "http://printer.local./", "http://nas.internal./"]; for (const u of blocked) { assert.equal(validateCrawlUrl(u).ok, false, u); }