fix: use platform independent absolute path algorithm

Fixes issue https://github.com/hibiken/asynqmon/issues/257
This commit is contained in:
Paweł Kierski 2023-04-07 17:20:44 +02:00 committed by GitHub
parent 5c48e4e31d
commit 724e77fc0c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -29,11 +29,7 @@ type uiAssetsHandler struct {
// serve the file specified by the URL path.
func (h *uiAssetsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
// Get the absolute path to prevent directory traversal.
path, err := filepath.Abs(r.URL.Path)
if err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
path := filepath.filepath.ToSlash(filepath.Clean(r.URL.Path))
// Get the path relative to the root path.
if !strings.HasPrefix(path, h.rootPath) {