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
The send_header method in Lib/http/server.py writes headers directly to the output stream without checking for line breaks. When user-controlled input is passed to send_header, an attacker can inject CRLF sequences (\r\n) to terminate the current header and inject new headers or manipulate the response.
Vulnerable Code:
defsend_header(self, keyword, value):
"""Send a MIME header to the headers buffer."""ifself.request_version!='HTTP/0.9':
ifnothasattr(self, '_headers_buffer'):
self._headers_buffer= []
self._headers_buffer.append(
("%s: %s\r\n"% (keyword, value)).encode('latin-1', 'strict'))
# No validation for \r or \n characters!
Bug report
Bug description:
Vulnerability Description
The
send_headermethod inLib/http/server.pywrites headers directly to the output stream without checking for line breaks. When user-controlled input is passed tosend_header, an attacker can inject CRLF sequences (\r\n) to terminate the current header and inject new headers or manipulate the response.Vulnerable Code:
Attack Scenarios
Scenario 1: Set-Cookie Injection (Session Fixation)
Vulnerable Application:
Attack URL:
Result:
Impact: Attacker can inject session cookies, leading to session fixation attacks.
Scenario 2: Location Header Injection (Malicious Redirect)
Attack URL:
Result:
Impact:
Verified Test Results:
Attack Vector
http.server.BaseHTTPRequestHandlersend_header()Impact
Set-Cookieheaders to control user sessionsLocationheaders to redirect users to attacker-controlled sitesCPython versions tested on:
CPython main branch
Operating systems tested on:
macOS
Linked PRs