Skip to content

Commit 0421e78

Browse files
committed
net/http: fix too-strict validation of server header values
As Andy Balholm noted in #11207: "RFC2616 §4.2 says that a header's field-content can consist of *TEXT, and RFC2616 §2.2 says that TEXT is <any OCTET except CTLs, but including LWS>, so that would mean that bytes greater than 128 are allowed." This is a partial rollback of the strictness from https://golang.org/cl/11207 (added in the Go 1.6 dev cycle, only released in Go 1.6beta1) Fixes #11207 Change-Id: I3a752a7941de100e4803ff16a5d626d5cfec4f03 Reviewed-on: https://go-review.googlesource.com/18374 Reviewed-by: Russ Cox <rsc@golang.org> Reviewed-by: Andrew Gerrand <adg@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
1 parent ee566d5 commit 0421e78

File tree

2 files changed

+4
-8
lines changed

2 files changed

+4
-8
lines changed

src/net/http/request.go

+2-6
Original file line numberDiff line numberDiff line change
@@ -1139,13 +1139,9 @@ func validHeaderName(v string) bool {
11391139
func validHeaderValue(v string) bool {
11401140
for i := 0; i < len(v); i++ {
11411141
b := v[i]
1142-
if b == '\t' {
1143-
continue
1144-
}
1145-
if ' ' <= b && b <= '~' {
1146-
continue
1142+
if b < ' ' && b != '\t' {
1143+
return false
11471144
}
1148-
return false
11491145
}
11501146
return true
11511147
}

src/net/http/serve_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -3798,8 +3798,8 @@ func TestServerValidatesHeaders(t *testing.T) {
37983798
{"foo\xffbar: foo\r\n", 400}, // binary in header
37993799
{"foo\x00bar: foo\r\n", 400}, // binary in header
38003800

3801-
{"foo: foo\x00foo\r\n", 400}, // binary in value
3802-
{"foo: foo\xfffoo\r\n", 400}, // binary in value
3801+
{"foo: foo\x00foo\r\n", 400}, // CTL in value is bad
3802+
{"foo: foo\xfffoo\r\n", 200}, // non-ASCII high octets in value are fine
38033803
}
38043804
for _, tt := range tests {
38053805
conn := &testConn{closec: make(chan bool)}

0 commit comments

Comments
 (0)