mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
gh-133889: Only show the path of the URL in the SimpleHTTPRequestHandler page (GH-134135)
The query and fragment are ambiguous and not used.
This commit is contained in:
parent
bb32f3c698
commit
5cbc8c632e
3 changed files with 15 additions and 8 deletions
|
@ -818,11 +818,14 @@ class SimpleHTTPRequestHandler(BaseHTTPRequestHandler):
|
||||||
return None
|
return None
|
||||||
list.sort(key=lambda a: a.lower())
|
list.sort(key=lambda a: a.lower())
|
||||||
r = []
|
r = []
|
||||||
|
displaypath = self.path
|
||||||
|
displaypath = displaypath.split('#', 1)[0]
|
||||||
|
displaypath = displaypath.split('?', 1)[0]
|
||||||
try:
|
try:
|
||||||
displaypath = urllib.parse.unquote(self.path,
|
displaypath = urllib.parse.unquote(displaypath,
|
||||||
errors='surrogatepass')
|
errors='surrogatepass')
|
||||||
except UnicodeDecodeError:
|
except UnicodeDecodeError:
|
||||||
displaypath = urllib.parse.unquote(self.path)
|
displaypath = urllib.parse.unquote(displaypath)
|
||||||
displaypath = html.escape(displaypath, quote=False)
|
displaypath = html.escape(displaypath, quote=False)
|
||||||
enc = sys.getfilesystemencoding()
|
enc = sys.getfilesystemencoding()
|
||||||
title = f'Directory listing for {displaypath}'
|
title = f'Directory listing for {displaypath}'
|
||||||
|
|
|
@ -627,13 +627,14 @@ class SimpleHTTPServerTestCase(BaseTestCase):
|
||||||
self.check_list_dir_filename(filename)
|
self.check_list_dir_filename(filename)
|
||||||
os_helper.unlink(os.path.join(self.tempdir, filename))
|
os_helper.unlink(os.path.join(self.tempdir, filename))
|
||||||
|
|
||||||
def test_undecodable_parameter(self):
|
def test_list_dir_with_query_and_fragment(self):
|
||||||
# sanity check using a valid parameter
|
prefix = f'listing for {self.base_url}/</'.encode('latin1')
|
||||||
|
response = self.request(self.base_url + '/#123').read()
|
||||||
|
self.assertIn(prefix + b'title>', response)
|
||||||
|
self.assertIn(prefix + b'h1>', response)
|
||||||
response = self.request(self.base_url + '/?x=123').read()
|
response = self.request(self.base_url + '/?x=123').read()
|
||||||
self.assertRegex(response, rf'listing for {self.base_url}/\?x=123'.encode('latin1'))
|
self.assertIn(prefix + b'title>', response)
|
||||||
# now the bogus encoding
|
self.assertIn(prefix + b'h1>', response)
|
||||||
response = self.request(self.base_url + '/?x=%bb').read()
|
|
||||||
self.assertRegex(response, rf'listing for {self.base_url}/\?x=\xef\xbf\xbd'.encode('latin1'))
|
|
||||||
|
|
||||||
def test_get_dir_redirect_location_domain_injection_bug(self):
|
def test_get_dir_redirect_location_domain_injection_bug(self):
|
||||||
"""Ensure //evil.co/..%2f../../X does not put //evil.co/ in Location.
|
"""Ensure //evil.co/..%2f../../X does not put //evil.co/ in Location.
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
The generated directory listing page in
|
||||||
|
:class:`http.server.SimpleHTTPRequestHandler` now only shows the decoded
|
||||||
|
path component of the requested URL, and not the query and fragment.
|
Loading…
Add table
Add a link
Reference in a new issue