Skip to content

Commit 5976db7

Browse files
authored
Merge pull request #3488 from bdarnell/obs-fold
httputil: Reject header lines beginning with invalid whitespace
2 parents 1a8c152 + 1ea1435 commit 5976db7

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

tornado/httputil.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ def parse_line(self, line: str) -> None:
248248
if not line:
249249
# Empty line, or the final CRLF of a header block.
250250
return
251-
if line[0].isspace():
251+
if line[0] in HTTP_WHITESPACE:
252252
# continuation of a multi-line header
253253
# TODO(7.0): Remove support for line folding.
254254
if self._last_key is None:

tornado/test/httputil_test.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,13 +287,22 @@ def test_multi_line(self):
287287
[("Asdf", "qwer zxcv"), ("Foo", "bar baz"), ("Foo", "even more lines")],
288288
)
289289

290-
def test_malformed_continuation(self):
290+
def test_continuation(self):
291+
data = "Foo: bar\r\n\tasdf"
292+
headers = HTTPHeaders.parse(data)
293+
self.assertEqual(headers["Foo"], "bar asdf")
294+
291295
# If the first line starts with whitespace, it's a
292296
# continuation line with nothing to continue, so reject it
293297
# (with a proper error).
294298
data = " Foo: bar"
295299
self.assertRaises(HTTPInputError, HTTPHeaders.parse, data)
296300

301+
# \f (formfeed) is whitespace according to str.isspace, but
302+
# not according to the HTTP spec.
303+
data = "Foo: bar\r\n\fasdf"
304+
self.assertRaises(HTTPInputError, HTTPHeaders.parse, data)
305+
297306
def test_unicode_newlines(self):
298307
# Ensure that only \r\n is recognized as a header separator, and not
299308
# the other newline-like unicode characters.

0 commit comments

Comments
 (0)