From ec759ae9bcf486be5fbcb249a1c870cb5ac753d0 Mon Sep 17 00:00:00 2001 From: t0rchwo0d Date: Wed, 15 Feb 2023 02:46:45 +0900 Subject: [PATCH] Add escape logic for header --- gin.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/gin.go b/gin.go index 35159d03fa..32dae2497f 100644 --- a/gin.go +++ b/gin.go @@ -9,6 +9,7 @@ import ( "html/template" "net" "net/http" + "net/url" "os" "path" "strings" @@ -668,6 +669,9 @@ func redirectTrailingSlash(c *Context) { req := c.Request p := req.URL.Path if prefix := path.Clean(c.Request.Header.Get("X-Forwarded-Prefix")); prefix != "." { + prefix = url.QueryEscape(prefix) + prefix = strings.ReplaceAll(prefix, "%2F", "/") + p = prefix + "/" + req.URL.Path } req.URL.Path = p + "/"