1
0
mirror of https://github.com/django/django.git synced 2025-10-31 09:41:08 +00:00

[1.7.x] Stripped headers containing underscores to prevent spoofing in WSGI environ.

This is a security fix. Disclosure following shortly.

Thanks to Jedediah Smith for the report.
This commit is contained in:
Carl Meyer
2014-09-10 11:06:19 -06:00
committed by Tim Graham
parent 33f1ccf5b1
commit 41b4bc73ee
6 changed files with 164 additions and 0 deletions

View File

@@ -155,6 +155,17 @@ class WSGIRequestHandler(simple_server.WSGIRequestHandler, object):
sys.stderr.write(msg)
def get_environ(self):
# Strip all headers with underscores in the name before constructing
# the WSGI environ. This prevents header-spoofing based on ambiguity
# between underscores and dashes both normalized to underscores in WSGI
# env vars. Nginx and Apache 2.4+ both do this as well.
for k, v in self.headers.items():
if '_' in k:
del self.headers[k]
return super(WSGIRequestHandler, self).get_environ()
def run(addr, port, wsgi_handler, ipv6=False, threading=False):
server_address = (addr, port)