Repository navigation
net/http-client: reject CR and LF in the request line and headers - #5670
Open
Sahana2524 wants to merge 1 commit into
Open
Sahana2524 wants to merge 1 commit into
Sahana2524 wants to merge 1 commit into
Conversation
http-conn-send! wrote the method, the URI, and each header line into the request unchecked, so a CR or LF in any of them ended the line early and the rest of the string reached the server as extra headers, or as a second request on the same connection. Raise an error before anything is sent instead.
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.
Checklist
Description of change
http-conn-send!writes the method, the request URI, and each header line into the request withfprintfand no check for line breaks.http-sendrecv,http-conn-sendrecv!andhttp-conn-CONNECT-tunnelall go through it, and the URI is often assembled from a path or query piece that came from somewhere else. A CR or LF there ends the line early, so the rest of the string is sent as extra header lines or, with a blank line, as a second request on the same keep-alive connection. This is the same class as Python's http.client fix (CVE-2019-9740).net/urlisn't affected sinceurl->stringpercent-encodes the path; this only matters for directnet/http-clientcallers.For example,
(http-sendrecv "127.0.0.1" "/a\r\nX-Injected: 1" #:port port)on the current code sends:With the change,
http-conn-send!raisesexn:fail:contractbefore anything is written when the method, URI, or a header contains CR or LF. I went with rejecting rather than encoding because a header or method has no sensible encoded form, and a URI with a raw line break isn't valid to begin with. The new test fails on the old code (the server receives the injected header and a secondGET) and passes after; the rest oftests/net/http-client.rkt(1274 tests) still passes. I checked against a 9.3 build on Windows, where that file is slow becauselocalhosttries::1first, but it completes.