Skip to content

Commit 6f2e1bd

Browse files
mrsdizzietechknowlogick
authored andcommitted
Don't Unescape redirect_to cookie value (#6399)
redirect_to holds a value that we want to redirect back to after login. This value can be a path with intentonally escaped values and we should not unescape it. Fixes #4475
1 parent 6d345e0 commit 6f2e1bd

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

routers/user/auth.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"errors"
1010
"fmt"
1111
"net/http"
12-
"net/url"
1312
"strings"
1413

1514
"code.gitea.io/gitea/models"
@@ -96,7 +95,7 @@ func checkAutoLogin(ctx *context.Context) bool {
9695
if len(redirectTo) > 0 {
9796
ctx.SetCookie("redirect_to", redirectTo, 0, setting.AppSubURL, "", setting.SessionConfig.Secure, true)
9897
} else {
99-
redirectTo, _ = url.QueryUnescape(ctx.GetCookie("redirect_to"))
98+
redirectTo = ctx.GetCookie("redirect_to")
10099
}
101100

102101
if isSucceed {
@@ -496,7 +495,7 @@ func handleSignInFull(ctx *context.Context, u *models.User, remember bool, obeyR
496495
return setting.AppSubURL + "/"
497496
}
498497

499-
if redirectTo, _ := url.QueryUnescape(ctx.GetCookie("redirect_to")); len(redirectTo) > 0 && !util.IsExternalURL(redirectTo) {
498+
if redirectTo := ctx.GetCookie("redirect_to"); len(redirectTo) > 0 && !util.IsExternalURL(redirectTo) {
500499
ctx.SetCookie("redirect_to", "", -1, setting.AppSubURL, "", setting.SessionConfig.Secure, true)
501500
if obeyRedirect {
502501
ctx.RedirectToFirst(redirectTo)
@@ -587,7 +586,7 @@ func handleOAuth2SignIn(u *models.User, gothUser goth.User, ctx *context.Context
587586
return
588587
}
589588

590-
if redirectTo, _ := url.QueryUnescape(ctx.GetCookie("redirect_to")); len(redirectTo) > 0 {
589+
if redirectTo := ctx.GetCookie("redirect_to"); len(redirectTo) > 0 {
591590
ctx.SetCookie("redirect_to", "", -1, setting.AppSubURL, "", setting.SessionConfig.Secure, true)
592591
ctx.RedirectToFirst(redirectTo)
593592
return
@@ -1298,7 +1297,7 @@ func MustChangePasswordPost(ctx *context.Context, cpt *captcha.Captcha, form aut
12981297

12991298
log.Trace("User updated password: %s", u.Name)
13001299

1301-
if redirectTo, _ := url.QueryUnescape(ctx.GetCookie("redirect_to")); len(redirectTo) > 0 && !util.IsExternalURL(redirectTo) {
1300+
if redirectTo := ctx.GetCookie("redirect_to"); len(redirectTo) > 0 && !util.IsExternalURL(redirectTo) {
13021301
ctx.SetCookie("redirect_to", "", -1, setting.AppSubURL)
13031302
ctx.RedirectToFirst(redirectTo)
13041303
return

routers/user/auth_openid.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func SignInOpenID(ctx *context.Context) {
4747
if len(redirectTo) > 0 {
4848
ctx.SetCookie("redirect_to", redirectTo, 0, setting.AppSubURL, "", setting.SessionConfig.Secure, true)
4949
} else {
50-
redirectTo, _ = url.QueryUnescape(ctx.GetCookie("redirect_to"))
50+
redirectTo = ctx.GetCookie("redirect_to")
5151
}
5252

5353
if isSucceed {

0 commit comments

Comments
 (0)