summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_httpservers.py
diff options
context:
space:
mode:
authorMartin Panter <vadmium+py@gmail.com>2016-04-18 03:45:18 (GMT)
committerMartin Panter <vadmium+py@gmail.com>2016-04-18 03:45:18 (GMT)
commitd274b3f1f1e2d8811733fb952c9f18d7da3a376a (patch)
tree891261fc059068092ffa9e906c2a85c78f559520 /Lib/test/test_httpservers.py
parent6aafbd433dbca6c11f41f1fc55d4304d2d98d6f5 (diff)
downloadcpython-d274b3f1f1e2d8811733fb952c9f18d7da3a376a.zip
cpython-d274b3f1f1e2d8811733fb952c9f18d7da3a376a.tar.gz
cpython-d274b3f1f1e2d8811733fb952c9f18d7da3a376a.tar.bz2
Issue #26657: Fix Windows directory traversal vulnerability with http.server
Based on patch by Philipp Hagemeister. This fixes a regression caused by revision f4377699fd47.
Diffstat (limited to 'Lib/test/test_httpservers.py')
-rw-r--r--Lib/test/test_httpservers.py19
1 files changed, 19 insertions, 0 deletions
diff --git a/Lib/test/test_httpservers.py b/Lib/test/test_httpservers.py
index f396ebd..0866684 100644
--- a/Lib/test/test_httpservers.py
+++ b/Lib/test/test_httpservers.py
@@ -12,6 +12,7 @@ import os
import sys
import re
import base64
+import ntpath
import shutil
import urllib.parse
import html
@@ -918,6 +919,24 @@ class SimpleHTTPRequestHandlerTestCase(unittest.TestCase):
path = self.handler.translate_path('//filename?foo=bar')
self.assertEqual(path, self.translated)
+ def test_windows_colon(self):
+ with support.swap_attr(server.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)
+
class MiscTestCase(unittest.TestCase):
def test_all(self):