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
20 changes: 20 additions & 0 deletions pkgs/lab-ops-hub/container/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
26 changes: 26 additions & 0 deletions pkgs/lab-ops-hub/test/lib.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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/",
Comment on lines +201 to +204

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Remove Node-accepted hosts from the blocked test cases

The package CI runs npm test under Node 24 (.github/workflows/lab-ops-hub.yml), whose URL parser accepts both the standalone Hanifi Rohingya digit on line 201 and standalone U+066B on line 204, normalizing them to xn--jf0d.com and xn--kib.com. Consequently the loop reaches line 210 with validateCrawlUrl(u).ok === true; I reproduced the suite failing on http://𐴰.com/. Since these Bun-only verdicts cannot be asserted by the Node-based suite, move them to the container/Bun coverage or implement an explicit check in the TypeScript validator.

Useful? React with 👍 / 👎.

];
// (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
Expand Down
30 changes: 30 additions & 0 deletions pkgs/lab-ops-hub/test/test_container_validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -699,13 +719,23 @@ 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
# accepted, matching the Worker.
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/")

Expand Down
Loading