From eb687ec75b29fa91ac79ec83db5e5cef13d7c191 Mon Sep 17 00:00:00 2001 From: Lauris BH Date: Thu, 8 Jun 2023 11:32:23 +0300 Subject: [PATCH 1/2] Fix open redirect check for more cases --- modules/context/context_response.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/context/context_response.go b/modules/context/context_response.go index aeeb51ba377f2..84eaa8ebd0b76 100644 --- a/modules/context/context_response.go +++ b/modules/context/context_response.go @@ -51,7 +51,7 @@ func (ctx *Context) RedirectToFirst(location ...string) { // Unfortunately browsers consider a redirect Location with preceding "//" and "/\" as meaning redirect to "http(s)://REST_OF_PATH" // Therefore we should ignore these redirect locations to prevent open redirects - if len(loc) > 1 && loc[0] == '/' && (loc[1] == '/' || loc[1] == '\\') { + if len(loc) > 1 && (loc[0] == '/' || loc[0] == '\\') && (loc[1] == '/' || loc[1] == '\\') { continue } From 29c8848230ccb0b10cfe2c2613e05b812c8709cf Mon Sep 17 00:00:00 2001 From: Lauris BH Date: Thu, 8 Jun 2023 11:41:18 +0300 Subject: [PATCH 2/2] Update comment --- modules/context/context_response.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/context/context_response.go b/modules/context/context_response.go index 84eaa8ebd0b76..1f215eb8ad5d0 100644 --- a/modules/context/context_response.go +++ b/modules/context/context_response.go @@ -49,7 +49,7 @@ func (ctx *Context) RedirectToFirst(location ...string) { continue } - // Unfortunately browsers consider a redirect Location with preceding "//" and "/\" as meaning redirect to "http(s)://REST_OF_PATH" + // Unfortunately browsers consider a redirect Location with preceding "//", "\\" and "/\" as meaning redirect to "http(s)://REST_OF_PATH" // Therefore we should ignore these redirect locations to prevent open redirects if len(loc) > 1 && (loc[0] == '/' || loc[0] == '\\') && (loc[1] == '/' || loc[1] == '\\') { continue