Skip to content

Commit

Permalink
check if the header contains control characters
Browse files Browse the repository at this point in the history
fix #1227
  • Loading branch information
benoitc committed Mar 18, 2016
1 parent 6dcd7a6 commit d38804c
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions gunicorn/http/wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import sys

from gunicorn._compat import unquote_to_wsgi_str
from gunicorn.http.errors import InvalidHeader
from gunicorn.six import string_types, binary_type, reraise
from gunicorn import SERVER_SOFTWARE
import gunicorn.util as util
Expand All @@ -28,6 +29,7 @@
BLKSIZE = 0x3FFFFFFF

NORMALIZE_SPACE = re.compile(r'(?:\r\n)?[ \t]+')
HEADER_VALUE_RE = re.compile(r"[\x07\x1B\f\n\r\t\v]")

log = logging.getLogger(__name__)

Expand Down Expand Up @@ -262,6 +264,10 @@ def process_headers(self, headers):
for name, value in headers:
if not isinstance(name, string_types):
raise TypeError('%r is not a string' % name)

if HEADER_VALUE_RE.search(value):
raise InvalidHeader('%r' % value)

value = str(value).strip()
lname = name.lower().strip()
if lname == "content-length":
Expand Down

0 comments on commit d38804c

Please sign in to comment.