mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
bug [ 1100201 ] Cross-site scripting on BaseHTTPServer
This commit is contained in:
parent
379f99dbc3
commit
a2aa1ac42b
1 changed files with 4 additions and 1 deletions
|
@ -89,6 +89,8 @@ DEFAULT_ERROR_MESSAGE = """\
|
||||||
</body>
|
</body>
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
def _quote_html(html):
|
||||||
|
return html.replace("&", "&").replace("<", "<").replace(">", ">")
|
||||||
|
|
||||||
class HTTPServer(SocketServer.TCPServer):
|
class HTTPServer(SocketServer.TCPServer):
|
||||||
|
|
||||||
|
@ -336,8 +338,9 @@ class BaseHTTPRequestHandler(SocketServer.StreamRequestHandler):
|
||||||
message = short
|
message = short
|
||||||
explain = long
|
explain = long
|
||||||
self.log_error("code %d, message %s", code, message)
|
self.log_error("code %d, message %s", code, message)
|
||||||
|
# using _quote_html to prevent Cross Site Scripting attacks (see bug #1100201)
|
||||||
content = (self.error_message_format %
|
content = (self.error_message_format %
|
||||||
{'code': code, 'message': message, 'explain': explain})
|
{'code': code, 'message': _quote_html(message), 'explain': explain})
|
||||||
self.send_response(code, message)
|
self.send_response(code, message)
|
||||||
self.send_header("Content-Type", "text/html")
|
self.send_header("Content-Type", "text/html")
|
||||||
self.send_header('Connection', 'close')
|
self.send_header('Connection', 'close')
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue