diff --git a/pkgs/lab-ops-hub/container/app.py b/pkgs/lab-ops-hub/container/app.py index 4866f693df..46c57d049b 100644 --- a/pkgs/lab-ops-hub/container/app.py +++ b/pkgs/lab-ops-hub/container/app.py @@ -762,7 +762,7 @@ 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, + # IDNA2008/UTS-46 marks every punctuation, 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 @@ -772,21 +772,36 @@ def _judge_idna_label(label, host): # (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. + # U+00A8, U+00B4 or U+037E passed while the Worker refuses it + # (#588). Category-based, not an enumerated table, so it carries + # no unicodedata version skew of its own. + # The symbol categories are NOT refused wholesale (#8428): the + # Worker judges the WHATWG-parsed host, and WHATWG domainToASCII + # accepts the So/Sc/Sm symbols (U+1F600 -> xn--e28h, U+00A4 -> + # xn--bba, U+00D7 -> xn--rca, U+20AC -> xn--lzg, all verified + # against Node) — #588's premise that the Worker refuses + # currency/math symbols does not hold for the URL-parser path. + # Parity therefore refuses only what WHATWG refuses in this + # family: punctuation and separators as above, and the Sk + # modifier symbols (U+00A8/U+00B4 map to space + combining mark + # under UTS-46 and domainToASCII returns empty for them). + # Accepting So/Sc/Sm is not an SSRF weakening: these labels + # resolve through ordinary public DNS to the same A-label form + # the Worker certifies, and the private/loopback/link-local + # refusals live in the address checks, not in this category rule. if any( ord(c) > 0x7F and ord(c) not in (0x00B7, 0x05F3, 0x05F4, 0x066B, 0x066C, 0x203F, 0x2040) and ( - unicodedata.category(c)[0] in "PSZ" + unicodedata.category(c)[0] in "PZ" + or unicodedata.category(c) == "Sk" 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 an IDNA-disallowed punctuation, separator or modifier-symbol character" ) label = label.translate({0x0345: "ι"}) if any(_maps_to_label_separator(c) for c in label if ord(c) > 0x7F): diff --git a/pkgs/lab-ops-hub/test/test_container_validate.py b/pkgs/lab-ops-hub/test/test_container_validate.py index 7ec4957541..cc7740952d 100644 --- a/pkgs/lab-ops-hub/test/test_container_validate.py +++ b/pkgs/lab-ops-hub/test/test_container_validate.py @@ -1015,8 +1015,12 @@ def test_refuses_idna_invalid_hosts(self): def test_a_label_must_be_its_uts46_mapped_form_and_disallowed_free(self): # #588 residual: a decoded A-label that is not its own UTS-46 # mapped form, or that carries an IDNA-disallowed punctuation / - # symbol / separator character, is refused — the punycode - # round-trip alone certifies all of these. + # separator / modifier-symbol character, is refused — the + # punycode round-trip alone certifies all of these. The Sc + # cases #588 originally listed here (cent sign, euro sign) + # moved to the accepted controls under the #8428 WHATWG + # parity decision: domainToASCII accepts them, so the Worker + # certifies these hosts and the container must too. # Mapped-form class (the issue's headline hosts): self.assertRefused("http://xn--example-yoa.com/") # ex\u00c0ample (uppercase) self.assertRefused( @@ -1038,12 +1042,8 @@ 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( - "http://xn--example-3ha.com/" - ) # ex\u00a2ample (cent sign, Sc) - self.assertRefused( - "http://xn--example-u17c.com/" - ) # ex\u20acample (euro sign, Sc) + # (The cent-sign and euro-sign A-labels that stood here as + # refusals are accepted controls below since #8428.) # The raw spellings of the DISALLOWED class are refused too # (the check sits in the shared label judge): self.assertRefused("http://ex\u00a8ample.com/") @@ -1057,6 +1057,14 @@ def test_a_label_must_be_its_uts46_mapped_form_and_disallowed_free(self): self.assertAccepted("http://xn--bcher-kva.de/") # b\u00fccher.de self.assertAccepted("http://xn--fsq.com/") # \u4f8b.com self.assertAccepted("http://xn--al-0ea.com/") # a\u00b7l (Catalan middle dot) + # #8428 parity controls: Sc symbols are WHATWG-accepted. + self.assertEqual( + validate_crawl_url("http://xn--example-3ha.com/"), + "http://xn--example-3ha.com/", + ) # ex\u00a2ample (cent sign, Sc) + self.assertAccepted( + "http://xn--example-u17c.com/" + ) # ex\u20acample (euro sign, Sc) def test_judges_length_and_blocked_names_on_the_mapped_form(self): # UTS-46 mapping deletes the "ignored" codepoints before any @@ -1463,6 +1471,41 @@ def test_returns_idn_hosts_in_alabel_form(self): for raw, expected in cases.items(): self.assertEqual(validate_crawl_url(raw), expected, raw) + def test_symbol_hosts_match_whatwg_parity(self): + # #8428: the #588 category check refused every P/S/Z-category + # character, but the Worker judges the WHATWG-parsed host and + # domainToASCII ACCEPTS the So/Sc/Sm symbols — the two copies + # disagreed and this suite failed on clean main. Parity rule: + # So/Sc/Sm accepted (values below are Node domainToASCII + # returns, re-verified with the fix); Sk modifier symbols and + # punctuation/separators stay refused, in raw form (they map + # to space + combining mark under UTS-46) and as decoded + # A-labels (judged unmapped by _judge_a_label). + accepted = { + "http://\U0001F600.com/": "http://xn--e28h.com/", + "http://\u00A4.com/": "http://xn--bba.com/", + "http://\u00D7.com/": "http://xn--rca.com/", + "http://\u20AC.com/": "http://xn--lzg.com/", + "http://a\U0001F600b.com/": "http://xn--ab-no82a.com/", + "http://xn--e28h.com/": "http://xn--e28h.com/", + } + for raw, expected in accepted.items(): + self.assertEqual(validate_crawl_url(raw), expected, raw) + refused = [ + # Raw Sk / Po spellings (U+00A8, U+00B4, U+203E). + "http://\u00A8.com/", + "http://\u00B4.com/", + "http://\u203E.com/", + # A-labels decoding to U+00A8, U+00B4, U+203E, U+037E. + "http://xn--fba.com/", + "http://xn--rba.com/", + "http://xn--gwg.com/", + "http://xn--5va.com/", + ] + for raw in refused: + with self.assertRaises(ValueError, msg=raw): + validate_crawl_url(raw) + def test_returns_alabel_derived_from_original_spelling(self): # Codex review of PR #3781: deriving the returned A-label # from the NFKC-mapped judged label changes the DOMAIN for