Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PR #6305/7f325135 backport][3.8] Made chunked encoding HTTP header check stricter #6306

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES/6305.bugfix
@@ -0,0 +1 @@
Made chunked encoding HTTP header check stricter.
5 changes: 3 additions & 2 deletions aiohttp/http_parser.py
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
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