-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Fix multipart parsing for empty body parts #11857
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
Fix multipart parsing for empty body parts #11857
Conversation
for more information, see https://pre-commit.ci
|
FWIW, a real world application of this: https://strawberry.rocks/docs/general/multipart-subscriptions Minimal implementation here: https://github.com/magicmark/gql-book-server/ Raw response: It's also possible the fix needs to be made in Strawberry? cc @patrick91 @erikwrede |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #11857 +/- ##
==========================================
- Coverage 98.74% 98.74% -0.01%
==========================================
Files 127 127
Lines 44171 44187 +16
Branches 2342 2343 +1
==========================================
+ Hits 43618 43631 +13
- Misses 392 395 +3
Partials 161 161
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
CodSpeed Performance ReportMerging #11857 will not alter performanceComparing Summary
|
764cb47 to
0e70964
Compare
https://datatracker.ietf.org/doc/html/rfc2046#section-5.1.1 So, an empty body part looks like: So, the example provided appears to be invalid syntax to me (not to mention that it seems illogical to be wasting bandwidth sending nothing). If we allowed this, there's a possibility it could open up an HTTP request smuggling vulnerability. |
|
Thanks @Dreamsorcerer. Will make the fix in Strawberry then. |
|
Tests are still xfailing with correct syntax, so there may be a fix needed in both. |
|
OK, I have a fix. Going to make some tweaks to the this test and then will followup with the actual fix. |
|
Causes too many warnings. Will have to add the fix here. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR fixes a bug in multipart parsing when encountering empty body parts. Despite the description stating it only adds failing tests marked with @pytest.mark.xfail, the PR actually includes both test cases and implementation fixes.
Key Changes:
- Adds two test cases for empty body parts in multipart parsing
- Fixes CRLF handling in
_read_chunk_from_streamby prepending and later stripping the CRLF consumed during header parsing - Corrects the boundary truncation logic by removing an incorrect conditional check
- Changes header line processing from
strip()torstrip(b"\r\n")for more precise whitespace handling
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| tests/test_multipart.py | Adds two test cases to verify correct handling of empty body parts with and without headers |
| aiohttp/multipart.py | Fixes multipart parsing logic to correctly handle empty body parts by adjusting CRLF handling and boundary detection |
| CONTRIBUTORS.txt | Adds Mark Larah to the contributors list |
| CHANGES/11857.bugfix.rst | Documents the bugfix with credit to Dreamsorcerer |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
bdraco
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good once PR description is updated
Backport to 3.13: 💚 backport PR created✅ Backport PR branch: Backported as #11879 🤖 @patchback |
Fixes multipart parser when encountering an empty body. --------- Co-authored-by: Sam Bull <git@sambull.org> (cherry picked from commit 0a915b8)
Backport to 3.14: 💚 backport PR created✅ Backport PR branch: Backported as #11880 🤖 @patchback |
Fixes multipart parser when encountering an empty body. --------- Co-authored-by: Sam Bull <git@sambull.org> (cherry picked from commit 0a915b8)
Fixes multipart parser when encountering an empty body.