Validate request method and sanitize streaming request headers - #924
Merged
Conversation
The streaming request path (send_headers_only) serialized headers with a raw to_list/1 concatenation, so a CR/LF in a header value was written verbatim and could add extra header lines. Route it through hackney_headers:to_iolist/1 like the buffered path, which strips CR/LF. The method was also never checked, only the path. valid_request_line/2 now validates both at every entry point so a CR/LF in either is refused before it reaches the request line.
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.
Two gaps in HTTP/1.1 request serialization where a caller-supplied value reached the wire unsanitized.
The streaming path (
send_headers_only) built headers with a rawto_list/1list-comprehension, so CR/LF in a header value was written verbatim and could add extra header lines. It now serializes throughhackney_headers:to_iolist/1, the same sanitizing path the buffered request uses.The method was never validated either, only the path.
valid_request_line/2now checks CR/LF/NUL in both the method and the target at every entry point (request,request_streaming,send_request_headers,open_h2_stream,request_async), returning{error, {invalid_method, _}}for a bad method.