Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.7k
gh-87389: Fix an open redirection vulnerability in http.server.#93879
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes from1 commit
Commits
Show all changes
7 commits Select commitHold shift + click to select a range
2f09fe2 gh-87389: Fix an open redirection vulnerability in http.server.
gpshead3b38f52 A more defensive assert within the test.
gpshead19a5bf6 Fix wording in some comments.
gpsheade16d38d Add an explanatory comment in the test.
gpshead25a3a1c Address vstinner comments on the test.
gpshead7c9464a Add a test for absolute Request-URI and fixup to allow it.
gpshead8563d4a Further improve test cases.
gpsheadFile filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
Address vstinner comments on the test.
make the base urls, attack urls, and expected_location more clear in thetest. Adds an additional test for a triple-slash path to ensure we'renot only treating double slashes as special.
- Loading branch information
Uh oh!
There was an error while loading.Please reload this page.
commit25a3a1c4188fb8f50bb7dd07c9ccdb7c9c8a654f
There are no files selected for viewing
17 changes: 12 additions & 5 deletionsLib/test/test_httpservers.py
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -421,25 +421,32 @@ def test_undecodable_filename(self): | ||
| def test_get_dir_redirect_location_domain_injection_bug(self): | ||
| """Ensure //evil.co/..%2f../../X does not put //evil.co/ in Location. | ||
| //netloc/ in a Location header is a redirect to a newhost. | ||
| https://github.com/python/cpython/issues/87389 | ||
| This checks that a path resolving to a directory on our server cannot | ||
| resolve into a redirect to another server. | ||
| """ | ||
| os.mkdir(os.path.join(self.tempdir, 'existing_directory')) | ||
| url = f'/python.org/..%2f..%2f..%2f..%2f..%2f../%0a%0d/../{self.tempdir_name}/existing_directory' | ||
| # Canonicalizes to /tmp/tempdir_name/existing_directory which does | ||
| # exist and is a dir, triggering the 301 redirect and former bug. | ||
| attack_url = f'/{url}' # //python.org... multi-slash prefix, no trailing slash | ||
| expected_location = f'{url}/' # /python.org.../ single slash single prefix, trailing slash | ||
| response = self.request(attack_url) | ||
| self.check_status_and_reason(response, HTTPStatus.MOVED_PERMANENTLY) | ||
| location = response.getheader('Location') | ||
| self.assertFalse(location.startswith('//'), msg=location) | ||
| self.assertEqual(location,expected_location, | ||
| msg='Expected Location header to start with a single / and ' | ||
gpshead marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| 'end with a / as this is a directory redirect.') | ||
gpshead marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| attack3_url = f'//{url}' # ///python.org... triple-slash prefix, no trailing slash | ||
| response = self.request(attack3_url) | ||
| self.check_status_and_reason(response, HTTPStatus.MOVED_PERMANENTLY) | ||
| self.assertEqual(response.getheader('Location'), expected_location) | ||
| def test_get(self): | ||
| #constructs the path relative to the root directory of the HTTPServer | ||
| response = self.request(self.base_url + '/test') | ||
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.