Validate Content-Length format in ClientRequest#12385
Validate Content-Length format in ClientRequest#12385Dreamsorcerer merged 4 commits intoaio-libs:masterfrom
Conversation
|
Could you add an end-to-end test in test_web_functional.py? I think this code is actually unreachable and even the current check can be removed. I'm pretty sure we already validate it in the parser. |
49f902f to
4296e72
Compare
dd083ea to
a66944d
Compare
|
Added an end-to-end test in Let me know if you'd like any changes. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #12385 +/- ##
=======================================
Coverage 98.92% 98.92%
=======================================
Files 134 134
Lines 46741 46751 +10
Branches 2429 2430 +1
=======================================
+ Hits 46239 46249 +10
Misses 373 373
Partials 129 129
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
Merging this PR will not alter performance
Comparing Footnotes
|
Sorry, I thought this was validating the response. I've just realised this is validating the request, i.e. the data from the developer. I guess this looks fine as a simple improvement to sanity checking then. |
ee47a1b to
7074a06
Compare
Reject non-RFC-compliant Content-Length values to align with HTTP parser behavior and ensure consistent validation.
7074a06 to
991105b
Compare
for more information, see https://pre-commit.ci
Backport to 3.14: 💔 cherry-picking failed — conflicts found❌ Failed to cleanly apply 365f717 on top of patchback/backports/3.14/365f717faf6df82108971b847264e9b28d4d1b07/pr-12385 Backporting merged PR #12385 into master
🤖 @patchback |
|
If you could follow the above instructions for a backport, that'd be really helpful. |
|
Sure, I’ll work on the backport following the instructions. |
What do these changes do?
This change adds strict validation for the
Content-Lengthheader inClientRequest.Currently,
_get_content_length()uses Python’sint()for parsing, which accepts non-RFC-compliant values such as negative numbers or values with whitespace. This patch introduces a DIGITS-only validation to ensure the header follows the same format already enforced by the HTTP parser.Are there changes in behavior for the user?
Yes, but only for invalid inputs.
Content-Lengthvalues (e.g.,"0","100") are unaffected."-100"," 100","+100") will now raise aValueErrorinstead of being accepted.This aligns behavior across send and receive paths and avoids unexpected behavior when invalid values are provided.
Is it a substantial burden for the maintainers to support this?
No.
This should not increase maintenance overhead.
Related issue number
N/A
Checklist
CONTRIBUTORS.txtCHANGES/folder