fixed open redirect

This commit is contained in:
cyal1 2024-04-01 14:50:18 +08:00 committed by GitHub
parent 6c8ec4deda
commit 29db90e1fc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

2
gin.go
View File

@ -699,7 +699,7 @@ func redirectTrailingSlash(c *Context) {
p = prefix + "/" + req.URL.Path p = prefix + "/" + req.URL.Path
} }
req.URL.Path = p + "/" req.URL.Path = p + "/"
p = regRemoveRepeatedChar.ReplaceAllString(p, "/") p = regexp.MustCompile("^/{2,}").ReplaceAllString(p, "/")
if length := len(p); length > 1 && p[length-1] == '/' { if length := len(p); length > 1 && p[length-1] == '/' {
req.URL.Path = p[:length-1] req.URL.Path = p[:length-1]
} }