Ignore invalid RFC 2231 extended value so it cannot erase a valid filename#479
Merged
Merged
Conversation
garydgregory
added a commit
that referenced
this pull request
Jul 18, 2026
Member
|
Thank you @alhudz , merged 🚀 Please port to 1.x if applicable. |
Contributor
Author
|
Thanks for merging. 1.x has the same pattern in |
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
ParameterParser.parsedecodes an RFC 2231 / RFC 5987 extended value (such asfilename*) and the decode throwsIllegalArgumentException, it set the value tonulland then unconditionally stored it. Becausefilenameandfilename*both strip to the keyfilename, a malformedfilename*clobbers a validfilenamefor the same part. Repro:parse("form-data; name=\"file\"; filename=\"safe.txt\"; filename*=UTF-8'bad%2", new char[]{',',';'}). Expected:filenamestayssafe.txt. Actual:filenameisnull, sogetFileNamereturns an empty name. A client controlling the multipartContent-Dispositionheader can therefore blank the filename of an uploaded file and slip past filename-based checks in callers.The existing comment already states the intent (
Treat invalid values as if they were not provided), but settingparamValue = nulland putting it does the opposite for a parameter that also has a valid sibling value. The fix flags the invalid decode and skips storing that parameter, so an invalid extended value is genuinely ignored and cannot overwrite a valid one, regardless of ordering. Keeping this inparsemeans every caller (getFileName,getFieldName,getBoundary, charset lookup) gets the corrected behaviour without its own guard. Covered by a newParameterParserTestcase; the core suite passes (72 tests).