Skip to content

Commit e538b7e

Browse files
committed
net/http/cgi: reject invalid header names
Being lenient on those has caused enough security issues. Spun out of CL 231419. Fixes #38889 Change-Id: Idd3bc6adc22e08a30b3dabb146ce78d4105684cd Reviewed-on: https://go-review.googlesource.com/c/go/+/232277 Reviewed-by: Brad Fitzpatrick <[email protected]>
1 parent 7d232ab commit e538b7e

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

src/go/build/deps_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,7 @@ var pkgDeps = map[string][]string{
448448

449449
// HTTP-using packages.
450450
"expvar": {"L4", "OS", "encoding/json", "net/http"},
451-
"net/http/cgi": {"L4", "NET", "OS", "crypto/tls", "net/http", "regexp"},
451+
"net/http/cgi": {"L4", "NET", "OS", "crypto/tls", "net/http", "regexp", "golang.org/x/net/http/httpguts"},
452452
"net/http/cookiejar": {"L4", "NET", "net/http"},
453453
"net/http/fcgi": {"L4", "NET", "OS", "context", "net/http", "net/http/cgi"},
454454
"net/http/httptest": {

src/net/http/cgi/host.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ import (
2929
"runtime"
3030
"strconv"
3131
"strings"
32+
33+
"golang.org/x/net/http/httpguts"
3234
)
3335

3436
var trailingPort = regexp.MustCompile(`:([0-9]+)$`)
@@ -277,7 +279,10 @@ func (h *Handler) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
277279
continue
278280
}
279281
header, val := parts[0], parts[1]
280-
header = textproto.TrimString(header)
282+
if !httpguts.ValidHeaderFieldName(header) {
283+
h.printf("cgi: invalid header name: %q", header)
284+
continue
285+
}
281286
val = textproto.TrimString(val)
282287
switch {
283288
case header == "Status":

0 commit comments

Comments
 (0)