Skip to content

Commit d77e77c

Browse files
miss-islingtonethanfurmangpsheadJelleZijlstra
authored
[3.10] gh-104049: do not expose on-disk location from SimpleHTTPRequestHandler (GH-104067) (#104119)
gh-104049: do not expose on-disk location from SimpleHTTPRequestHandler (GH-104067) Do not expose the local server's on-disk location from `SimpleHTTPRequestHandler` when generating a directory index. (unnecessary information disclosure) --------- (cherry picked from commit c7c3a60) Co-authored-by: Ethan Furman <[email protected]> Co-authored-by: Gregory P. Smith <[email protected]> Co-authored-by: Jelle Zijlstra <[email protected]>
1 parent e277266 commit d77e77c

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

Lib/http/server.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -791,7 +791,7 @@ def list_directory(self, path):
791791
displaypath = urllib.parse.unquote(self.path,
792792
errors='surrogatepass')
793793
except UnicodeDecodeError:
794-
displaypath = urllib.parse.unquote(path)
794+
displaypath = urllib.parse.unquote(self.path)
795795
displaypath = html.escape(displaypath, quote=False)
796796
enc = sys.getfilesystemencoding()
797797
title = 'Directory listing for %s' % displaypath

Lib/test/test_httpservers.py

+8
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,14 @@ def test_undecodable_filename(self):
417417
self.check_status_and_reason(response, HTTPStatus.OK,
418418
data=os_helper.TESTFN_UNDECODABLE)
419419

420+
def test_undecodable_parameter(self):
421+
# sanity check using a valid parameter
422+
response = self.request(self.base_url + '/?x=123').read()
423+
self.assertRegex(response, f'listing for {self.base_url}/\?x=123'.encode('latin1'))
424+
# now the bogus encoding
425+
response = self.request(self.base_url + '/?x=%bb').read()
426+
self.assertRegex(response, f'listing for {self.base_url}/\?x=\xef\xbf\xbd'.encode('latin1'))
427+
420428
def test_get_dir_redirect_location_domain_injection_bug(self):
421429
"""Ensure //evil.co/..%2f../../X does not put //evil.co/ in Location.
422430
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Do not expose the local on-disk location in directory indexes
2+
produced by :class:`http.client.SimpleHTTPRequestHandler`.

0 commit comments

Comments
 (0)