diff --git a/pkgs/lab-ops-hub/container/app.py b/pkgs/lab-ops-hub/container/app.py index 377ab5d4d2..c1796bb01e 100644 --- a/pkgs/lab-ops-hub/container/app.py +++ b/pkgs/lab-ops-hub/container/app.py @@ -450,6 +450,16 @@ def _judge_idna_label(label, host): # characters — outside an Arabic-script context the Worker # refuses them, while a pure Arabic label carrying one stays # accepted, matching the Worker; + # - it carries a character of bidi class AN (Arabic number) + # outside a right-to-left label, or mixes AN with EN (European + # number) in one label (#595): AN is only valid inside an RTL + # label, and never alongside EN. Every BMP AN codepoint is + # caught by another arm (the Cf check, the U+0660-U+0669 + # forbidden range, the U+066B / U+066C case above, which this + # rule subsumes), but the 41 astral AN codepoints — the Hanifi + # Rohingya digits U+10D30-U+10D39 and the Rumi digits + # U+10E60-U+10E7E — passed every other check, and an AN+EN + # mix inside an RTL label passed too; # - the stdlib IDNA codec rejects it. # Known residuals, measured on the #583 differential battery # (13,045 hosts vs the Worker's validator under Bun): this @@ -493,6 +503,16 @@ def _judge_idna_label(label, host): f"refusing to crawl host {host}: label {label!r} " "contains an Arabic separator outside an Arabic label" ) + if "AN" in bidis and (has_ltr or not has_rtl): + raise ValueError( + f"refusing to crawl host {host}: label {label!r} " + "contains an Arabic number outside a right-to-left label" + ) + if "AN" in bidis and "EN" in bidis: + raise ValueError( + f"refusing to crawl host {host}: label {label!r} " + "mixes Arabic and European numbers" + ) try: label.encode("idna") except UnicodeError as e: diff --git a/pkgs/lab-ops-hub/test/lib.test.ts b/pkgs/lab-ops-hub/test/lib.test.ts index 8736d1f1d1..bc66e04163 100644 --- a/pkgs/lab-ops-hub/test/lib.test.ts +++ b/pkgs/lab-ops-hub/test/lib.test.ts @@ -189,6 +189,32 @@ test("validateCrawlUrl refuses IDNA-invalid hosts (#583)", () => { assert.equal(validateCrawlUrl("http://münchen.de/").ok, true); }); +test("validateCrawlUrl refuses Arabic numbers outside RTL labels (#595)", () => { + // A character of bidi class AN (Arabic number) is only valid + // inside an RTL label, and never alongside EN (European number): + // the astral AN codepoints (Hanifi Rohingya digits U+10D30-U+10D39, + // Rumi digits U+10E60-U+10E7E) were certified by the container + // validator in Latin labels. It now pins the same verdicts (#595). + const blocked = [ + "http://ex\u{10d30}ample.com/", + "http://ex\u{10e60}ample.com/", + "http://\u{10d30}.com/", + "http://1\u{10d30}.com/", + "http://\u05d0\u{10d30}1.com/", + "http://\u066b.com/", + ]; + // (The A-label spelling xn--example-eh36b is refused under Bun but + // accepted by Node's URL parser, so it is pinned only in the + // container suite.) + for (const u of blocked) { + assert.equal(validateCrawlUrl(u).ok, false, u); + } + // Controls: an AN digit inside a genuine RTL label stays accepted. + assert.equal(validateCrawlUrl("http://\u05d0\u{10d30}\u05d0.com/").ok, true); + assert.equal(validateCrawlUrl("http://\u0627\u{10d30}\u0627.com/").ok, true); + assert.equal(validateCrawlUrl("http://\u{10d00}\u{10d30}.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 65d541ca24..fb2c51481a 100644 --- a/pkgs/lab-ops-hub/test/test_container_validate.py +++ b/pkgs/lab-ops-hub/test/test_container_validate.py @@ -677,6 +677,26 @@ def test_refuses_idna_invalid_hosts(self): # with strong LTR characters: self.assertRefused("http://ex\u066bample.com/") self.assertRefused("http://ex\u066cample.com/") + # A character of bidi class AN (Arabic number) is only valid + # inside an RTL label: the astral AN codepoints — Hanifi + # Rohingya and Rumi digits — passed every other arm of this + # check in Latin, neutral and digit-led labels (#595), and + # AN may not mix with EN (European number) even in an RTL + # label. The U+066B case below is the BMP instance of the + # AN+EN rule (U+066B is itself class AN). + self.assertRefused("http://ex\U00010d30ample.com/") + self.assertRefused("http://ex\U00010e60ample.com/") + self.assertRefused("http://\U00010d30abc.com/") + self.assertRefused("http://abc\U00010d30.com/") + self.assertRefused("http://m\u00fcnchen\U00010d30.de/") + self.assertRefused("http://\U00010d30.com/") + self.assertRefused("http://1\U00010d30.com/") + self.assertRefused("http://-\U00010d30.com/") + self.assertRefused("http://\u05d0\U00010d301.com/") + self.assertRefused("http://\u05d01\U00010d30.com/") + self.assertRefused("http://\u0627\u066b1.com/") + # An AN character alone is not an RTL label either: + self.assertRefused("http://\u066b.com/") # Characters whose compatibility mapping introduces a label # separator are disallowed (only U+3002/U+FF0E/U+FF61 are # UTS-46 separators); after NFKC they would be judged as two @@ -699,6 +719,9 @@ def test_refuses_idna_invalid_hosts(self): # The A-label spelling of "ex\ufe12ample": the decoded label # carries U+FE12, whose mapping is the U+3002 separator (#593). self.assertRefused("http://xn--example-t673b.com/") + # The A-label spelling of "ex\U00010d30ample": the decoded + # label carries an astral AN digit in a Latin label (#595). + self.assertRefused("http://xn--example-eh36b.com/") # Controls: pure RTL labels (with or without a trailing # European digit), the Arabic separator inside a pure Arabic # label, ordinary IDN, and a mid-label combining mark all stay @@ -706,6 +729,13 @@ def test_refuses_idna_invalid_hosts(self): self.assertAccepted("http://\u05d0\u05d0.com/") self.assertAccepted("http://\u05d01.com/") self.assertAccepted("http://\u0627\u066b\u0627.com/") + # An AN digit inside a genuine RTL label (Hebrew, Arabic, or + # its own Hanifi Rohingya script) stays accepted (#595): + self.assertAccepted("http://\u05d0\U00010d30\u05d0.com/") + self.assertAccepted("http://\u0627\U00010d30\u0627.com/") + self.assertAccepted("http://\U00010d00\U00010d30.com/") + self.assertAccepted("http://\u05d0\U00010d30.com/") + self.assertAccepted("http://xn--4dba5833r.com/") self.assertAccepted("http://m\u00fcnchen.de/") self.assertAccepted("http://ex\u0301ample.com/")