Repository navigation
fix(tools): apply the fetch_url checks to redirect targets - #728
Merged
Merged
Conversation
fetch_url checked only the first URL. A redirect could then send the request to a private host or to a URL that is not HTTPS. Check each redirect target with the same rules.
omkargaikwad23
requested review from
IsmailMehdi,
helloeve and
prernakakkar-google
as code owners
November 20, 2026 07:47
Collaborator
Author
|
/gcbrun |
wangauone
approved these changes
Nov 20, 2026
Collaborator
Author
|
/gcbrun |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this fixes
The
fetch_urljudge tool checks the URL before the request: HTTPS only, and no private, loopback, or link-local host. It did not check redirect targets. A server could answer with a redirect to a URL that these checks refuse.How
_url_error._url_errorto each redirect target. A refused redirect stops the request, andfetch_urlreturns an error string.Not in this PR
The host check and the connection still resolve the host name separately, so a change of the DNS answer between the two is not covered.
Testing
tools_fetch_url_test.pyfor the redirect handler. One test runs the real opener against a local server and confirms that the second request is not sent.pytest evalbench/testwithSKIP_CLOUD_TESTS=true: 1269 passed, 11 skipped.