Skip to content

Parsing issue of Duplicate Chunked Transfer-Encoding #10611

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

Open
1 task done
TUO-Wu opened this issue Mar 20, 2025 · 1 comment
Open
1 task done

Parsing issue of Duplicate Chunked Transfer-Encoding #10611

TUO-Wu opened this issue Mar 20, 2025 · 1 comment
Labels

Comments

@TUO-Wu
Copy link

TUO-Wu commented Mar 20, 2025

Describe the bug

Hello, I may have found a bug in aiohttp's parsing of HTTP requests with duplicate chunked Transfer-Encoding.
RFC 9112 says these:

A sender MUST NOT apply the chunked transfer coding more than once to a message body (i.e., chunking an already chunked message is not allowed).

A server that receives a request message with a transfer coding it does not understand SHOULD respond with 501 (Not Implemented).

Although the RFC only restricts the sender (A sender MUST NOT apply the chunked transfer coding more than once to a message body), this should imply that duplicate chunked Transfer-Encoding is incorrect. The server may reject the request with 501 (Not Implemented) or 400 (Bad Request).
However, aiohttp does not reject such request.

To Reproduce

  1. Run aiohttp.
  2. Send the following request to aiohttp.
POST / HTTP/1.1\r\n
Host: victim.com\r\n
Transfer-Encoding: chunked, chunked\r\n
\r\n
0\r\n
\r\n
  1. Aiohttp does not reject:
$ echo -ne "POST / HTTP/1.1\r\nHost: victim.com\r\nTransfer-Encoding: chunked, chunked\r\n\r\n0\r\n\r\n" | nc 172.18.0.8 80
HTTP/1.1 200 OK
Content-Type: text/plain; charset=utf-8
Content-Length: 161
Date: Thu, 20 Mar 2025 12:12:13 GMT
Server: Python/3.10 aiohttp/4.0.0a2.dev0

{"headers":[["SG9zdA==","dmljdGltLmNvbQ=="],["VHJhbnNmZXItRW5jb2Rpbmc=","Y2h1bmtlZCwgY2h1bmtlZA=="]],"body":"","method":"UE9TVA==","uri":"Lw==","version":"MS4x"}

Expected behavior

The server may reject the request with 501 (Not Implemented) or 400 (Bad Request).

Logs/tracebacks

/

Python Version

$ python --version
Python/3.10

aiohttp Version

$ python -m pip show aiohttp
aiohttp/4.0.0a2.dev0

multidict Version

$ python -m pip show multidict
/

propcache Version

$ python -m pip show propcache
/

yarl Version

$ python -m pip show yarl
/

OS

Ubuntu 11.4.0-1ubuntu1~22.04

Related component

Server

Additional context

No response

Code of Conduct

  • I agree to follow the aio-libs Code of Conduct
@TUO-Wu TUO-Wu added the bug label Mar 20, 2025
@Dreamsorcerer
Copy link
Member

A server that receives a request message with a transfer coding it does not understand SHOULD respond with 501 (Not Implemented).

We do understand the chunked coding, so this is not relevant.

I believe expected behaviour is either:

  • We parse it as chunked once and pop one of the chunked codes from the header (which is close to what happens right now).
  • We parse it as chunked twice and produce a parse error.

It probably makes sense to end up with a parse error in this context, so feel free to create a PR to change that, but I feel this is unlikely to get prioritised by a maintainer as the current approach is still a valid approach.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants