Repository navigation
2.7.18.16: SimpleHTTPServer // open redirect (CVE-2021-28861) - #97
Merged
Merged
Conversation
CVE-2021-28861) Backport of python/cpython pythongh-87389 (pythonGH-93879, 4dc2cae) to 2.7.18.x. A request path starting with "//" that resolves to a directory made SimpleHTTPRequestHandler.send_head() answer with a 301 whose Location header also started with "//". Browsers treat "//host/path" as a scheme-relative URL, so a crafted link to the server redirected the user to an attacker-chosen host. BaseHTTPRequestHandler.parse_request() now reduces a leading run of slashes in the path to a single "/". Verified on 2.7.18.15: the "//python.org/..." request answers "Location: //python.org/..."; with this change it is "/python.org/...". 2.7.18.x: the fix lands in BaseHTTPServer.parse_request(); the test uses string concatenation and the literal 301 status instead of f-strings and HTTPStatus. Co-Authored-By: Claude Opus 5.5 <[email protected]>
ezequielp-activestate
approved these changes
Oct 28, 2026
ezequielp-activestate
left a comment
There was a problem hiding this comment.
No blockers.
-
Fix matches upstream. The leading-slash collapse in
parse_request()is upstream pythongh-87389 (4abab6b). No later upstream fix changes it. -
Repro (
SimpleHTTPRequestHandler, serving a directory withexisting_directory/):request path base Locationthis branch Location//python.org/..%2f..%2f..%2f..%2f..%2f../%0a%0d/../existing_directory//python.org/…/python.org/…////evil.com/..%2f../existing_directory//evil.com/…/evil.com/…/existing_directory/existing_directory/unchanged -
Tests:
test_httpserverspasses. -
FYI, not for this PR:
/\evil.com/..%2f../existing_directorystill redirects toLocation: /\evil.com/..%2f../existing_directory/, which browsers read as//evil.com/…. Upstream 3.14 does exactly the same, so this isn't a gap in the backport.
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.
Backport of python/cpython pythongh-87389 (CVE-2021-28861, PSF-2022-5) to 2.7.18.x. This fix was released after Python 2.7's end of life.
Problem: if a request path starts with
//and resolves to a directory,SimpleHTTPRequestHandleranswers with a 301 whoseLocationalso starts with//. Browsers treat//host/pathas a URL to another host, so a crafted link to the server can redirect users anywhere.Fix:
BaseHTTPRequestHandler.parse_request()now collapses any leading run of slashes in the path to a single/.Test:
test_get_dir_redirect_location_domain_injection_bug, adapted from upstream with string formatting and the literal 301.Location: //python.org/..%2f…/existing_directory/.test_httpserverspasses 41/41.Part of 2.7.18.16. It targets the
2.7.18.16integration branch.