diff --git a/pkgs/lab-ops-hub/container/app.py b/pkgs/lab-ops-hub/container/app.py index 60ebbff3ac..f73d640aed 100644 --- a/pkgs/lab-ops-hub/container/app.py +++ b/pkgs/lab-ops-hub/container/app.py @@ -470,8 +470,18 @@ def _judge_idna_label(label, host): # interpreter's unicodedata is 15.0.0, so a few dozen codepoints # assigned in later Unicode versions read as Cn here while the # Worker's newer tables accept them (the same version skew PR - # #584 accepted for A-labels), and U+0345, which UTS-46 maps to - # a letter, reads as a leading mark here. + # #584 accepted for A-labels). + # UTS-46 mapping is not NFKC: U+0345 (combining Greek + # ypogegrammeni) maps to U+03B9 (ι, bidi class L), but NFKC + # leaves it unchanged (the mapping lives in the special-casing + # data), so the mapped host validate_crawl_url hands over still + # carries it as a combining mark (bidi NSM), legal mid-label in + # any context. Judge the UTS-46-mapped form: inside an RTL + # label the mapped letter makes the label R + L + R, a bidi + # violation the Worker refuses, while at label start the mapped + # letter is an ordinary first character, closing the former + # leading-mark over-refusal (#596). + label = label.translate({0x0345: "ι"}) if any(_maps_to_label_separator(c) for c in label if ord(c) > 0x7F): # A decoded A-label is judged unmapped, so the mapped-dot # refusal in validate_crawl_url never sees this form. diff --git a/pkgs/lab-ops-hub/test/lib.test.ts b/pkgs/lab-ops-hub/test/lib.test.ts index f097f40f77..d53b718a2e 100644 --- a/pkgs/lab-ops-hub/test/lib.test.ts +++ b/pkgs/lab-ops-hub/test/lib.test.ts @@ -239,6 +239,25 @@ test("validateCrawlUrl judges Arabic-Indic digits by their bidi context (#605)", assert.equal(validateCrawlUrl("http://xn--4db40a.com/").ok, true); }); +test("validateCrawlUrl judges U+0345 by its UTS-46 mapping (#596)", () => { + // UTS-46 maps U+0345 (combining Greek ypogegrammeni) to U+03B9 + // (ι, bidi class L): inside an RTL label the mapped form mixes + // L with R and is refused. The container validator judged the + // unmapped mark (bidi NSM) and certified these hosts; it now + // pins the same verdicts (#596). + assert.equal(validateCrawlUrl("http://\u05d0\u0345\u05d0.com/").ok, false); + assert.equal(validateCrawlUrl("http://\u05d0\u0345.com/").ok, false); + // (The A-label spelling xn--jua51kba is refused under Bun but + // accepted by Node's URL parser, so it is pinned only in the + // container suite.) + // Controls: LTR/Greek contexts and the label-start spelling + // (U+0345 maps to a letter, so the label starts with one) stay + // accepted. + assert.equal(validateCrawlUrl("http://ex\u0345ample.com/").ok, true); + assert.equal(validateCrawlUrl("http://\u03b1\u0345.com/").ok, true); + assert.equal(validateCrawlUrl("http://\u0345abc.com/").ok, true); +}); + test("validateCrawlUrl refuses hosts whose mapping introduces a separator (#593)", () => { // U+FE12's compatibility mapping is U+3002, itself a UTS-46 label // separator: WHATWG domain-to-ASCII refuses the host outright diff --git a/pkgs/lab-ops-hub/test/test_container_validate.py b/pkgs/lab-ops-hub/test/test_container_validate.py index b4cbc4842f..bd882c6d6e 100644 --- a/pkgs/lab-ops-hub/test/test_container_validate.py +++ b/pkgs/lab-ops-hub/test/test_container_validate.py @@ -673,6 +673,26 @@ def test_accepts_arabic_indic_digits_inside_rtl_labels(self): self.assertRefused("http://\u05d0\u06611.com/") self.assertRefused("http://\u0661\u0627.com/") + def test_judges_u0345_by_its_uts46_mapping(self): + # UTS-46 maps U+0345 (combining Greek ypogegrammeni) to + # U+03B9 (ι, bidi class L), but NFKC leaves it unchanged, so + # the container judged it as a combining mark (bidi NSM) — + # legal mid-label anywhere — while the Worker judges the + # mapped letter: inside an RTL label the mapped form is + # R + L + R, a bidi violation (#596). + self.assertRefused("http://\u05d0\u0345\u05d0.com/") + self.assertRefused("http://\u05d0\u0345.com/") + # The A-label spelling of the first host is refused too. + self.assertRefused("http://xn--jua51kba.com/") + # Controls: in LTR/Greek contexts the mapped letter is an + # ordinary character and the hosts stay accepted. + self.assertAccepted("http://ex\u0345ample.com/") + self.assertAccepted("http://\u03b1\u0345.com/") + # Pin: at label start the mapping closes the former + # leading-mark over-refusal — U+0345 maps to a letter, so + # the label starts with one, matching the Worker (#596). + self.assertAccepted("http://\u0345abc.com/") + def test_refuses_idna_invalid_hosts(self): # A label can punycode-encode without being a valid IDNA # label at all: the mapped host was never IDNA-validated, so