Skip to content
Closed
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
60 changes: 42 additions & 18 deletions pkgs/lab-ops-hub/container/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,35 @@ def _maps_to_label_separator(c: str) -> bool:
+ list(range(0x2066, 0x206A))
)

# The codepoints UTS-46 — the table the Worker's WHATWG
# domain-to-ASCII consults — marks DISALLOWED, per codepoint, in a
# category the earlier arms do not already refuse. UTS-46 is not
# category-based: the great majority of symbol, punctuation and
# separator codepoints are *valid* (the Worker accepts and
# punycode-encodes them: U+1F600 "😀", U+00A9 "©", U+2603 "☃",
# U+20AC "€", U+2665 "♥", U+00A7 "§" all round-trip through new URL
# as A-labels), so the old blanket "any non-ASCII P/S/Z" refusal
# over-refused them and left the package's own pinned
# WHATWG-alignment test red on main (#5947). What UTS-46 does reject
# is a much smaller per-codepoint set; most of it — the Cn, Cf, Cc,
# Co and Cs disallowed codepoints — is already refused by the
# forbidden-character, unassigned/format and private-use arms, so
# this frozenset carries only the disallowed codepoints of the
# remaining categories: the dot leaders, ellipsis and three
# separators (the separators also listed in _IDNA_DISALLOWED above),
# the enclosed alphanumerics, the ideographic description
# characters, the squared Latin abbreviations, the vertical/small
# presentation forms with no NFKC mapping, and the object/replacement
# characters. Frozen to IdnaMappingTable.txt 16.0.0 (2024-07-03); a
# codepoint UTS-46 later reclassifies is a deliberate version bump,
# not a unicodedata artefact.
_UTS46_DISALLOWED = frozenset(
[0x1680, 0x2024, 0x2025, 0x2026, 0x2028, 0x2029, 0xFFFC, 0xFFFD, 0x1F100]
+ list(range(0x2488, 0x249C))
+ list(range(0x2FF0, 0x3000))
+ [0x31EF, 0x33C2, 0x33C7, 0x33D8, 0xFE12, 0xFE19, 0xFE30, 0xFE52]
)


def validate_crawl_url(raw):
# WHATWG URL parsing first removes leading and trailing C0 control
Expand Down Expand Up @@ -762,31 +791,26 @@ def _judge_idna_label(label, host):
# violation the Worker refuses, while at label start the mapped
# letter is an ordinary first character, closing the former
# leading-mark over-refusal (#596).
# IDNA2008/UTS-46 marks every punctuation, symbol, separator,
# private-use and surrogate codepoint DISALLOWED (the CONTEXTO /
# CONTEXTJ exceptions below are judged by their own rules: the
# Catalan middle dot and Hebrew punctuation are context-judged
# UTS-46 judges symbol/punctuation/separator codepoints one by
# one, not by Unicode category: most are valid and the Worker's
# WHATWG domain-to-ASCII accepts them, while the smaller
# _UTS46_DISALLOWED set is refused (#5947). The CONTEXTO /
# CONTEXTJ exceptions are judged by their own rules: the Catalan
# middle dot and Hebrew punctuation are context-validated
# punctuation, the Arabic separators by the AN/separator rules
# below, and the undertie pair is CONTEXTJ joining punctuation).
# None of the checks around this one sees them: they are assigned
# (not Cn), not format characters (not Cf), NFKC leaves most of
# them unchanged, and the stdlib IDNA-2003 codec's stringprep
# tables do not prohibit them — so a decoded label carrying
# U+00A8, U+00B4, U+037E or a currency/math symbol passed while
# the Worker refuses it (#588). Category-based, not an enumerated
# table, so it carries no unicodedata version skew of its own.
# below, and the undertie pair is CONTEXTJ joining punctuation —
# all of them UTS-46 *valid*, so they are absent from the set.
# The Cn / Cf / Cc disallowed codepoints and the private-use /
# surrogate codepoints are refused by the arms around this one,
# so this check names only the residual disallowed codepoints.
if any(
ord(c) > 0x7F
and ord(c) not in (0x00B7, 0x05F3, 0x05F4, 0x066B, 0x066C, 0x203F, 0x2040)
and (
unicodedata.category(c)[0] in "PSZ"
or unicodedata.category(c) in ("Co", "Cs")
)
and (ord(c) in _UTS46_DISALLOWED or unicodedata.category(c) in ("Co", "Cs"))
for c in label
):
raise ValueError(
f"refusing to crawl host {host}: label {label!r} "
"contains an IDNA-disallowed punctuation, symbol or separator character"
"contains a UTS-46 disallowed punctuation, symbol or separator character"
)
label = label.translate({0x0345: "ι"})
if any(_maps_to_label_separator(c) for c in label if ord(c) > 0x7F):
Expand Down
52 changes: 49 additions & 3 deletions pkgs/lab-ops-hub/test/test_container_validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -1024,7 +1024,9 @@ def test_a_label_must_be_its_uts46_mapped_form_and_disallowed_free(self):
self.assertRefused(
"http://xn--mnchen-3ya5364d.com/"
) # m\u00fcn\u2000chen (space class)
# DISALLOWED class (survive NFKC, assigned, not format chars):
# DISALLOWED class (survive NFKC, assigned, not format chars).
# UTS-46 refuses these per codepoint, so the container does
# too — the #588 cases stay refused (#5947):
self.assertRefused(
"http://xn--example-hja.com/"
) # ex\u00a8ample (diaeresis, Sk)
Expand All @@ -1034,10 +1036,14 @@ def test_a_label_must_be_its_uts46_mapped_form_and_disallowed_free(self):
self.assertRefused(
"http://xn--example-f9e.com/"
) # ex\u037eample (Greek question mark, Po)
self.assertRefused(
# ...but the currency symbols are UTS-46 *valid*, not
# disallowed: the Worker's WHATWG parser accepts and
# re-encodes them, so the container must not refuse them
# (#5947). The old blanket P/S/Z arm refused both.
self.assertAccepted(
"http://xn--example-3ha.com/"
) # ex\u00a2ample (cent sign, Sc)
self.assertRefused(
self.assertAccepted(
"http://xn--example-u17c.com/"
) # ex\u20acample (euro sign, Sc)
# The raw spellings of the DISALLOWED class are refused too
Expand All @@ -1054,6 +1060,46 @@ def test_a_label_must_be_its_uts46_mapped_form_and_disallowed_free(self):
self.assertAccepted("http://xn--fsq.com/") # \u4f8b.com
self.assertAccepted("http://xn--al-0ea.com/") # a\u00b7l (Catalan middle dot)

def test_judges_uts46_symbols_per_codepoint(self):
# #5947: UTS-46 judges punctuation, symbol and separator
# codepoints one by one, not by Unicode category. The Worker's
# WHATWG new URL accepts and A-label-encodes the great majority
# of them (each expected return below was checked against Node
# and Bun on the laptop), while the old blanket "any non-ASCII
# P/S/Z" arm refused them all and left
# test_returns_idn_hosts_in_alabel_form red on main.
accepted = {
"http://\U0001f600.com/": "http://xn--e28h.com/", # 😀 So
"http://\u00a9.com/": "http://xn--gba.com/", # © So
"http://\u2603.com/": "http://xn--n3h.com/", # ☃ So
"http://\u20ac.com/": "http://xn--lzg.com/", # € Sc
"http://\u2665.com/": "http://xn--g6h.com/", # ♥ So
"http://\u00a7.com/": "http://xn--eba.com/", # § Po
"http://\u00a2.com/": "http://xn--8a.com/", # ¢ Sc
}
for raw, expected in accepted.items():
self.assertEqual(validate_crawl_url(raw), expected, raw)
# The residual UTS-46-disallowed punctuation / symbol /
# separator codepoints stay refused, and the #588 refusal
# cases (U+00A8 / U+00B4 class, which WHATWG genuinely
# refuses) stay refused too — the alignment is per codepoint,
# not a blanket removal of the check.
for ch in (
"\u00a8", # diaeresis (Sk, #588)
"\u00b4", # acute accent (Sk, #588)
"\u2024", # one dot leader
"\u2025", # two dot leader
"\u2026", # horizontal ellipsis
"\u2488", # digit one full stop
"\u2ff0", # ideographic description character
"\u31ef", # ideographic description character subtraction
"\u33c2", # square am
"\ufffc", # object replacement character
"\ufffd", # replacement character
"\U0001f100", # digit zero full stop
):
self.assertRefused("http://example" + ch + ".com/")

def test_judges_length_and_blocked_names_on_the_mapped_form(self):
# UTS-46 mapping deletes the "ignored" codepoints before any
# judgement, so the length check must measure the mapped form
Expand Down
Loading