Skip to content

Commit 88a2350

Browse files
committed
net/http: permit incoming CONNECT requests without Host headers
Apparently they exist in the wild. See: #18215 (comment) (Facebook / iOS) Fixes #18215 Change-Id: I9ddad3896b5d784cb3f5b3ee9c6819081a4a2702 Reviewed-on: https://go-review.googlesource.com/44004 Run-TryBot: Brad Fitzpatrick <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Matt Layher <[email protected]> Reviewed-by: Brad Fitzpatrick <[email protected]>
1 parent a5083bb commit 88a2350

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

src/net/http/serve_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4358,6 +4358,9 @@ func TestServerValidatesHostHeader(t *testing.T) {
43584358
// Make an exception for HTTP upgrade requests:
43594359
{"PRI * HTTP/2.0", "", 200},
43604360

4361+
// Also an exception for CONNECT requests: (Issue 18215)
4362+
{"CONNECT golang.org:443 HTTP/1.1", "", 200},
4363+
43614364
// But not other HTTP/2 stuff:
43624365
{"PRI / HTTP/2.0", "", 400},
43634366
{"GET / HTTP/2.0", "", 400},

src/net/http/server.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -943,7 +943,7 @@ func (c *conn) readRequest(ctx context.Context) (w *response, err error) {
943943

944944
hosts, haveHost := req.Header["Host"]
945945
isH2Upgrade := req.isH2Upgrade()
946-
if req.ProtoAtLeast(1, 1) && (!haveHost || len(hosts) == 0) && !isH2Upgrade {
946+
if req.ProtoAtLeast(1, 1) && (!haveHost || len(hosts) == 0) && !isH2Upgrade && req.Method != "CONNECT" {
947947
return nil, badRequestError("missing required Host header")
948948
}
949949
if len(hosts) > 1 {

0 commit comments

Comments
 (0)