Commit 0cf2cf2b authored by Martin Panter's avatar Martin Panter

Issue #26657: Fix SimpleHTTPServer Windows directory traversal vulnerability

Based on patch by Philipp Hagemeister.  This fixes a regression caused by
revision 6b314f5c9404.
parent 9a118f1d
...@@ -167,9 +167,9 @@ class SimpleHTTPRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler): ...@@ -167,9 +167,9 @@ class SimpleHTTPRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
words = filter(None, words) words = filter(None, words)
path = os.getcwd() path = os.getcwd()
for word in words: for word in words:
drive, word = os.path.splitdrive(word) if os.path.dirname(word) or word in (os.curdir, os.pardir):
head, word = os.path.split(word) # Ignore components that are not a simple file/directory name
if word in (os.curdir, os.pardir): continue continue
path = os.path.join(path, word) path = os.path.join(path, word)
if trailing_slash: if trailing_slash:
path += '/' path += '/'
......
...@@ -8,6 +8,7 @@ import os ...@@ -8,6 +8,7 @@ import os
import sys import sys
import re import re
import base64 import base64
import ntpath
import shutil import shutil
import urllib import urllib
import httplib import httplib
...@@ -604,6 +605,25 @@ class SimpleHTTPRequestHandlerTestCase(unittest.TestCase): ...@@ -604,6 +605,25 @@ class SimpleHTTPRequestHandlerTestCase(unittest.TestCase):
path = self.handler.translate_path('//filename?foo=bar') path = self.handler.translate_path('//filename?foo=bar')
self.assertEqual(path, self.translated) self.assertEqual(path, self.translated)
def test_windows_colon(self):
import SimpleHTTPServer
with test_support.swap_attr(SimpleHTTPServer.os, 'path', ntpath):
path = self.handler.translate_path('c:c:c:foo/filename')
path = path.replace(ntpath.sep, os.sep)
self.assertEqual(path, self.translated)
path = self.handler.translate_path('\\c:../filename')
path = path.replace(ntpath.sep, os.sep)
self.assertEqual(path, self.translated)
path = self.handler.translate_path('c:\\c:..\\foo/filename')
path = path.replace(ntpath.sep, os.sep)
self.assertEqual(path, self.translated)
path = self.handler.translate_path('c:c:foo\\c:c:bar/filename')
path = path.replace(ntpath.sep, os.sep)
self.assertEqual(path, self.translated)
def test_main(verbose=None): def test_main(verbose=None):
try: try:
......
...@@ -77,6 +77,10 @@ Core and Builtins ...@@ -77,6 +77,10 @@ Core and Builtins
Library Library
------- -------
- Issue #26657: Fix directory traversal vulnerability with SimpleHTTPServer
on Windows. This fixes a regression that was introduced in 2.7.7. Based
on patch by Philipp Hagemeister.
- Issue #19377: Add .svg to mimetypes.types_map. - Issue #19377: Add .svg to mimetypes.types_map.
- Issue #13952: Add .csv to mimetypes.types_map. Patch by Geoff Wilson. - Issue #13952: Add .csv to mimetypes.types_map. Patch by Geoff Wilson.
......
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