Repository navigation
Add max_nesting_depth to MultipartReader - #14585
Franco944796 wants to merge 1 commit into
Conversation
Each nested multipart/* part builds another MultipartReader and release() recursed once per level with no cap, so a ~70 KB body nested 1000 levels deep raised RecursionError. Nested readers now get one level less and a part nested deeper than max_nesting_depth (default 10) raises BadHttpMessage before another reader is built (THREAT_MODEL.md threat 4.3).
54b73aa to
69f3ef2
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #14585 +/- ##
=======================================
Coverage 99.13% 99.13%
=======================================
Files 135 135
Lines 54630 54673 +43
Branches 2808 2811 +3
=======================================
+ Hits 54158 54201 +43
Misses 357 357
Partials 115 115
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. |
Merging this PR will not alter performance1 warning
Comparing Footnotes
|
Confidence Score: 5/5
[Medium impact] The PR appears safe to merge. Reviews (1) · Last reviewed commit: "Add max_nesting_depth to MultipartReader" · Reviewed by Greptile |
What do these changes do?
MultipartReaderbuilds a new reader for every nestedmultipart/*part, with no limit on how deep that goes, andrelease()recurses once per level. A ~70 KB body nested 1000 levels deep makesrelease()raiseRecursionError. This is threat 4.3 inTHREAT_MODEL.md, which recommends amax_nesting_depthparameter.This adds
max_nesting_depth(default10). Each nested reader gets one level less, and a part nested deeper than the limit raisesBadHttpMessagebefore another reader is built. That is the same exception the per-partmax_headerslimit already raises.Are there changes in behavior for the user?
A body nested more than 10 levels deep now raises
BadHttpMessagefromnext()/release()instead of being parsed (or failing withRecursionErroronce it is deep enough). Code that needs deeper nesting can pass a largermax_nesting_depth.Request.post()is unchanged: it already rejects nested multipart parts.Is it a substantial burden for the maintainers to support this?
No. It is one keyword argument, passed to nested readers the same way as
max_headers, including throughmultipart_reader_cls.Related issue number
No issue;
THREAT_MODEL.mdthreat 4.3. The PR updates its mitigation row and the recap of §5.4.Checklist
CONTRIBUTORS.txtCHANGES/folderTest run (pure-Python mode,
AIOHTTP_NO_EXTENSIONS=1)Every step verified
Drafted with Claude Opus 5.5; reviewed by @Franco944796.