Skip to content

Commit

Permalink
Made chunked encoding HTTP header check stricter (#6305) (#6306)
Browse files Browse the repository at this point in the history
(cherry picked from commit 7f32513)

Co-authored-by: Andrew Svetlov <andrew.svetlov@gmail.com>
  • Loading branch information
patchback[bot] and asvetlov authored Nov 13, 2021
1 parent 5795bbc commit 8457ffd
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGES/6305.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Made chunked encoding HTTP header check stricter.
5 changes: 3 additions & 2 deletions aiohttp/http_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -491,9 +491,10 @@ def parse_headers(
# chunking
te = headers.get(hdrs.TRANSFER_ENCODING)
if te is not None:
te_lower = te.lower()
if "chunked" in te_lower:
if "chunked" == te.lower():
chunked = True
else:
raise BadHttpMessage("Request has invalid `Transfer-Encoding`")

if hdrs.CONTENT_LENGTH in headers:
raise BadHttpMessage(
Expand Down
9 changes: 9 additions & 0 deletions tests/test_http_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,15 @@ def test_request_te_chunked_with_content_length(parser: Any) -> None:
parser.feed_data(text)


def test_request_te_chunked123(parser: Any) -> None:
text = b"GET /test HTTP/1.1\r\n" b"transfer-encoding: chunked123\r\n\r\n"
with pytest.raises(
http_exceptions.BadHttpMessage,
match="Request has invalid `Transfer-Encoding`",
):
parser.feed_data(text)


def test_conn_upgrade(parser: Any) -> None:
text = (
b"GET /test HTTP/1.1\r\n"
Expand Down

0 comments on commit 8457ffd

Please sign in to comment.