Kaydet (Commit) c8937629 authored tarafından Ned Deily's avatar Ned Deily

Issue #21323: Fix CGIHTTPServer to again handle scripts in CGI subdirectories,

broken by the fix for security issue #19435.  Patch by Zach Byrne.
üst f2892879
...@@ -106,16 +106,16 @@ class CGIHTTPRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler): ...@@ -106,16 +106,16 @@ class CGIHTTPRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
def run_cgi(self): def run_cgi(self):
"""Execute a CGI script.""" """Execute a CGI script."""
dir, rest = self.cgi_info dir, rest = self.cgi_info
path = dir + '/' + rest
i = rest.find('/') i = path.find('/', len(dir)+1)
while i >= 0: while i >= 0:
nextdir = rest[:i] nextdir = path[:i]
nextrest = rest[i+1:] nextrest = path[i+1:]
scriptdir = self.translate_path(nextdir) scriptdir = self.translate_path(nextdir)
if os.path.isdir(scriptdir): if os.path.isdir(scriptdir):
dir, rest = nextdir, nextrest dir, rest = nextdir, nextrest
i = rest.find('/') i = path.find('/', len(dir)+1)
else: else:
break break
......
...@@ -386,7 +386,9 @@ class CGIHTTPServerTestCase(BaseTestCase): ...@@ -386,7 +386,9 @@ class CGIHTTPServerTestCase(BaseTestCase):
BaseTestCase.setUp(self) BaseTestCase.setUp(self)
self.parent_dir = tempfile.mkdtemp() self.parent_dir = tempfile.mkdtemp()
self.cgi_dir = os.path.join(self.parent_dir, 'cgi-bin') self.cgi_dir = os.path.join(self.parent_dir, 'cgi-bin')
self.cgi_child_dir = os.path.join(self.cgi_dir, 'child-dir')
os.mkdir(self.cgi_dir) os.mkdir(self.cgi_dir)
os.mkdir(self.cgi_child_dir)
# The shebang line should be pure ASCII: use symlink if possible. # The shebang line should be pure ASCII: use symlink if possible.
# See issue #7668. # See issue #7668.
...@@ -411,6 +413,11 @@ class CGIHTTPServerTestCase(BaseTestCase): ...@@ -411,6 +413,11 @@ class CGIHTTPServerTestCase(BaseTestCase):
file2.write(cgi_file2 % self.pythonexe) file2.write(cgi_file2 % self.pythonexe)
os.chmod(self.file2_path, 0777) os.chmod(self.file2_path, 0777)
self.file3_path = os.path.join(self.cgi_child_dir, 'file3.py')
with open(self.file3_path, 'w') as file3:
file3.write(cgi_file1 % self.pythonexe)
os.chmod(self.file3_path, 0777)
self.cwd = os.getcwd() self.cwd = os.getcwd()
os.chdir(self.parent_dir) os.chdir(self.parent_dir)
...@@ -422,6 +429,8 @@ class CGIHTTPServerTestCase(BaseTestCase): ...@@ -422,6 +429,8 @@ class CGIHTTPServerTestCase(BaseTestCase):
os.remove(self.nocgi_path) os.remove(self.nocgi_path)
os.remove(self.file1_path) os.remove(self.file1_path)
os.remove(self.file2_path) os.remove(self.file2_path)
os.remove(self.file3_path)
os.rmdir(self.cgi_child_dir)
os.rmdir(self.cgi_dir) os.rmdir(self.cgi_dir)
os.rmdir(self.parent_dir) os.rmdir(self.parent_dir)
finally: finally:
...@@ -516,6 +525,11 @@ class CGIHTTPServerTestCase(BaseTestCase): ...@@ -516,6 +525,11 @@ class CGIHTTPServerTestCase(BaseTestCase):
self.assertEqual((b'Hello World\n', 'text/html', 200), self.assertEqual((b'Hello World\n', 'text/html', 200),
(res.read(), res.getheader('Content-type'), res.status)) (res.read(), res.getheader('Content-type'), res.status))
def test_nested_cgi_path_issue21323(self):
res = self.request('/cgi-bin/child-dir/file3.py')
self.assertEqual((b'Hello World\n', 'text/html', 200),
(res.read(), res.getheader('Content-type'), res.status))
class SimpleHTTPRequestHandlerTestCase(unittest.TestCase): class SimpleHTTPRequestHandlerTestCase(unittest.TestCase):
""" Test url parsing """ """ Test url parsing """
......
...@@ -198,6 +198,7 @@ Tarn Weisner Burton ...@@ -198,6 +198,7 @@ Tarn Weisner Burton
Lee Busby Lee Busby
Katherine Busch Katherine Busch
Ralph Butler Ralph Butler
Zach Byrne
Nicolas Cadou Nicolas Cadou
Jp Calderone Jp Calderone
Arnaud Calmettes Arnaud Calmettes
......
...@@ -25,6 +25,9 @@ Library ...@@ -25,6 +25,9 @@ Library
- Issue #21923: Prevent AttributeError in distutils.sysconfig.customize_compiler - Issue #21923: Prevent AttributeError in distutils.sysconfig.customize_compiler
due to possible uninitialized _config_vars. due to possible uninitialized _config_vars.
- Issue #21323: Fix CGIHTTPServer to again handle scripts in CGI subdirectories,
broken by the fix for security issue #19435. Patch by Zach Byrne.
What's New in Python 2.7.8? What's New in Python 2.7.8?
=========================== ===========================
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment