Skip to content

Commit

Permalink
Handle invalid CRLF in header name. fixes #122 (#141)
Browse files Browse the repository at this point in the history
  • Loading branch information
jhnstrk authored Sep 28, 2024
1 parent 851a026 commit dcf0ba1
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion multipart/multipart.py
Original file line number Diff line number Diff line change
Expand Up @@ -1163,7 +1163,7 @@ def data_callback(name: str, remaining: bool = False) -> None:
# If we've reached a CR at the beginning of a header, it means
# that we've reached the second of 2 newlines, and so there are
# no more headers to parse.
if c == CR:
if c == CR and index == 0:
delete_mark("header_field")
state = MultipartState.HEADERS_ALMOST_DONE
i += 1
Expand Down
6 changes: 6 additions & 0 deletions tests/test_data/http/CRLF_in_header.http
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
------WebKitFormBoundaryTkr3kCBQlBe1nrhc
Content-
isposition: form-data; name="field"

This is a test.
------WebKitFormBoundaryTkr3kCBQlBe1nrhc--
3 changes: 3 additions & 0 deletions tests/test_data/http/CRLF_in_header.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
boundary: ----WebKitFormBoundaryTkr3kCBQlBe1nrhc
expected:
error: 50
2 changes: 1 addition & 1 deletion tests/test_data/http/CR_in_header.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
boundary: ----WebKitFormBoundaryTkr3kCBQlBe1nrhc
expected:
error: 51
error: 50

0 comments on commit dcf0ba1

Please sign in to comment.