You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
gh-87389: Fix an open redirection vulnerability in http.server. (#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].
Copy file name to clipboardExpand all lines: Lib/http/server.py
+7Lines changed: 7 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -329,6 +329,13 @@ def parse_request(self):
329
329
returnFalse
330
330
self.command, self.path=command, path
331
331
332
+
# gh-87389: The purpose of replacing '//' with '/' is to protect
333
+
# against open redirect attacks possibly triggered if the path starts
334
+
# with '//' because http clients treat //path as an absolute URI
335
+
# without scheme (similar to http://path) rather than a path.
336
+
ifself.path.startswith('//'):
337
+
self.path='/'+self.path.lstrip('/') # Reduce to a single /
338
+
332
339
# Examine the headers and look for a Connection directive.
0 commit comments