Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

net/http: FileServer sets wrong content type when 404 #24985

Closed
linkerlin opened this issue Apr 21, 2018 · 1 comment
Closed

net/http: FileServer sets wrong content type when 404 #24985

linkerlin opened this issue Apr 21, 2018 · 1 comment

Comments

@linkerlin
Copy link

linkerlin commented Apr 21, 2018

What version of Go are you using (go version)?

v1.10.1

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

GOARCH="amd64"
GOBIN=""
GOCACHE="/home/linker/.cache/go-build"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/linker/go"
GORACE=""
GOROOT="/home/linker/go111"
GOTMPDIR=""
GOTOOLDIR="/home/linker/go111/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build206124006=/tmp/go-build -gno-record-gcc-switches"

What did you do?

The net/http.FileServer uses net/http.ServeContent to automatically detect the content type of the 404 response body and concludes, rightly, that it is text/plain.

When the X-Content-Type-Options: nosniff is set to header, the browser will argue:
Refused to execute script from 'http://localhost:8080/xxxxxxxx.js' because its MIME type ('text/plain') is not executable, and strict MIME type checking is enabled.
I think it's a bug.
REF: X-Content-Type-Options: nosniff

@myitcv myitcv changed the title [X-Content-Type-Options: nosniff] Wrong content type when 404 net/http: FileServer sets wrong content type when 404 Apr 21, 2018
@myitcv
Copy link
Member

myitcv commented Apr 21, 2018

@linkerlin as I mentioned over in gopherjs/gopherjs#802 (comment), I think this is more of an issue with Chrome reporting what is a derivative error, rather than net/http.(FileServer|ServeContent). Chrome has already seen that the .js file it tried to get was 404, so why it should try to do anything with the headers/body is slightly beyond me.

As a result, I'll close this for now, but please do say if you think we've reached the wrong conclusion.

Thanks

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants