catch unknown charset when decoding content-disposition params#13042
Draft
arshsmith1 wants to merge 2 commits into
Draft
catch unknown charset when decoding content-disposition params#13042arshsmith1 wants to merge 2 commits into
arshsmith1 wants to merge 2 commits into
Conversation
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.
What do these changes do?
parse_content_dispositionandcontent_disposition_filenamedecode RFC 5987 / 2231 extended parameters withunquote(value, encoding, "strict"), where the charset name comes straight from the (attacker-controlled)Content-Dispositionheader of a multipart part.parse_content_dispositionthe decode is wrapped inexcept UnicodeDecodeError, but an unknown charset name makesunquoteraise the builtinLookupError, which slips past it. The bare nameLookupErrorin this module is shadowed bypayload.LookupError, so I referencebuiltins.LookupErrorto catch the real one.content_disposition_filenameruns the same decode on the reassembled continuation value with no guard at all, so bothLookupErrorandUnicodeDecodeErrorpropagate.Reading
part.filename/part.nameon a crafted part then raises out of the parser. Both sites now give up the same way the existingUnicodeDecodeErrorbranch already intended: the parameter is dropped, and no filename is returned.Repro
Content-Disposition: form-data; name="x"; filename*=unknown-8bit''foo: before,LookupError: unknown encoding: unknown-8bit; after, the parameter is ignored.Are there changes in behavior for the user?
Only for malformed input: an extended-parameter filename with an unknown charset, or undecodable bytes in the continuation form, is ignored instead of raising. Valid values are unchanged.
Is it a substantial burden for the maintainers to support this?
No. It extends the existing exception handling by a few lines and adds unit tests next to the sibling cases.
Related issue number
N/A
Checklist
CONTRIBUTORS.txtCHANGES/folder