Skip to content

Commit d3c3aaa

Browse files
committed
net/http: revert CL 89275 (don't sniff Content-Type when nosniff set)
Also updates the bundled http2 to x/net/http2 git rev 49c15d80 for: http2: revert CL 107295 (don't sniff Content-type in Server when nosniff) https://golang.org/cl/126895 Fixes golang#24795 Change-Id: I6ae1a21c919947089274e816eb628d20490f83ce Reviewed-on: https://go-review.googlesource.com/126896 Reviewed-by: Damien Neil <[email protected]>
1 parent 9e2a4f4 commit d3c3aaa

File tree

4 files changed

+3
-42
lines changed

4 files changed

+3
-42
lines changed

doc/go1.11.html

+1-4
Original file line numberDiff line numberDiff line change
@@ -677,10 +677,7 @@ <h3 id="minor_library_changes">Minor changes to the library</h3>
677677
methods will return errors after a shutdown or close.
678678
</p>
679679

680-
<p><!-- CL 89275 -->
681-
The HTTP server will no longer automatically set the Content-Type if a
682-
<code>Handler</code> sets the "<code>X-Content-Type-Options</code>" header to "<code>nosniff</code>".
683-
</p>
680+
<!-- CL 89275 was reverted before Go 1.11 -->
684681

685682
<p><!-- CL 93296 -->
686683
The constant <code>StatusMisdirectedRequest</code> is now defined for HTTP status code 421.

src/net/http/h2_bundle.go

+1-9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/net/http/serve_test.go

-20
Original file line numberDiff line numberDiff line change
@@ -3585,26 +3585,6 @@ func TestHeaderToWire(t *testing.T) {
35853585
return nil
35863586
},
35873587
},
3588-
{
3589-
name: "Nosniff without Content-type",
3590-
handler: func(rw ResponseWriter, r *Request) {
3591-
rw.Header().Set("X-Content-Type-Options", "nosniff")
3592-
rw.WriteHeader(200)
3593-
rw.Write([]byte("<!doctype html>\n<html><head></head><body>some html</body></html>"))
3594-
},
3595-
check: func(got, logs string) error {
3596-
if !strings.Contains(got, "Content-Type: application/octet-stream\r\n") {
3597-
return errors.New("Output should have an innocuous content-type")
3598-
}
3599-
if strings.Contains(got, "text/html") {
3600-
return errors.New("Output should not have a guess")
3601-
}
3602-
if !strings.Contains(logs, "X-Content-Type-Options:nosniff but no Content-Type") {
3603-
return errors.New("Expected log message")
3604-
}
3605-
return nil
3606-
},
3607-
},
36083588
}
36093589
for _, tc := range tests {
36103590
ht := newHandlerTest(HandlerFunc(tc.handler))

src/net/http/server.go

+1-9
Original file line numberDiff line numberDiff line change
@@ -1360,15 +1360,7 @@ func (cw *chunkWriter) writeHeader(p []byte) {
13601360
// If no content type, apply sniffing algorithm to body.
13611361
_, haveType := header["Content-Type"]
13621362
if !haveType && !hasTE && len(p) > 0 {
1363-
if cto := header.get("X-Content-Type-Options"); strings.EqualFold("nosniff", cto) {
1364-
// nosniff is an explicit directive not to guess a content-type.
1365-
// Content-sniffing is no less susceptible to polyglot attacks via
1366-
// hosted content when done on the server.
1367-
setHeader.contentType = "application/octet-stream"
1368-
w.conn.server.logf("http: WriteHeader called with X-Content-Type-Options:nosniff but no Content-Type")
1369-
} else {
1370-
setHeader.contentType = DetectContentType(p)
1371-
}
1363+
setHeader.contentType = DetectContentType(p)
13721364
}
13731365
} else {
13741366
for _, k := range suppressedHeaders(code) {

0 commit comments

Comments
 (0)