mirror of
https://github.com/python/cpython.git
synced 2024-11-27 11:55:13 +08:00
gh-104049: do not expose on-disk location from SimpleHTTPRequestHandler (#104067)
Do not expose the local server's on-disk location from `SimpleHTTPRequestHandler` when generating a directory index. (unnecessary information disclosure) --------- Co-authored-by: Gregory P. Smith <greg@krypto.org> Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
This commit is contained in:
parent
292076a9aa
commit
c7c3a60c88
@ -791,7 +791,7 @@ class SimpleHTTPRequestHandler(BaseHTTPRequestHandler):
|
||||
displaypath = urllib.parse.unquote(self.path,
|
||||
errors='surrogatepass')
|
||||
except UnicodeDecodeError:
|
||||
displaypath = urllib.parse.unquote(path)
|
||||
displaypath = urllib.parse.unquote(self.path)
|
||||
displaypath = html.escape(displaypath, quote=False)
|
||||
enc = sys.getfilesystemencoding()
|
||||
title = f'Directory listing for {displaypath}'
|
||||
|
@ -418,6 +418,14 @@ class SimpleHTTPServerTestCase(BaseTestCase):
|
||||
self.check_status_and_reason(response, HTTPStatus.OK,
|
||||
data=os_helper.TESTFN_UNDECODABLE)
|
||||
|
||||
def test_undecodable_parameter(self):
|
||||
# sanity check using a valid parameter
|
||||
response = self.request(self.base_url + '/?x=123').read()
|
||||
self.assertRegex(response, f'listing for {self.base_url}/\?x=123'.encode('latin1'))
|
||||
# now the bogus encoding
|
||||
response = self.request(self.base_url + '/?x=%bb').read()
|
||||
self.assertRegex(response, f'listing for {self.base_url}/\?x=\xef\xbf\xbd'.encode('latin1'))
|
||||
|
||||
def test_get_dir_redirect_location_domain_injection_bug(self):
|
||||
"""Ensure //evil.co/..%2f../../X does not put //evil.co/ in Location.
|
||||
|
||||
|
@ -0,0 +1,2 @@
|
||||
Do not expose the local on-disk location in directory indexes
|
||||
produced by :class:`http.client.SimpleHTTPRequestHandler`.
|
Loading…
Reference in New Issue
Block a user