bpo-26657: Fix Windows directory traversal vulnerability with http.se… · AmitKumar79/PythonBegin@6f6bc1d · GitHub
Skip to content

Commit 6f6bc1d

Browse files
vstinnerlarryhastings
authored andcommitted
bpo-26657: Fix Windows directory traversal vulnerability with http.server (#782)
Based on patch by Philipp Hagemeister. This fixes a regression caused by revision f4377699fd47. (cherry picked from commit d274b3f)
1 parent cc54c1c commit 6f6bc1d

3 files changed

Lines changed: 25 additions & 3 deletions

File tree

Lib/http/server.py

Lines changed: 3 additions & 3 deletions

Lib/test/test_httpservers.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import sys
1313
import re
1414
import base64
15+
import ntpath
1516
import shutil
1617
import urllib.parse
1718
import html
@@ -829,6 +830,24 @@ def test_start_with_double_slash(self):
829830
path = self.handler.translate_path('//filename?foo=bar')
830831
self.assertEqual(path, self.translated)
831832

833+
def test_windows_colon(self):
834+
with support.swap_attr(server.os, 'path', ntpath):
835+
path = self.handler.translate_path('c:c:c:foo/filename')
836+
path = path.replace(ntpath.sep, os.sep)
837+
self.assertEqual(path, self.translated)
838+
839+
path = self.handler.translate_path('\\c:../filename')
840+
path = path.replace(ntpath.sep, os.sep)
841+
self.assertEqual(path, self.translated)
842+
843+
path = self.handler.translate_path('c:\\c:..\\foo/filename')
844+
path = path.replace(ntpath.sep, os.sep)
845+
self.assertEqual(path, self.translated)
846+
847+
path = self.handler.translate_path('c:c:foo\\c:c:bar/filename')
848+
path = path.replace(ntpath.sep, os.sep)
849+
self.assertEqual(path, self.translated)
850+
832851

833852
class MiscTestCase(unittest.TestCase):
834853
def test_all(self):
Lines changed: 3 additions & 0 deletions

0 commit comments

Comments
 (0)