-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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: http.FileServer returns 500 when a null byte is passed in the URL #72091
Comments
Interesting bits that did not fit the template: We are interested in this change because we monitor services for 5xx error codes and every now and then an automated scanner will hit our services with a null byte in the URL which will trigger an alert for us. Of course we could front our services with e.g. an nginx or WAF that would reject all requests with a null byte but I would rather fix the root cause and change the HTTP status code returned by Go http.FileServer to make it more appropriate than apply a patch like fronting all our services just for this use case. Call stack:
in This error is then not mapped to any specific error in My suggestion to implement a 400 instead of a 500:
I can make a PR if this suggestion looks good 👍 Thank you |
CC @neild |
I agree that we should return a 4xx error in this case, not a 500. I think 404 might make more sense than 400; this is just another case of an input path not mapping to a file we can serve. Happy to review a CL if you want to send one. |
Change https://go.dev/cl/654975 mentions this issue: |
Go version
go version go1.24.0 darwin/arm64
Output of
go env
in your module/workspace:What did you do?
Go's
http.FileServer
will return a 500 for requests that have a null byte character in the path, likehttp://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:
What did you see happen?
What did you expect to see?
The text was updated successfully, but these errors were encountered: