]> Cypherpunks repositories - gostls13.git/commit
net/http: prevent redirect loop in serveFile if "/" is a normal file
authorMauri de Souza Meneguzzo <mauri870@gmail.com>
Wed, 10 Jan 2024 13:33:40 +0000 (13:33 +0000)
committerGopher Robot <gobot@golang.org>
Tue, 27 Feb 2024 18:08:40 +0000 (18:08 +0000)
commit296d0812b091d9cb1847381cb88ed8936d7c35ec
tree735c034d54639054e12affc1fac4ac939a5c2173
parent9fcffc53593c5cd103630d0d24ef8bd91e17246d
net/http: prevent redirect loop in serveFile if "/" is a normal file

When FileServer(Dir("file")) is used where "file" is a normal file and
not a directory, the server enters a redirect loop.

The usage of a file inplace of a directory path is not documented in
http.Dir and it could be considered undefined behavior.

This CL updates serveFile to check if we are trying to traverse a normal
file instead of a directory and return an error, preventing the redirect
loop.

Fixes #63769

Change-Id: I81e289444e7d0bd72189c2e7b763f5540333e2d0
GitHub-Last-Rev: 754c9a1167916b5a8c3c827391d7e4a2ff3bc44d
GitHub-Pull-Request: golang/go#63860
Reviewed-on: https://go-review.googlesource.com/c/go/+/538719
Reviewed-by: Damien Neil <dneil@google.com>
Reviewed-by: Emmanuel Odeke <emmanuel@orijtech.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
Auto-Submit: Bryan Mills <bcmills@google.com>
Commit-Queue: Bryan Mills <bcmills@google.com>
src/net/http/fs.go
src/net/http/fs_test.go