Repository navigation
lab-ops-hub: judge slash-run authority spellings by the WHATWG host (#586) #587
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -75,6 +75,18 @@ def validate_crawl_url(raw): | |
| # are non-http(s) spellings (the scheme check below refuses them). | ||
| if "\\" in raw and re.match(r"(?i)https?:", raw): | ||
| raw = raw.replace("\\", "/") | ||
| # 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 | ||
| # other run lengths parse as hostless and were refused as "url has | ||
| # no host" even for public targets the Worker accepts and | ||
| # normalizes (#586). Collapse the run to exactly "//" before | ||
| # parsing and judge (and return) the normalized spelling, as with | ||
| # the backslash normalization above. Blocked hosts in these | ||
| # spellings are then refused by the ordinary checks below, for the | ||
| # right reason. | ||
| if re.match(r"(?i)https?:", raw): | ||
| raw = re.sub(r"(?i)^(https?:)/*", r"\g<1>//", raw) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
For inputs containing WHATWG-ignored tab, CR, or LF characters in the delimiter run, such as Useful? React with 👍 / 👎. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When this line newly admits a spelling such as Useful? React with 👍 / 👎. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
For a direct input such as Useful? React with 👍 / 👎. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
For a direct input such as Useful? React with 👍 / 👎. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When a direct caller supplies Useful? React with 👍 / 👎. |
||
| u = urlparse(raw) | ||
| if u.scheme not in ("http", "https"): | ||
| raise ValueError("only http: and https: URLs may be crawled") | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When an actual response contains
Location: http:///127.0.0.1/admin,HTTPRedirectHandler.http_error_302callsurljoin(req.full_url, newurl)before_ValidatingRedirectHandler.redirect_request, so this line receiveshttp://example.com/127.0.0.1/adminand never sees or rejects the WHATWG loopback target. The added test invokesredirect_requestdirectly and therefore misses the real flow; intercept and validate the raw Location before stdlib resolution, otherwise slash-run redirects continue to be followed on the wrong host.Useful? React with 👍 / 👎.