From e06f8bddbc050f7e177dcc42b7da04141a296222 Mon Sep 17 00:00:00 2001 From: Solderpunk Date: Sun, 24 Jan 2021 16:27:07 +0100 Subject: [PATCH] Fix infinite redirect bug. Previously, URLs without trailing slashes in the path which resolved to directories caused infinite redirects if there was anything in the URL after the path (like a query). Thanks to both Luke Emmet and Stephane Bortzmeyer for reporting this! --- handler.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/handler.go b/handler.go index b4ee12a..096416e 100644 --- a/handler.go +++ b/handler.go @@ -205,7 +205,8 @@ func serveDirectory(URL *url.URL, path string, log *LogEntry, conn net.Conn, con // Redirect to add trailing slash if missing // (otherwise relative links don't work properly) if !strings.HasSuffix(URL.Path, "/") { - conn.Write([]byte(fmt.Sprintf("31 %s\r\n", URL.String()+"/"))) + URL.Path += "/" + conn.Write([]byte(fmt.Sprintf("31 %s\r\n", URL.String()))) log.Status = 31 return }