Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
SUSE:SLE-12-SP1:GA
python3-doc.30641
CVE-2021-28861-double-slash-path.patch
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File CVE-2021-28861-double-slash-path.patch of Package python3-doc.30641
From d01648738934922d413b65f2f97951cbab66e0bd Mon Sep 17 00:00:00 2001 From: "Gregory P. Smith" <greg@krypto.org> Date: Tue, 21 Jun 2022 13:16:57 -0700 Subject: [PATCH] gh-87389: Fix an open redirection vulnerability in http.server. (GH-93879) Fix an open redirection vulnerability in the `http.server` module when an URI path starts with `//` that could produce a 301 Location header with a misleading target. Vulnerability discovered, and logic fix proposed, by Hamza Avvan (@hamzaavvan). Test and comments authored by Gregory P. Smith [Google]. (cherry picked from commit 4abab6b603dd38bec1168e9a37c40a48ec89508e) Co-authored-by: Gregory P. Smith <greg@krypto.org> --- Lib/http/server.py | 7 +++ Lib/test/test_httpservers.py | 53 ++++++++++++++++++- ...2-06-15-20-09-23.gh-issue-87389.QVaC3f.rst | 3 ++ 3 files changed, 61 insertions(+), 2 deletions(-) create mode 100644 Misc/NEWS.d/next/Security/2022-06-15-20-09-23.gh-issue-87389.QVaC3f.rst Index: Python-3.4.10/Lib/http/server.py =================================================================== --- Python-3.4.10.orig/Lib/http/server.py +++ Python-3.4.10/Lib/http/server.py @@ -318,6 +318,13 @@ class BaseHTTPRequestHandler(socketserve return False self.command, self.path, self.request_version = command, path, version + # gh-87389: The purpose of replacing '//' with '/' is to protect + # against open redirect attacks possibly triggered if the path starts + # with '//' because http clients treat //path as an absolute URI + # without scheme (similar to http://path) rather than a path. + if self.path.startswith('//'): + self.path = '/' + self.path.lstrip('/') # Reduce to a single / + # Examine the headers and look for a Connection directive. try: self.headers = http.client.parse_headers(self.rfile, Index: Python-3.4.10/Lib/test/test_httpservers.py =================================================================== --- Python-3.4.10.orig/Lib/test/test_httpservers.py +++ Python-3.4.10/Lib/test/test_httpservers.py @@ -241,7 +241,7 @@ class SimpleHTTPServerTestCase(BaseTestC pass def setUp(self): - BaseTestCase.setUp(self) + super().setUp() self.cwd = os.getcwd() basetempdir = tempfile.gettempdir() os.chdir(basetempdir) @@ -259,7 +259,7 @@ class SimpleHTTPServerTestCase(BaseTestC except: pass finally: - BaseTestCase.tearDown(self) + super().tearDown() def check_status_and_reason(self, response, status, data=None): body = response.read() @@ -296,6 +296,55 @@ class SimpleHTTPServerTestCase(BaseTestC self.check_status_and_reason(response, 200, data=support.TESTFN_UNDECODABLE) + 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 new host. + 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 = '/python.org/..%2f..%2f..%2f..%2f..%2f../%0a%0d/../' + self.tempdir_name + '/existing_directory' + expected_location = url + '/' # /python.org.../ single slash single prefix, trailing slash + # Canonicalizes to /tmp/tempdir_name/existing_directory which does + # exist and is a dir, triggering the 301 redirect logic. + response = self.request(url) + self.check_status_and_reason(response, 301) + location = response.getheader('Location') + self.assertEqual(location, expected_location, msg='non-attack failed!') + + # //python.org... multi-slash prefix, no trailing slash + attack_url = '/' + url + response = self.request(attack_url) + self.check_status_and_reason(response, 301) + 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 ' + 'end with a / as this is a directory redirect.') + + # ///python.org... triple-slash prefix, no trailing slash + attack3_url = '//' + url + response = self.request(attack3_url) + self.check_status_and_reason(response, 301) + self.assertEqual(response.getheader('Location'), expected_location) + + # If the second word in the http request (Request-URI for the http + # method) is a full URI, we don't worry about it, as that'll be parsed + # and reassembled as a full URI within BaseHTTPRequestHandler.send_head + # so no errant scheme-less //netloc//evil.co/ domain mixup can happen. + attack_scheme_netloc_2slash_url = 'https://pypi.org/' + url + expected_scheme_netloc_location = attack_scheme_netloc_2slash_url + '/' + response = self.request(attack_scheme_netloc_2slash_url) + self.check_status_and_reason(response, 301) + location = response.getheader('Location') + # We're just ensuring that the scheme and domain make it through, if + # there are or aren't multiple slashes at the start of the path that + # follows that isn't important in this Location: header. + self.assertTrue(location.startswith('https://pypi.org/'), msg=location) + def test_get(self): #constructs the path relative to the root directory of the HTTPServer response = self.request(self.tempdir_name + '/test')
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor