8000 url unquote the path before checking if it refers to a CGI script (cl… · python/cpython@73b8b1c · GitHub
[go: up one dir, main page]

Skip to content

Commit 73b8b1c

Browse files
committed
url unquote the path before checking if it refers to a CGI script (closes #21766)
1 parent 49991de commit 73b8b1c

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

Lib/http/server.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -946,7 +946,7 @@ def is_cgi(self):
946946
(and the next character is a '/' or the end of the string).
947947
948948
"""
949-
collapsed_path = _url_collapse_path(self.path)
949+
collapsed_path = _url_collapse_path(urllib.parse.unquote(self.path))
950950
dir_sep = collapsed_path.find('/', 1)
951951
head, tail = collapsed_path[:dir_sep], collapsed_path[dir_sep+1:]
952952
if head in self.cgi_directories:

Lib/test/test_httpservers.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,11 @@ def test_os_environ_is_not_altered(self):
461461
(res.read(), res.getheader('Content-type'), res.status))
462462
self.assertEqual(os.environ['SERVER_SOFTWARE'], signature)
463463

464+
def test_urlquote_decoding_in_cgi_check(self):
465+
res = self.request('/cgi-bin%2ffile1.py')
466+
self.assertEqual((b'Hello World\n', 'text/html', 200),
467+
(res.read(), res.getheader('Content-type'), res.status))
468+
464469

465470
class SocketlessRequestHandler(SimpleHTTPRequestHandler):
466471
def __init__(self):

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ What's New in Python 3.2.6?
1010
Library
1111
-------
1212

13+
- Issue #21766: Prevent a security hole in CGIHTTPServer by URL unquoting paths
14+
before checking for a CGI script at that path.
15+
1316
- Fix arbitrary memory access in JSONDecoder.raw_decode with a negative second
1417
parameter. Bug reported by Guido Vranken.
1518

0 commit comments

Comments
 (0)
0