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
43 changes: 43 additions & 0 deletions pkgs/lab-ops-hub/container/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,23 @@ def _judge_a_label(label, host):
f"refusing to crawl host {host}: A-label {label} "
"is not the canonical encoding of its decoded label"
)
# A valid U-label is its own UTS-46 mapped form: the mapping
# validate_crawl_url applies to raw hosts (NFKC, lowercasing,
# ignored-codepoint deletion) must leave the decoded label
# unchanged. The punycode round-trip above cannot see this —
# punycode encodes any string — so a decoded label carrying a
# character UTS-46 maps away (an uppercase letter such as
# U+00C0, a compatibility character such as U+00B2 or the
# fullwidth solidus U+FF0F, a space-class character such as
# U+2000, or an ignored codepoint) passed every check while the
# Worker's WHATWG validator refuses the label outright (#588).
mapped = unicodedata.normalize("NFKC", decoded).lower()
mapped = mapped.translate({cp: None for cp in _UTS46_IGNORED})
if mapped != decoded:
Comment on lines +586 to +588

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve Cherokee uppercase in the A-label mapping check

For A-labels containing Cherokee letters, Python .lower() is not the UTS-46 mapping: UTS-46 preserves uppercase Cherokee, whereas .lower() converts it to the lowercase block. For example, http://xn--ab-y8l.com/ (decoded label aᎠb, containing U+13A0) succeeds in the parent validator and the actual Worker validateCrawlUrl under Bun, but this check now rejects it as not being its UTS-46 mapped form. These valid letter-only domains therefore lose container crawling even if the symbol-category filter is corrected. Use a UTS-46-compatible mapping for this fixed-point check rather than universally requiring lowercase equivalence.

Useful? React with 👍 / 👎.

raise ValueError(
f"refusing to crawl host {host}: A-label {label} "
f"decodes to a label that is not its UTS-46 mapped form {decoded!r}"
)
if any(
ord(c) <= 0x20
or 0x7F <= ord(c) <= 0xA0
Expand Down Expand Up @@ -642,6 +659,32 @@ 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
# 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.
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")
Comment on lines +679 to +680

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve WHATWG-valid symbol and emoji hostnames

For symbol-bearing domains such as http://xn--ls8h.la/ (💩.la), this blanket category filter rejects hosts that the Worker's WHATWG validator accepts. Executing validateCrawlUrl from src/lib.ts under Bun confirms acceptance of that URL and http://xn--example-u17c.com/, while the parent commit's Python validator accepts both and this commit rejects both. Consequently, Worker-approved requests to these domains can no longer use the container crawler and unnecessarily fall back to the Worker. Match the Worker's actual UTS-46 acceptance behavior rather than treating every Unicode symbol or punctuation category as disallowed.

Useful? React with 👍 / 👎.

)
for c in label
):
raise ValueError(
f"refusing to crawl host {host}: label {label!r} "
"contains an IDNA-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):
# A decoded A-label is judged unmapped, so the mapped-dot
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 @@ -886,6 +886,36 @@ def test_refuses_idna_invalid_hosts(self):
self.assertAccepted("http://m\u00fcnchen.de/")
self.assertAccepted("http://ex\u0301ample.com/")

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.
# Mapped-form class (the issue's headline hosts):
self.assertRefused("http://xn--example-yoa.com/") # ex\u00c0ample (uppercase)
self.assertRefused("http://xn--example-rla.com/") # ex\u00b2ample (compatibility digit)
self.assertRefused("http://xn--ab-cja0631x.com/") # a\uff0fb\u00e9 (fullwidth solidus)
self.assertRefused("http://xn--mnchen-3ya5364d.com/") # m\u00fcn\u2000chen (space class)
# DISALLOWED class (survive NFKC, assigned, not format chars):
self.assertRefused("http://xn--example-hja.com/") # ex\u00a8ample (diaeresis, Sk)
self.assertRefused("http://xn--example-7la.com/") # ex\u00b4ample (acute accent, Sk)
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 raw spellings of the DISALLOWED class are refused too
# (the check sits in the shared label judge):
self.assertRefused("http://ex\u00a8ample.com/")
# (No raw U+037E case: NFKC folds it to an ASCII ";" before
# judging, in both validators — only the unmapped decoded
# A-label form above is the #588 divergence.)
# Controls: the PR #584 accepted A-labels and ordinary IDN
# stay accepted, and the CONTEXTO middle dot label is not
# swept up by the punctuation arm.
self.assertAccepted("http://xn--mnchen-3ya.de/") # m\u00fcnchen.de
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)

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