- Add patch CVE-2021-28861-double-slash-path.patch:

* BaseHTTPServer: Fix an open redirection vulnerability in the HTTP server
    when an URI path starts with //. (bsc#1202624, CVE-2021-28861)

OBS-URL: https://build.opensuse.org/package/show/devel:languages:python:Factory/python?expand=0&rev=330
This commit is contained in:
Steve Kowalik 2022-09-07 04:48:27 +00:00 committed by Git OBS Bridge
parent 9a59733bbe
commit de85457a6c
7 changed files with 109 additions and 0 deletions

View File

@ -0,0 +1,76 @@
Index: Python-2.7.18/Lib/BaseHTTPServer.py
===================================================================
--- Python-2.7.18.orig/Lib/BaseHTTPServer.py
+++ Python-2.7.18/Lib/BaseHTTPServer.py
@@ -287,6 +287,14 @@ class BaseHTTPRequestHandler(SocketServe
return False
self.command, self.path, self.request_version = command, path, version
+ # CVE-2021-28861: 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
self.headers = self.MessageClass(self.rfile, 0)
Index: Python-2.7.18/Lib/test/test_httpservers.py
===================================================================
--- Python-2.7.18.orig/Lib/test/test_httpservers.py
+++ Python-2.7.18/Lib/test/test_httpservers.py
@@ -417,6 +417,52 @@ class SimpleHTTPServerTestCase(BaseTestC
self.assertEqual(response.getheader("Location"),
self.tempdir_name + "/?hi=1")
+ 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)
+
cgi_file1 = """\
#!%s

View File

@ -1,3 +1,10 @@
-------------------------------------------------------------------
Wed Sep 7 04:46:44 UTC 2022 - Steve Kowalik <steven.kowalik@suse.com>
- Add patch CVE-2021-28861-double-slash-path.patch:
* BaseHTTPServer: Fix an open redirection vulnerability in the HTTP server
when an URI path starts with //. (bsc#1202624, CVE-2021-28861)
------------------------------------------------------------------- -------------------------------------------------------------------
Thu Jun 9 16:43:30 UTC 2022 - Matej Cepl <mcepl@suse.com> Thu Jun 9 16:43:30 UTC 2022 - Matej Cepl <mcepl@suse.com>

View File

@ -130,6 +130,9 @@ Patch69: CVE-2022-0391-urllib_parse-newline-parsing.patch
# PATCH-FIX-UPSTREAM CVE-2015-20107-mailcap-unsafe-filenames.patch bsc#1198511 mcepl@suse.com # PATCH-FIX-UPSTREAM CVE-2015-20107-mailcap-unsafe-filenames.patch bsc#1198511 mcepl@suse.com
# avoid the command injection in the mailcap module. # avoid the command injection in the mailcap module.
Patch70: CVE-2015-20107-mailcap-unsafe-filenames.patch Patch70: CVE-2015-20107-mailcap-unsafe-filenames.patch
# PATCH-FIX-UPSTREAM CVE-2021-28861 bsc#1202624
# Coerce // to / in Lib/BaseHTTPServer.py
Patch71: CVE-2021-28861-double-slash-path.patch
# COMMON-PATCH-END # COMMON-PATCH-END
%define python_version %(echo %{tarversion} | head -c 3) %define python_version %(echo %{tarversion} | head -c 3)
BuildRequires: automake BuildRequires: automake
@ -266,6 +269,7 @@ other applications.
%patch68 -p1 %patch68 -p1
%patch69 -p1 %patch69 -p1
%patch70 -p1 %patch70 -p1
%patch71 -p1
# For patch 66 # For patch 66
cp -v %{SOURCE66} Lib/test/recursion.tar cp -v %{SOURCE66} Lib/test/recursion.tar

View File

@ -1,3 +1,10 @@
-------------------------------------------------------------------
Wed Sep 7 04:46:44 UTC 2022 - Steve Kowalik <steven.kowalik@suse.com>
- Add patch CVE-2021-28861-double-slash-path.patch:
* BaseHTTPServer: Fix an open redirection vulnerability in the HTTP server
when an URI path starts with //. (bsc#1202624, CVE-2021-28861)
------------------------------------------------------------------- -------------------------------------------------------------------
Thu Jun 9 16:43:30 UTC 2022 - Matej Cepl <mcepl@suse.com> Thu Jun 9 16:43:30 UTC 2022 - Matej Cepl <mcepl@suse.com>

View File

@ -129,6 +129,9 @@ Patch69: CVE-2022-0391-urllib_parse-newline-parsing.patch
# PATCH-FIX-UPSTREAM CVE-2015-20107-mailcap-unsafe-filenames.patch bsc#1198511 mcepl@suse.com # PATCH-FIX-UPSTREAM CVE-2015-20107-mailcap-unsafe-filenames.patch bsc#1198511 mcepl@suse.com
# avoid the command injection in the mailcap module. # avoid the command injection in the mailcap module.
Patch70: CVE-2015-20107-mailcap-unsafe-filenames.patch Patch70: CVE-2015-20107-mailcap-unsafe-filenames.patch
# PATCH-FIX-UPSTREAM CVE-2021-28861 bsc#1202624
# Coerce // to / in Lib/BaseHTTPServer.py
Patch71: CVE-2021-28861-double-slash-path.patch
# COMMON-PATCH-END # COMMON-PATCH-END
Provides: pyth_doc = %{version} Provides: pyth_doc = %{version}
Provides: pyth_ps = %{version} Provides: pyth_ps = %{version}
@ -203,6 +206,7 @@ Python, and Macintosh Module Reference in PDF format.
%patch68 -p1 %patch68 -p1
%patch69 -p1 %patch69 -p1
%patch70 -p1 %patch70 -p1
%patch71 -p1
# For patch 66 # For patch 66
cp -v %{SOURCE66} Lib/test/recursion.tar cp -v %{SOURCE66} Lib/test/recursion.tar

View File

@ -1,3 +1,10 @@
-------------------------------------------------------------------
Wed Sep 7 04:46:44 UTC 2022 - Steve Kowalik <steven.kowalik@suse.com>
- Add patch CVE-2021-28861-double-slash-path.patch:
* BaseHTTPServer: Fix an open redirection vulnerability in the HTTP server
when an URI path starts with //. (bsc#1202624, CVE-2021-28861)
------------------------------------------------------------------- -------------------------------------------------------------------
Thu Jun 9 16:43:30 UTC 2022 - Matej Cepl <mcepl@suse.com> Thu Jun 9 16:43:30 UTC 2022 - Matej Cepl <mcepl@suse.com>

View File

@ -129,6 +129,9 @@ Patch69: CVE-2022-0391-urllib_parse-newline-parsing.patch
# PATCH-FIX-UPSTREAM CVE-2015-20107-mailcap-unsafe-filenames.patch bsc#1198511 mcepl@suse.com # PATCH-FIX-UPSTREAM CVE-2015-20107-mailcap-unsafe-filenames.patch bsc#1198511 mcepl@suse.com
# avoid the command injection in the mailcap module. # avoid the command injection in the mailcap module.
Patch70: CVE-2015-20107-mailcap-unsafe-filenames.patch Patch70: CVE-2015-20107-mailcap-unsafe-filenames.patch
# PATCH-FIX-UPSTREAM CVE-2021-28861 bsc#1202624
# Coerce // to / in Lib/BaseHTTPServer.py
Patch71: CVE-2021-28861-double-slash-path.patch
# COMMON-PATCH-END # COMMON-PATCH-END
BuildRequires: automake BuildRequires: automake
BuildRequires: db-devel BuildRequires: db-devel
@ -319,6 +322,7 @@ that rely on earlier non-verification behavior.
%patch68 -p1 %patch68 -p1
%patch69 -p1 %patch69 -p1
%patch70 -p1 %patch70 -p1
%patch71 -p1
# For patch 66 # For patch 66
cp -v %{SOURCE66} Lib/test/recursion.tar cp -v %{SOURCE66} Lib/test/recursion.tar