-
Notifications
You must be signed in to change notification settings - Fork 18k
net/http: prevent redirect loop in serveFile if "/" is a normal file #63860
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: prevent redirect loop in serveFile if "/" is a normal file #63860
Conversation
When FileServer(Dir("file")) is used where "file" is a normal file and not a directory, the server enters a redirect loop. If serveFile is trying to serve "/" from a FileSystem and it happens to be a normal file then we can avoid the redirect loop to ../ and serve the file itself. This is the same behavior of newer apis in net/http like ServeFileFS. Fixes [reserved]
This PR (HEAD: c8c8bf4) has been imported to Gerrit for code review. Please visit Gerrit at https://go-review.googlesource.com/c/go/+/538719. Important tips:
|
Message from Damien Neil: Patch Set 2: Code-Review+2 Commit-Queue+1 (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/538719. |
Message from Go LUCI: Patch Set 2: Dry run: CV is trying the patch. Bot data: {"action":"start","triggered_at":"2023-11-06T21:40:13Z","revision":"72db8915d510aeed01e7ce63f221d78475889c8e"} Please don’t reply on this GitHub thread. Visit golang.org/cl/538719. |
Message from Damien Neil: Patch Set 2: -Commit-Queue Please don’t reply on this GitHub thread. Visit golang.org/cl/538719. |
Message from Go LUCI: Patch Set 2: This CL has passed the run Please don’t reply on this GitHub thread. Visit golang.org/cl/538719. |
Message from Go LUCI: Patch Set 2: LUCI-TryBot-Result+1 Please don’t reply on this GitHub thread. Visit golang.org/cl/538719. |
Message from Bryan Mills: Patch Set 2: (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/538719. |
Message from Mauri de Souza Meneguzzo: Patch Set 2: (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/538719. |
Message from Bryan Mills: Patch Set 2: (2 comments) Please don’t reply on this GitHub thread. Visit golang.org/cl/538719. |
Message from Mauri de Souza Meneguzzo: Patch Set 2: (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/538719. |
Message from Mauri de Souza Meneguzzo: Patch Set 2: (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/538719. |
Message from Mauri de Souza Meneguzzo: Patch Set 2: (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/538719. |
This PR (HEAD: 8e2f667) has been imported to Gerrit for code review. Please visit Gerrit at https://go-review.googlesource.com/c/go/+/538719. Important tips:
|
Message from Bryan Mills: Patch Set 2: (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/538719. |
This PR (HEAD: 6279bce) has been imported to Gerrit for code review. Please visit Gerrit at https://go-review.googlesource.com/c/go/+/538719. Important tips:
|
db6fcf1
to
480bda8
Compare
This PR (HEAD: 480bda8) has been imported to Gerrit for code review. Please visit Gerrit at https://go-review.googlesource.com/c/go/+/538719. Important tips:
|
Message from Mauri de Souza Meneguzzo: Patch Set 4: (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/538719. |
Message from Damien Neil: Patch Set 6: Code-Review+2 Commit-Queue+1 (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/538719. |
Message from Go LUCI: Patch Set 6: Dry run: CV is trying the patch. Bot data: {"action":"start","triggered_at":"2023-11-16T22:36:19Z","revision":"5394ca24677113fcbee41570ae92a9a7e732a9a7"} Please don’t reply on this GitHub thread. Visit golang.org/cl/538719. |
Message from Damien Neil: Patch Set 6: -Commit-Queue Please don’t reply on this GitHub thread. Visit golang.org/cl/538719. |
Message from Go LUCI: Patch Set 6: This CL has passed the run Please don’t reply on this GitHub thread. Visit golang.org/cl/538719. |
Message from Go LUCI: Patch Set 6: LUCI-TryBot-Result+1 Please don’t reply on this GitHub thread. Visit golang.org/cl/538719. |
480bda8
to
6f5f712
Compare
Message from Mauri de Souza Meneguzzo: Patch Set 8: Run-TryBot+1 Please don’t reply on this GitHub thread. Visit golang.org/cl/538719. |
Message from Gopher Robot: Patch Set 8: (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/538719. |
Message from Gopher Robot: Patch Set 8: TryBot-Result+1 (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/538719. |
Message from Emmanuel Odeke: Patch Set 8: Hold+1 (4 comments) Please don’t reply on this GitHub thread. Visit golang.org/cl/538719. |
Message from Emmanuel Odeke: Patch Set 8: (2 comments) Please don’t reply on this GitHub thread. Visit golang.org/cl/538719. |
…eserver-dir-file Change-Id: Iad4fd4bd06eda52cf160bcd47b5319b911c3ad94
This PR (HEAD: dbbbe96) has been imported to Gerrit for code review. Please visit Gerrit at https://go-review.googlesource.com/c/go/+/538719. Important tips:
|
Message from Mauri de Souza Meneguzzo: Patch Set 8: -Run-TryBot (3 comments) Please don’t reply on this GitHub thread. Visit golang.org/cl/538719. |
Message from Emmanuel Odeke: Patch Set 9: -Hold Code-Review+2 Run-TryBot+1 (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/538719. |
Message from Gopher Robot: Patch Set 9: (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/538719. |
Message from Gopher Robot: Patch Set 9: TryBot-Result+1 (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/538719. |
Message from Bryan Mills: Patch Set 9: (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/538719. |
Message from Bryan Mills: Patch Set 9: (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/538719. |
Message from Mauri de Souza Meneguzzo: Patch Set 9: (2 comments) Please don’t reply on this GitHub thread. Visit golang.org/cl/538719. |
This PR (HEAD: 7399288) has been imported to Gerrit for code review. Please visit Gerrit at https://go-review.googlesource.com/c/go/+/538719. Important tips:
|
Message from Mauri de Souza Meneguzzo: Patch Set 9: (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/538719. |
Message from Bryan Mills: Patch Set 10: Code-Review+1 Please don’t reply on this GitHub thread. Visit golang.org/cl/538719. |
This PR (HEAD: 754c9a1) has been imported to Gerrit for code review. Please visit Gerrit at https://go-review.googlesource.com/c/go/+/538719. Important tips:
|
Message from Mauri de Souza Meneguzzo: Patch Set 11: Commit-Queue+1 Please don’t reply on this GitHub thread. Visit golang.org/cl/538719. |
Message from Go LUCI: Patch Set 11: Dry run: CV is trying the patch. Bot data: {"action":"start","triggered_at":"2024-02-26T23:41:46Z","revision":"b47fd82ac595fbfc78aa53aa33f4ede92de3d7c6"} Please don’t reply on this GitHub thread. Visit golang.org/cl/538719. |
Message from Mauri de Souza Meneguzzo: Patch Set 11: -Commit-Queue Please don’t reply on this GitHub thread. Visit golang.org/cl/538719. |
Message from Go LUCI: Patch Set 11: This CL has passed the run Please don’t reply on this GitHub thread. Visit golang.org/cl/538719. |
Message from Go LUCI: Patch Set 11: LUCI-TryBot-Result+1 Please don’t reply on this GitHub thread. Visit golang.org/cl/538719. |
Message from Mauri de Souza Meneguzzo: Patch Set 11: (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/538719. |
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: 754c9a1 GitHub-Pull-Request: #63860 Reviewed-on: https://go-review.googlesource.com/c/go/+/538719 Reviewed-by: Damien Neil <[email protected]> Reviewed-by: Emmanuel Odeke <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Bryan Mills <[email protected]> Auto-Submit: Bryan Mills <[email protected]> Commit-Queue: Bryan Mills <[email protected]>
This PR is being closed because golang.org/cl/538719 has been merged. |
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