classification
Title: Security hole in wsgiref.headers.Headers
Type: security Stage: needs patch
Components: Library (Lib) Versions: Python 3.3, Python 3.2, Python 3.1, Python 2.7, Python 2.6
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: pje Nosy List: Felix.Gröbert, pje
Priority: normal Keywords:

Created on 2011-03-25 12:14 by Felix.Gröbert, last changed 2011-06-01 06:30 by terry.reedy.

Messages (3)
msg132080 - (view) Author: Felix Gröbert (Felix.Gröbert) Date: 2011-03-25 12:14
As noted by security@python.org's response I'm filing this bug here.


In wsgiref.headers.Headers it is possible to include headers which
contain a newline (i.e. \n or \r) either through add_header or
__init__. It is not uncommon that developers provide web applications
to the public in which the HTTP response headers are not filtered for
newlines but are controlled by the user. In such scenarios a malicious
user can use a newline to inject another header or even initiate a
HTTP response body. The impact would be at least equivalent to XSS.
Therefore, I suggest to filter/warn/except header tuples which contain
the above characters upon assignment in wsgiref.headers.
msg132132 - (view) Author: Phillip J. Eby (pje) * (Python committer) Date: 2011-03-25 18:41
> It is not uncommon that developers provide web applications
to the public in which the HTTP response headers are not filtered for
newlines but are controlled by the user.

Really?  Which applications, and which response headers?

> Therefore, I suggest to filter/warn/except header tuples which contain
the above characters upon assignment in wsgiref.headers.

Applications that send them are not WSGI compliant anyway, since the spec forbids control characters in header strings -- and wsgiref.validate already validates this.

Still, I'm not aware of any legitimate use case for apps sending user input as an HTTP header where the data wouldn't already be escaped in some fashion -- cookies, URLs, ...?
msg132393 - (view) Author: Felix Gröbert (Felix.Gröbert) Date: 2011-03-28 11:23
If the spec forbids control characters in headers, the module should
enforce that.

The most frequent example of header injection is the redirect-case: an
application is forwarding using the Location header to a user-supplied
URL.
http://google.com/codesearch?as_q=self.redirect%5C%28self.request.get
Other examples are proxies, setting user-agent, or, as you mention,
custom set-cookies headers.
History
Date User Action Args
2011-06-01 06:30:00terry.reedysetversions: - Python 2.5
2011-03-28 11:23:32Felix.Gröbertsetmessages: + msg132393
2011-03-25 18:41:27pjesetmessages: + msg132132
2011-03-25 16:09:44eric.araujosetnosy: + pje
title: Potential misuse of wsgiref.headers.Headers -> Security hole in wsgiref.headers.Headers
assignee: pje
versions: + Python 2.6, Python 2.5, Python 3.1, Python 2.7, Python 3.2
stage: needs patch
2011-03-25 12:14:57Felix.Gröbertcreate