fileserver: Use safe redirects in file browser

This commit is contained in:
Matthew Holt 2022-07-07 14:10:19 -06:00
parent f259ed52bb
commit c0f76e9ed4
No known key found for this signature in database
GPG key ID: 2A349DD577D586A5

View file

@ -67,9 +67,7 @@ func (fsrv *FileServer) serveBrowse(root, dirPath string, w http.ResponseWriter,
if r.URL.Path == "" || path.Base(origReq.URL.Path) == path.Base(r.URL.Path) {
if !strings.HasSuffix(origReq.URL.Path, "/") {
fsrv.logger.Debug("redirecting to trailing slash to preserve hrefs", zap.String("request_path", r.URL.Path))
origReq.URL.Path += "/"
http.Redirect(w, r, origReq.URL.String(), http.StatusMovedPermanently)
return nil
return redirect(w, r, origReq.URL.Path+"/")
}
}