Skip to content

net/http-client: reject CR and LF in the request line and headers - #5670

Open
Sahana2524 wants to merge 1 commit into
racket:masterfrom
Sahana2524:http-client-reject-crlf
Open

Sahana2524 wants to merge 1 commit into
racket:masterfrom
Sahana2524:http-client-reject-crlf

Conversation

@Sahana2524

Copy link
Copy Markdown
Contributor

Checklist

  • Bugfix
  • tests included
  • documentation

Description of change

http-conn-send! writes the method, the request URI, and each header line into the request with fprintf and no check for line breaks. http-sendrecv, http-conn-sendrecv! and http-conn-CONNECT-tunnel all 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/url isn't affected since url->string percent-encodes the path; this only matters for direct net/http-client callers.

For example, (http-sendrecv "127.0.0.1" "/a\r\nX-Injected: 1" #:port port) on the current code sends:

GET /a
X-Injected: 1 HTTP/1.1
Host: 127.0.0.1:...

With the change, http-conn-send! raises exn:fail:contract before 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 second GET) and passes after; the rest of tests/net/http-client.rkt (1274 tests) still passes. I checked against a 9.3 build on Windows, where that file is slow because localhost tries ::1 first, but it completes.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant