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
8 changes: 8 additions & 0 deletions pkgs/lab-ops-hub/container/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ def validate_crawl_url(raw):
host = host[:-1]
if not host:
raise ValueError("url has no host")
# A raw % in the host is a percent-encoded spelling (or an IPv6 zone
# id): WHATWG URL parsing percent-decodes the host before judging it
# — %6cocalhost is localhost — and rejects the rest outright, while
# urlparse hands the spelling through verbatim and the checks below
# would mistake it for a public DNS name (or ipaddress would accept
# the zone id). Refuse every % host, fail-closed (#505).
if "%" in host:
raise ValueError(f"refusing to crawl percent-encoded host {host}")
if host == "localhost" or host.endswith(_BLOCKED_SUFFIXES):
raise ValueError(f"refusing to crawl local host {host}")
try:
Expand Down
19 changes: 19 additions & 0 deletions pkgs/lab-ops-hub/test/test_container_validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,25 @@ def test_refuses_malformed_or_out_of_range_ports(self):
):
self.assertRefused(url)

def test_refuses_percent_encoded_hosts_and_zone_ids(self):
# WHATWG URL parsing percent-decodes the host before judging it
# (%6cocalhost is localhost) and rejects the other % spellings
# outright; urlparse passes them through verbatim and the old
# code mistook them for public DNS names, while ipaddress
# accepted the IPv6 zone id (#505).
for url in (
"http://%6cocalhost/",
"http://localhost%00/",
"http://127.0.0.1%09/",
"http://8.8.8.8%09/",
"http://8.8.8.8%zz/",
"http://example.com%09/",
"http://example.com%/", # malformed: bare %
"http://example.com%2/", # malformed: truncated escape
"https://[2001:4860:4860::8888%25eth0]/", # IPv6 zone id
):
self.assertRefused(url)

def test_accepts_public_targets(self):
for url in (
"https://example.com/page",
Expand Down
Loading