From f7311bb1e609d196a8f521738096973361c3f7a7 Mon Sep 17 00:00:00 2001 From: Muse Sweep Date: Wed, 21 Oct 2026 19:03:55 -0500 Subject: [PATCH 1/2] lab-ops-hub: refuse overlong DNS names in both crawl validators (#513) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit RFC 1035 §2.3.4 limits labels to 63 octets and names to 253 text characters; both validators certified longer names as public DNS names and let the resolver fail on them inside the fetcher. Add the length check beside the #511 empty-label check in each validator, with tests (including the at-limit 63/253 near misses) in both suites. Ablation-verified: each new test fails pre-fix. --- pkgs/lab-ops-hub/container/app.py | 13 +++++++++++++ pkgs/lab-ops-hub/src/lib.ts | 12 ++++++++++++ pkgs/lab-ops-hub/test/lib.test.ts | 19 +++++++++++++++++++ .../test/test_container_validate.py | 16 ++++++++++++++++ 4 files changed, 60 insertions(+) diff --git a/pkgs/lab-ops-hub/container/app.py b/pkgs/lab-ops-hub/container/app.py index 810f557ce7..7e16f29dd7 100644 --- a/pkgs/lab-ops-hub/container/app.py +++ b/pkgs/lab-ops-hub/container/app.py @@ -57,6 +57,19 @@ def validate_crawl_url(raw): # structure. if ":" not in host and any(label == "" for label in host.split(".")): raise ValueError(f"refusing to crawl host with an empty label {host}") + # A label over 63 octets, or a name over 253 characters, can never + # be a DNS name at all (RFC 1035 §2.3.4: 63-octet labels, 255-octet + # wire names = 253 characters of text without the root dot, which + # the strip above already removed) — refuse it up front instead of + # certifying it as a public DNS name and letting the resolver fail + # on it deep inside the fetcher, matching the Worker's validator + # (#513). Character length is a lower bound on the IDNA-encoded + # length, so this can never refuse a name that encodes within the + # limits. IPv6 literals are judged as addresses, as above. + if ":" not in host and ( + len(host) > 253 or any(len(label) > 63 for label in host.split(".")) + ): + raise ValueError(f"refusing to crawl host with an overlong label or name {host}") # A raw % in the host is a percent-encoded spelling (or an IPv6 zone # id): WHATWG URL parsing percent-decodes the host before judging it # — %6cocalhost is localhost — and rejects the rest outright, while diff --git a/pkgs/lab-ops-hub/src/lib.ts b/pkgs/lab-ops-hub/src/lib.ts index c36092e02f..e93c447aa2 100644 --- a/pkgs/lab-ops-hub/src/lib.ts +++ b/pkgs/lab-ops-hub/src/lib.ts @@ -153,6 +153,18 @@ export function validateCrawlUrl(raw: string): { ok: true; url: string } | { ok: if (!host.startsWith("[") && host.split(".").some((label) => label === "")) { return { ok: false, error: `refusing to crawl host with an empty label ${host}` }; } + // A label over 63 octets, or a name over 253 characters, can never + // be a DNS name at all (RFC 1035 §2.3.4: 63-octet labels, 255-octet + // wire names = 253 characters of text without the root dot, which + // the strip above already removed) — refuse it up front instead of + // certifying it as a public DNS name and letting the resolver fail + // on it, matching the container's validator (#513). u.hostname is + // already the punycode (IDNA-encoded) form, so these lengths are + // the wire lengths exactly. Bracketed IPv6 literals are exempt, as + // with the empty-label check above. + 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))) { 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 206447ba05..be3cf8ecc5 100644 --- a/pkgs/lab-ops-hub/test/lib.test.ts +++ b/pkgs/lab-ops-hub/test/lib.test.ts @@ -163,6 +163,25 @@ test("validateCrawlUrl refuses empty-label hosts (#511)", () => { assert.equal(validateCrawlUrl("http://example.com/").ok, true); }); +test("validateCrawlUrl refuses overlong DNS names (#513)", () => { + // RFC 1035 §2.3.4: no label over 63 octets, no name over 253 + // characters of text. Neither can ever resolve; refuse up front. + const blocked = [ + `http://${"b".repeat(64)}.com/`, + `http://${["a".repeat(63), "a".repeat(63), "a".repeat(63), "a".repeat(63), "com"].join(".")}/`, + ]; + for (const u of blocked) { + assert.equal(validateCrawlUrl(u).ok, false, u); + } + // Controls at the limit stay allowed: a 63-char label, and a + // 253-char name (63+63+63+61 + 3 dots). + assert.equal(validateCrawlUrl(`http://${"b".repeat(63)}.com/`).ok, true); + assert.equal( + validateCrawlUrl(`http://${["a".repeat(63), "a".repeat(63), "a".repeat(63), "a".repeat(61)].join(".")}/`).ok, + true, + ); +}); + function stubFetcher(routes: Record) { const seen: string[] = []; const fetchFn = async (url: string): Promise => { diff --git a/pkgs/lab-ops-hub/test/test_container_validate.py b/pkgs/lab-ops-hub/test/test_container_validate.py index 2e2cd463aa..7c35afe7be 100644 --- a/pkgs/lab-ops-hub/test/test_container_validate.py +++ b/pkgs/lab-ops-hub/test/test_container_validate.py @@ -51,6 +51,22 @@ def test_refuses_empty_label_hosts(self): self.assertAccepted("http://example.com./") self.assertAccepted("http://example.com/") + def test_refuses_overlong_dns_names(self): + # RFC 1035 §2.3.4: no label over 63 octets, no name over 253 + # characters of text. Neither can ever resolve; refuse up + # front instead of certifying them as public DNS names (#513). + overlong_name = ".".join(["a" * 63] * 4 + ["com"]) # 259 chars + for url in ( + "http://" + "b" * 64 + ".com/", + "http://" + overlong_name + "/", + ): + self.assertRefused(url) + # Controls at the limit stay allowed: a 63-char label, and a + # 253-char name (63+63+63+61 + 3 dots). + self.assertAccepted("http://" + "b" * 63 + ".com/") + at_limit_name = ".".join(["a" * 63] * 3 + ["a" * 61]) # 253 chars + self.assertAccepted("http://" + at_limit_name + "/") + def test_refuses_dotted_quad_non_public(self): for url in ( "http://127.0.0.1/", From 75a6907cc3bffd63347df6fd86e098e6680c501c Mon Sep 17 00:00:00 2001 From: Muse Sweep Date: Wed, 21 Oct 2026 19:06:59 -0500 Subject: [PATCH 2/2] lab-ops-hub: ruff-format the #513 container check (treefmt) --- pkgs/lab-ops-hub/container/app.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pkgs/lab-ops-hub/container/app.py b/pkgs/lab-ops-hub/container/app.py index 7e16f29dd7..61ab8c62d4 100644 --- a/pkgs/lab-ops-hub/container/app.py +++ b/pkgs/lab-ops-hub/container/app.py @@ -69,7 +69,9 @@ def validate_crawl_url(raw): if ":" not in host and ( len(host) > 253 or any(len(label) > 63 for label in host.split(".")) ): - raise ValueError(f"refusing to crawl host with an overlong label or name {host}") + raise ValueError( + f"refusing to crawl host with an overlong label or name {host}" + ) # A raw % in the host is a percent-encoded spelling (or an IPv6 zone # id): WHATWG URL parsing percent-decodes the host before judging it # — %6cocalhost is localhost — and rejects the rest outright, while