Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGES/12996.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Fixed ``parse_content_disposition`` rejecting otherwise-valid
``Content-Disposition`` header values that contain optional whitespace (OWS)
around the disposition type (e.g. ``"form-data ; name=\"field\""``).
The disposition type is now stripped before token validation, consistent with
how parameter keys are already handled -- by :user:`JSap0914`.
2 changes: 2 additions & 0 deletions aiohttp/multipart.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,9 @@ def unescape(text: str, *, chars: str = "".join(map(re.escape, CHAR))) -> str:
if not header:
return None, {}

# https://www.rfc-editor.org/info/rfc9110/#section-5.6.6-2
disptype, *parts = header.split(";")
disptype = disptype.strip()
if not is_token(disptype):
warnings.warn(BadContentDispositionHeader(header))
return None, {}
Expand Down
10 changes: 10 additions & 0 deletions tests/test_multipart_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,16 @@ def test_empty_param_value_multiple(self) -> None:
assert disptype is None
assert {} == params

def test_disptype_with_trailing_space_before_semicolon(self) -> None:
disptype, params = parse_content_disposition('form-data ; name="field"')
assert disptype == "form-data"
assert params == {"name": "field"}

def test_disptype_with_trailing_space_no_params(self) -> None:
disptype, params = parse_content_disposition("inline ")
assert disptype == "inline"
assert params == {}


class TestContentDispositionFilename:
# http://greenbytes.de/tech/tc2231/
Expand Down
Loading