Skip to content

Commit

Permalink
Fix multipart parsing bug
Browse files Browse the repository at this point in the history
Escape special regex characters from the boundary before placing into
the regexs used to locate the boundaries in the multipart data.
  • Loading branch information
pgjones committed May 14, 2021
1 parent a44c1d7 commit d170b2d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/werkzeug/sansio/multipart.py
Expand Up @@ -101,7 +101,7 @@ def __init__(
# group to understand if it is an epilogue boundary.
self.preamble_re = re.compile(
br"%s?--%s(--[^\S\n\r]*%s?|[^\S\n\r]*%s)"
% (LINE_BREAK, boundary, LINE_BREAK, LINE_BREAK),
% (LINE_BREAK, re.escape(boundary), LINE_BREAK, LINE_BREAK),
re.MULTILINE,
)
# A boundary must include a line break prefix and suffix, and
Expand All @@ -110,7 +110,7 @@ def __init__(
# understand if it is an epilogue boundary.
self.boundary_re = re.compile(
br"%s--%s(--[^\S\n\r]*%s?|[^\S\n\r]*%s)"
% (LINE_BREAK, boundary, LINE_BREAK, LINE_BREAK),
% (LINE_BREAK, re.escape(boundary), LINE_BREAK, LINE_BREAK),
re.MULTILINE,
)

Expand Down
8 changes: 4 additions & 4 deletions tests/sansio/test_multipart.py
Expand Up @@ -10,18 +10,18 @@


def test_decoder_simple() -> None:
boundary = b"---------------------------9704338192090380615194531385"
boundary = b"---------------------------9704338192090380615194531385$"
decoder = MultipartDecoder(boundary)
data = """
-----------------------------9704338192090380615194531385
-----------------------------9704338192090380615194531385$
Content-Disposition: form-data; name="fname"
ß∑œß∂ƒå∂
-----------------------------9704338192090380615194531385
-----------------------------9704338192090380615194531385$
Content-Disposition: form-data; name="lname"; filename="bob"
asdasd
-----------------------------9704338192090380615194531385--
-----------------------------9704338192090380615194531385$--
""".replace(
"\n", "\r\n"
).encode(
Expand Down

0 comments on commit d170b2d

Please sign in to comment.