Repository navigation
Conversation
The email parser used by http.client.parse_headers() treats a bare CR as a line terminator, so one field line could be parsed as several header fields. Replace a bare CR with SP before parsing, as RFC 9112 section 2.2 permits. This also covers http.server and wsgiref.simple_server.
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.
The email parser used by
http.client.parse_headers()treats a bare CR as a line terminator, so one field line can be parsed as several header fields. With the request from the issue,Visible: :/\rSmuggled: :)\r\nis parsed as two headers,
VisibleandSmuggled. This affectshttp.client,http.serverandwsgiref.simple_server.RFC 9112 section 2.2 says a recipient of a bare CR must either treat the element as invalid or replace each bare CR with SP before processing. This change replaces it with SP in
_read_headers(), so the line stays one field. I chose replacement over rejection because it cannot break clients that talk to servers sending a stray CR. Happy to switch to rejecting (at least inhttp.server) if that is preferred.Only CR is affected: I checked the other characters
str.splitlines()splits on (\x0b,\x0c,\x1cto\x1e,\x85) and none of them split a header line.Tests: two in
test_httpliband one intest_httpservers; all fail without the change.