Repository navigation
Fix: handle malformed multipart bodies - #2196
Merged
Merged
Conversation
The multipart parser throws on bodies it cannot parse, including an empty form (browsers send only the closing boundary for a FormData with no fields). The exception failed the whole invocation before the application ran. PHP-FPM ignores these bodies, so the PSR-7 bridge now does the same. Claude-Session: https://claude.ai/code/session_016WNB2UWjhyHkDifCSsk3V2
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.
When a POST request has a
multipart/form-datacontent type but a body thatriverline/multipart-parsercannot parse,Psr7Bridgelets the parser's exception escape. The Lambda invocation fails before the application runs: the client gets a 5xx, the application cannot handle it, and the process restarts.This happens with valid requests too: a
FormDatawith no fields is sent by browsers as just the closing boundary (--boundary--), which the parser rejects withLogicException: Can't find multi-part content. We saw this in production with a Laravel Octane application.PHP-FPM never fails on these bodies: PHP gives an empty
$_POST(or what it could parse) and the application decides what to do. This only affects the PSR-7 bridge (Octane, PSR-15 and other handlers that usePsr7Bridge).The bridge now catches the parser's exceptions (
LogicException, whichInvalidArgumentExceptionextends) and ignores the body: no parsed body and no uploaded files, the raw body is still available. A failure to create a temporary file is still reported.I considered returning a 400 instead, but:
The new test covers an empty form, an empty body, a missing closing boundary, a content type without boundary and a nested
multipart/mixedpart. All 5 cases threw before this change.