feat(): sanitize '/' path properly
This commit is contained in:
parent
b8ad1dd9b9
commit
2212962796
9
main.go
9
main.go
@ -7,7 +7,6 @@ import (
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
@ -28,7 +27,13 @@ func main() {
|
||||
}
|
||||
|
||||
func fileHandler(w http.ResponseWriter, r *http.Request) {
|
||||
path := filepath.Join(filesDir, strings.TrimPrefix(r.URL.Path, "/"))
|
||||
name := filepath.Clean(r.URL.Path)
|
||||
path := filepath.Join(filesDir, name)
|
||||
|
||||
if !filepath.IsLocal(path) {
|
||||
http.Error(w, "Wrong url", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
if fileInfo, err := os.Stat(path); err == nil && !fileInfo.IsDir() {
|
||||
http.ServeFile(w, r, path)
|
||||
|
Loading…
Reference in New Issue
Block a user