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
14 changes: 12 additions & 2 deletions pkgs/lab-ops-hub/container/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -470,8 +470,18 @@ def _judge_idna_label(label, host):
# interpreter's unicodedata is 15.0.0, so a few dozen codepoints
# assigned in later Unicode versions read as Cn here while the
# Worker's newer tables accept them (the same version skew PR
# #584 accepted for A-labels), and U+0345, which UTS-46 maps to
# a letter, reads as a leading mark here.
# #584 accepted for A-labels).
# UTS-46 mapping is not NFKC: U+0345 (combining Greek
# ypogegrammeni) maps to U+03B9 (ι, bidi class L), but NFKC
# leaves it unchanged (the mapping lives in the special-casing
# data), so the mapped host validate_crawl_url hands over still
# carries it as a combining mark (bidi NSM), legal mid-label in
# any context. Judge the UTS-46-mapped form: inside an RTL
# label the mapped letter makes the label R + L + R, a bidi
# violation the Worker refuses, while at label start the mapped
# letter is an ordinary first character, closing the former
# leading-mark over-refusal (#596).
label = label.translate({0x0345: "ι"})

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 Do not remap decoded A-label payloads

_judge_idna_label also receives the decoded payload of xn-- labels, but UTS-46 mapping applies to raw U-label input, not after A-label decoding. Consequently, invalid A-labels such as xn--jua (decoding to U+0345) and xn--abc-blc (decoding to U+0345abc) are now translated to valid labels and accepted by the container, while Bun/WHATWG rejects both. Keep decoded A-labels on the unmapped validation path so redirects and initial requests cannot pass container validation with a hostname the Worker rejects.

Useful? React with 👍 / 👎.

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 Apply U+0345 mapping before enforcing the hostname limit

Because this translation happens only inside the per-label validator, the earlier whole-host length check still measures the unmapped punycode. For example, four labels consisting of U+0345 followed by 54 Greek alphas encode to 251 characters before this mapping but 255 afterward; the container now accepts that raw host because every mapped label is individually 63 characters, whereas the Worker's explicit 253-character guard rejects its canonical hostname. Map the raw host before computing encoded_labels, or recheck the mapped total, so an overlong redirect target is not accepted and passed to the resolver.

Useful? React with 👍 / 👎.

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
# refusal in validate_crawl_url never sees this form.
Expand Down
19 changes: 19 additions & 0 deletions pkgs/lab-ops-hub/test/lib.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,25 @@ test("validateCrawlUrl judges Arabic-Indic digits by their bidi context (#605)",
assert.equal(validateCrawlUrl("http://xn--4db40a.com/").ok, true);
});

test("validateCrawlUrl judges U+0345 by its UTS-46 mapping (#596)", () => {
// UTS-46 maps U+0345 (combining Greek ypogegrammeni) to U+03B9
// (ι, bidi class L): inside an RTL label the mapped form mixes
// L with R and is refused. The container validator judged the
// unmapped mark (bidi NSM) and certified these hosts; it now
// pins the same verdicts (#596).
assert.equal(validateCrawlUrl("http://\u05d0\u0345\u05d0.com/").ok, false);
assert.equal(validateCrawlUrl("http://\u05d0\u0345.com/").ok, false);
// (The A-label spelling xn--jua51kba is refused under Bun but
// accepted by Node's URL parser, so it is pinned only in the
// container suite.)
// Controls: LTR/Greek contexts and the label-start spelling
// (U+0345 maps to a letter, so the label starts with one) stay
// accepted.
assert.equal(validateCrawlUrl("http://ex\u0345ample.com/").ok, true);
assert.equal(validateCrawlUrl("http://\u03b1\u0345.com/").ok, true);
assert.equal(validateCrawlUrl("http://\u0345abc.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
20 changes: 20 additions & 0 deletions pkgs/lab-ops-hub/test/test_container_validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,26 @@ def test_accepts_arabic_indic_digits_inside_rtl_labels(self):
self.assertRefused("http://\u05d0\u06611.com/")
self.assertRefused("http://\u0661\u0627.com/")

def test_judges_u0345_by_its_uts46_mapping(self):
# UTS-46 maps U+0345 (combining Greek ypogegrammeni) to
# U+03B9 (ι, bidi class L), but NFKC leaves it unchanged, so
# the container judged it as a combining mark (bidi NSM) —
# legal mid-label anywhere — while the Worker judges the
# mapped letter: inside an RTL label the mapped form is
# R + L + R, a bidi violation (#596).
self.assertRefused("http://\u05d0\u0345\u05d0.com/")
self.assertRefused("http://\u05d0\u0345.com/")
# The A-label spelling of the first host is refused too.
self.assertRefused("http://xn--jua51kba.com/")
# Controls: in LTR/Greek contexts the mapped letter is an
# ordinary character and the hosts stay accepted.
self.assertAccepted("http://ex\u0345ample.com/")
self.assertAccepted("http://\u03b1\u0345.com/")
# Pin: at label start the mapping closes the former
# leading-mark over-refusal — U+0345 maps to a letter, so
# the label starts with one, matching the Worker (#596).
self.assertAccepted("http://\u0345abc.com/")

def test_refuses_idna_invalid_hosts(self):
# A label can punycode-encode without being a valid IDNA
# label at all: the mapped host was never IDNA-validated, so
Expand Down
Loading