例如,用户可以将您的 url 与 linux 命令一起放在文件夹/目录中吗?
假设我的服务器包括:
bin/
serverfile.go
...
public/
index.html
style.css
“www.example.com/../bin/etc”
与 serverfile.go 组成:
pacakage main
import "net/http"
func main() {
htttp.ListenAndServe(":8000", http.FileServer(http.Dir("public")))
}
最佳答案
http.FileServer 禁止突破您指定的根目录。
相比之下,您可以使用 http.ServeFile 构建自己的文件服务器,这可能是一项危险的任务。
另见 Golang. What to use? http.ServeFile(..) or http.FileServer(..)?
关于go - FileServer 处理程序是否仅服务于您指定目录中的内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44913349/