mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
gh-87389: Fix an open redirection vulnerability in http.server. (GH-93879)
Fix an open redirection vulnerability in the `http.server` module when
an URI path starts with `//` that could produce a 301 Location header
with a misleading target. Vulnerability discovered, and logic fix
proposed, by Hamza Avvan (@hamzaavvan).
Test and comments authored by Gregory P. Smith [Google].
(cherry picked from commit 4abab6b603
)
Co-authored-by: Gregory P. Smith <greg@krypto.org>
This commit is contained in:
parent
a1565a80ef
commit
e2e8847bf5
3 changed files with 61 additions and 2 deletions
|
@ -329,6 +329,13 @@ class BaseHTTPRequestHandler(socketserver.StreamRequestHandler):
|
|||
return False
|
||||
self.command, self.path = command, path
|
||||
|
||||
# gh-87389: The purpose of replacing '//' with '/' is to protect
|
||||
# against open redirect attacks possibly triggered if the path starts
|
||||
# with '//' because http clients treat //path as an absolute URI
|
||||
# without scheme (similar to http://path) rather than a path.
|
||||
if self.path.startswith('//'):
|
||||
self.path = '/' + self.path.lstrip('/') # Reduce to a single /
|
||||
|
||||
# Examine the headers and look for a Connection directive.
|
||||
try:
|
||||
self.headers = http.client.parse_headers(self.rfile,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue