summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2014-06-15 01:36:29 (GMT)
committerBenjamin Peterson <benjamin@python.org>2014-06-15 01:36:29 (GMT)
commit8d24d77c63bdbf25d68bf0a6cad408d06abf2d00 (patch)
tree31f600e2a4e6d8d72191552d2a09f411604655d3
parentce817cb36d7e8764b5ddecadea4b02276879d631 (diff)
downloadcpython-8d24d77c63bdbf25d68bf0a6cad408d06abf2d00.zip
cpython-8d24d77c63bdbf25d68bf0a6cad408d06abf2d00.tar.gz
cpython-8d24d77c63bdbf25d68bf0a6cad408d06abf2d00.tar.bz2
url unquote the path before checking if it refers to a CGI script (closes #21766)
-rw-r--r--Lib/CGIHTTPServer.py2
-rw-r--r--Lib/test/test_httpservers.py5
-rw-r--r--Misc/NEWS3
3 files changed, 9 insertions, 1 deletions
diff --git a/Lib/CGIHTTPServer.py b/Lib/CGIHTTPServer.py
index 50e0f7a..2acf913 100644
--- a/Lib/CGIHTTPServer.py
+++ b/Lib/CGIHTTPServer.py
@@ -84,7 +84,7 @@ class CGIHTTPRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
path begins with one of the strings in self.cgi_directories
(and the next character is a '/' or the end of the string).
"""
- collapsed_path = _url_collapse_path(self.path)
+ collapsed_path = _url_collapse_path(urllib.unquote(self.path))
dir_sep = collapsed_path.find('/', 1)
head, tail = collapsed_path[:dir_sep], collapsed_path[dir_sep+1:]
if head in self.cgi_directories:
diff --git a/Lib/test/test_httpservers.py b/Lib/test/test_httpservers.py
index 2390c70..6a23bb2 100644
--- a/Lib/test/test_httpservers.py
+++ b/Lib/test/test_httpservers.py
@@ -510,6 +510,11 @@ class CGIHTTPServerTestCase(BaseTestCase):
(res.read(), res.getheader('Content-type'), res.status))
self.assertEqual(os.environ['SERVER_SOFTWARE'], signature)
+ def test_urlquote_decoding_in_cgi_check(self):
+ res = self.request('/cgi-bin%2ffile1.py')
+ self.assertEqual((b'Hello World\n', 'text/html', 200),
+ (res.read(), res.getheader('Content-type'), res.status))
+
class SimpleHTTPRequestHandlerTestCase(unittest.TestCase):
""" Test url parsing """
diff --git a/Misc/NEWS b/Misc/NEWS
index b09bd84..310d237 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -25,6 +25,9 @@ Core and Builtins
Library
-------
+- Issue #21766: Prevent a security hole in CGIHTTPServer by URL unquoting paths
+ before checking for a CGI script at that path.
+
- Issue #21310: Fixed possible resource leak in failed open().
- Issue #21304: Backport the key derivation function hashlib.pbkdf2_hmac from