multipart: tolerate OWS after a quoted Content-Disposition parameter value#13056
Draft
HrachShah wants to merge 1 commit into
Draft
multipart: tolerate OWS after a quoted Content-Disposition parameter value#13056HrachShah wants to merge 1 commit into
HrachShah wants to merge 1 commit 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_dispositionnow accepts optional whitespace (OWS) between a quoted parameter value and the;that follows it. RFC 7230 § 3.2.3 / RFC 9110 § 5.6.6 permit OWS around the;separator in HTTP header fields, so headers likewere being misparsed: the trailing OWS made
is_quotedreturnFalse, the parser fell through to the semicolon-repair heuristic, and the next parameter (name="field") was greedily consumed into the filename value.The fix adds a second
is_quotedcheck againstvalue.rstrip()for the ordinary-parameter branch inaiohttp/multipart.pyso OWS is stripped before the value is validated as a quoted string. The greedy-repair branch is unchanged — it is only ever reached when the value really is not a quoted string and a real follow-up token needs to be salvaged.Are there changes in behavior for the user?
Content-Dispositionheaders with OWS after a quoted parameter value now parse the quoted value correctly and treat the next parameter as a separate entry, matching the behaviour of the browser-sideContent-Dispositionparser and the RFC.filename=a;bis untouched.Is it a substantial burden for the maintainers to support this?
No. The change is a one-line additional
is_quotedcheck in the existing parameter-handling branch and a 5-test addition totests/test_multipart_helpers.py. No new public API, no new failure modes — the additional branch is more permissive (it only matches values that already start and end with"after stripping trailing OWS).Related issue number
Fixes #13002.
Checklist
PYTHONPATH=. pytest tests/test_multipart_helpers.py— 104 passed, 5 skipped, 1 unrelated pre-existing failure ontest_attwithfn2231utf8comp).TestParseContentDisposition).CHANGES/13002.bugfix.rst.Test output
Without the fix, all 5 new tests fail. The relevant pre-fix failure for the issue's exact reproducer:
Drafted with Zo Computer; reviewed by HrachShah.