Reject Content-Length longer than 1 billion TB#181
Merged
njsmith merged 1 commit intopython-hyper:masterfrom Jan 12, 2025
Merged
Reject Content-Length longer than 1 billion TB#181njsmith merged 1 commit intopython-hyper:masterfrom
njsmith merged 1 commit intopython-hyper:masterfrom
Conversation
76ef74e to
40a14d8
Compare
40a14d8 to
8ff7107
Compare
sigmavirus24
approved these changes
Jan 11, 2025
Member
|
Let's make the limit something even more reasonable, like... 20? that's long enough for a 2**64 byte request body. |
8ff7107 to
dafc1e7
Compare
dafc1e7 to
60782ad
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
So there is this CVE on CPython https://www.cve.org/CVERecord?id=CVE-2020-10735, the problem is that parsing a base-10 integer with
int()is quadratic. A rogue agent can forge a badContent-Lengthheader with a huge integer to DOS h11.The way the bug was solved in CPython 3.11 was to verify the length of the
intinput, to make sure it stayed under a reasonable limit (4300 digits by default).So using h11 with Py3.11, we get a
ValueErrorwhen we try to parses a rogue Content-Length. But in Py3.8.2 (the lowest I have on my machine) it takes ages to parse it.Consider the folowing example:
So we craft a response with a Content-Length with 1MB digits.
The script takes 7 seconds to run:
Changing the
Content-Lengthfor another header (e.g.Content-Type) we don't have any problem.This PR solves 2 things:
h11.ProtocolErrorinstead of aValueError.