From c0f76e9ed482b0abde0c3d8f5e26e9f015418ca3 Mon Sep 17 00:00:00 2001 From: Matthew Holt Date: Thu, 7 Jul 2022 14:10:19 -0600 Subject: [PATCH] fileserver: Use safe redirects in file browser --- modules/caddyhttp/fileserver/browse.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/modules/caddyhttp/fileserver/browse.go b/modules/caddyhttp/fileserver/browse.go index f308281a32b..d59010d28f5 100644 --- a/modules/caddyhttp/fileserver/browse.go +++ b/modules/caddyhttp/fileserver/browse.go @@ -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+"/") } }