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
11 changes: 10 additions & 1 deletion pkgs/lab-ops-hub/container/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,17 @@ def validate_crawl_url(raw):
# host the Worker's parser names. Only a raw backslash is
# structural — a percent-encoded %5C is data and is untouched, as
# are non-http(s) spellings (the scheme check below refuses them).
# The backslash is structural only up to the first "?" or "#": in
# the query and fragment WHATWG keeps it as data, so replacing it
# there would fetch a different query than the Worker fetches for
# the same validated target (#620).
if "\\" in raw and re.match(r"(?i)https?:", raw):
raw = raw.replace("\\", "/")
cut = len(raw)
for delim in "?#":
i = raw.find(delim)
if i != -1:
cut = min(cut, i)
raw = raw[:cut].replace("\\", "/") + raw[cut:]
# WHATWG consumes the whole delimiter run after a special scheme's
# colon — 0, 1, 3 or more slashes name the same host as exactly 2 —
# while urlparse only sees a netloc behind exactly "//", so the
Expand Down
16 changes: 16 additions & 0 deletions pkgs/lab-ops-hub/test/test_container_validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,22 @@ def test_backslash_ends_the_authority_like_whatwg(self):
# is judged and returned exactly as before.
self.assertAccepted("http://example.com/%5c@127.0.0.1/")

def test_backslash_in_query_and_fragment_is_data(self):
# #620: the #577 replacement is structural only up to the first
# "?" or "#" — WHATWG keeps a backslash in the query/fragment
# verbatim, and the Worker fetches it that way.
v = app.validate_crawl_url
self.assertEqual(v(r"http://example.com/?q=a\b"), r"http://example.com/?q=a\b")
self.assertEqual(v(r"http://example.com/#a\b"), r"http://example.com/#a\b")
self.assertEqual(
v(r"https://example.com/?q=a\b\c#x\y"), r"https://example.com/?q=a\b\c#x\y"
)
# Control: a path backslash still normalizes, and an authority
# backslash before a query still ends the authority (#577).
self.assertEqual(v(r"http://example.com/a\b"), "http://example.com/a/b")
with self.assertRaises(ValueError):
v(r"http://127.0.0.1\@example.com/?q=a\b")

def test_redirect_handler_refuses_backslash_loopback_target(self):
# Redirect targets are validated by this validator alone
# (#577): a Location spelling whose WHATWG host is loopback
Expand Down
Loading