I implemented a simple web server in Go. Since I have no experience in web development, this was a serious question for me.
Say I'm serving webpages with a modified function loadPagefrom here
func loadPage(title string) []byte {
filename := title
body, _ := ioutil.ReadFile(filename)
return body
}
func handler(w http.ResponseWriter, req *http.Request) {
content := loadPage(req.URL.Path[1:])
fmt.Fprintf(w, "%s", content)
}
Technically, this allows me to write a query in the form
http://example.com/../../etc/passwd
and the code will gladly serve the / etc / passwd file, but it is not. Does this mean that there is some protection against ../the Go HTTP package or the HTTP protocol, or am I just doing something wrong and is this a security hole?
source
share