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

Tighten the parsing logic of chunked encoding #78

Merged
merged 2 commits into from
Dec 12, 2023

Conversation

kazuho
Copy link
Member

@kazuho kazuho commented Dec 12, 2023

According to RFC 9112, a chunk size consists of a series of hexadecimal characters, which may be optionally followed by whitespace and extensions beginning with a semicolon.

Picohttpparser's parsing logic has been more permissive. It recognizes a sequence of hexadecimal characters as the size, disregarding any subsequent characters. For example, although "123x\r\n" does not conform to RFC 9112, picohttpparser has interpreted this line as indicating a chunk size of 291 (0x123) bytes.

Recently, concerns have surfaced about this lenient behavior. Specifically, there is a risk that if a client, acting as a proxy, forwards a malformed chunk size which is interpreted differently by that client, it could enable splitting attacks.

To mitigate the concern, this PR tightens the parsing logic. Now, the first non-hexadecimal character must be a whitespace, a semicolon, or the end of line. While it is the responsibility of each endpoint to send HTTP messages in accordance with the specifications, these changes ensure a more robust handling of potential deviations.

We express our gratitude to Ben Kallus and Keran Mu for independently bringing this issue to our attention.

@kazuho kazuho merged commit 3bd03c2 into master Dec 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant