Skip to content

Commit

Permalink
Allow horizontal tabs in header values
Browse files Browse the repository at this point in the history
Addresses: #3450
  • Loading branch information
dave-shawley committed Dec 18, 2024
1 parent 0a39ba8 commit f9322d6
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
7 changes: 4 additions & 3 deletions tornado/test/web_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -700,11 +700,12 @@ def get(self):
self.set_header("X-Foo", "foo\r\nX-Bar: baz")
raise Exception("Didn't get expected exception")
except ValueError as e:
if "Unsafe header value" in str(e):
self.finish(b"ok")
else:
if "Unsafe header value" not in str(e):
raise

self.set_header("X-Foo", "foo\tX-Bar: baz")
self.finish(b"ok")


class GetArgumentHandler(RequestHandler):
def prepare(self):
Expand Down
2 changes: 1 addition & 1 deletion tornado/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ def clear_header(self, name: str) -> None:
if name in self._headers:
del self._headers[name]

_INVALID_HEADER_CHAR_RE = re.compile(r"[\x00-\x1f]")
_INVALID_HEADER_CHAR_RE = re.compile(r"[\x00-\x08\x0a-\x1f]")

def _convert_header_value(self, value: _HeaderTypes) -> str:
# Convert the input value to a str. This type check is a bit
Expand Down

0 comments on commit f9322d6

Please sign in to comment.