Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle invalid CRLF in header name. fixes #122 #141

Merged
merged 2 commits into from
Sep 28, 2024
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
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