Closed
Description
Go version
go version go1.24.0 darwin/arm64
Output of go env
in your module/workspace:
AR='ar'
CC='clang'
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_ENABLED='1'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
CXX='clang++'
GCCGO='gccgo'
GO111MODULE=''
GOARCH='arm64'
GOARM64='v8.0'
GOAUTH='netrc'
GOBIN=''
GOCACHE='/Users/greg/Library/Caches/go-build'
GOCACHEPROG=''
GODEBUG=''
GOENV='/Users/greg/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFIPS140='off'
GOFLAGS=''
GOGCCFLAGS='-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/02/s6w7nrhn6hl8_b1t1nslsfkh0000gp/T/go-build942617912=/tmp/go-build -gno-record-gcc-switches -fno-common'
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMOD='/Users/greg/Documents/yopass-500/go.mod'
GOMODCACHE='/Users/greg/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='darwin'
GOPATH='/Users/greg/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/local/go'
GOSUMDB='sum.golang.org'
GOTELEMETRY='local'
GOTELEMETRYDIR='/Users/greg/Library/Application Support/go/telemetry'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/local/go/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='go1.24.0'
GOWORK=''
PKG_CONFIG='pkg-config'
What did you do?
Go's http.FileServer
will return a 500 for requests that have a null byte character in the path, like http://localhost:8080/test%00
.
The client is requesting to be served a file named test%00
but null bytes are not allowed in file names in any modern filesystems AFAIK.
Therefore I think the HTTP error code should be 400 (Bad Request) instead of 500 (Internal Server Error).
Repro code:
package main
import "net/http"
func main() {
fileServer := http.FileServer(http.Dir("public"))
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
fileServer.ServeHTTP(w, r)
})
http.ListenAndServe(":8080", nil)
}
What did you see happen?
❯ curl http://localhost:8080/test
404 page not found
❯ curl http://localhost:8080/test%00
500 Internal Server Error
What did you expect to see?
❯ curl http://localhost:8080/test
404 page not found
❯ curl http://localhost:8080/test%00
400 bad request