@@ -56,8 +56,8 @@ func AutoSignIn(ctx *context.Context) (bool, error) {
5656 defer func () {
5757 if ! isSucceed {
5858 log .Trace ("auto-login cookie cleared: %s" , uname )
59- ctx .SetCookie (setting .CookieUserName , "" , - 1 , setting .AppSubURL )
60- ctx .SetCookie (setting .CookieRememberName , "" , - 1 , setting .AppSubURL )
59+ ctx .SetCookie (setting .CookieUserName , "" , - 1 , setting .AppSubURL , "" , setting . SessionConfig . Secure , true )
60+ ctx .SetCookie (setting .CookieRememberName , "" , - 1 , setting .AppSubURL , "" , setting . SessionConfig . Secure , true )
6161 }
6262 }()
6363
@@ -77,7 +77,7 @@ func AutoSignIn(ctx *context.Context) (bool, error) {
7777 isSucceed = true
7878 ctx .Session .Set ("uid" , u .ID )
7979 ctx .Session .Set ("uname" , u .Name )
80- ctx .SetCookie (setting .CSRFCookieName , "" , - 1 , setting .AppSubURL )
80+ ctx .SetCookie (setting .CSRFCookieName , "" , - 1 , setting .AppSubURL , "" , setting . SessionConfig . Secure , true )
8181 return true , nil
8282}
8383
@@ -91,13 +91,13 @@ func checkAutoLogin(ctx *context.Context) bool {
9191
9292 redirectTo := ctx .Query ("redirect_to" )
9393 if len (redirectTo ) > 0 {
94- ctx .SetCookie ("redirect_to" , redirectTo , 0 , setting .AppSubURL )
94+ ctx .SetCookie ("redirect_to" , redirectTo , 0 , setting .AppSubURL , "" , setting . SessionConfig . Secure , true )
9595 } else {
9696 redirectTo , _ = url .QueryUnescape (ctx .GetCookie ("redirect_to" ))
9797 }
9898
9999 if isSucceed {
100- ctx .SetCookie ("redirect_to" , "" , - 1 , setting .AppSubURL )
100+ ctx .SetCookie ("redirect_to" , "" , - 1 , setting .AppSubURL , "" , setting . SessionConfig . Secure , true )
101101 ctx .RedirectToFirst (redirectTo , setting .AppSubURL + string (setting .LandingPageURL ))
102102 return true
103103 }
@@ -438,9 +438,9 @@ func handleSignIn(ctx *context.Context, u *models.User, remember bool) {
438438func handleSignInFull (ctx * context.Context , u * models.User , remember bool , obeyRedirect bool ) string {
439439 if remember {
440440 days := 86400 * setting .LogInRememberDays
441- ctx .SetCookie (setting .CookieUserName , u .Name , days , setting .AppSubURL )
441+ ctx .SetCookie (setting .CookieUserName , u .Name , days , setting .AppSubURL , "" , setting . SessionConfig . Secure , true )
442442 ctx .SetSuperSecureCookie (base .EncodeMD5 (u .Rands + u .Passwd ),
443- setting .CookieRememberName , u .Name , days , setting .AppSubURL )
443+ setting .CookieRememberName , u .Name , days , setting .AppSubURL , "" , setting . SessionConfig . Secure , true )
444444 }
445445
446446 ctx .Session .Delete ("openid_verified_uri" )
@@ -464,10 +464,10 @@ func handleSignInFull(ctx *context.Context, u *models.User, remember bool, obeyR
464464 }
465465 }
466466
467- ctx .SetCookie ("lang" , u .Language , nil , setting .AppSubURL )
467+ ctx .SetCookie ("lang" , u .Language , nil , setting .AppSubURL , "" , setting . SessionConfig . Secure , true )
468468
469469 // Clear whatever CSRF has right now, force to generate a new one
470- ctx .SetCookie (setting .CSRFCookieName , "" , - 1 , setting .AppSubURL )
470+ ctx .SetCookie (setting .CSRFCookieName , "" , - 1 , setting .AppSubURL , "" , setting . SessionConfig . Secure , true )
471471
472472 // Register last login
473473 u .SetLastLogin ()
@@ -477,7 +477,7 @@ func handleSignInFull(ctx *context.Context, u *models.User, remember bool, obeyR
477477 }
478478
479479 if redirectTo , _ := url .QueryUnescape (ctx .GetCookie ("redirect_to" )); len (redirectTo ) > 0 && ! util .IsExternalURL (redirectTo ) {
480- ctx .SetCookie ("redirect_to" , "" , - 1 , setting .AppSubURL )
480+ ctx .SetCookie ("redirect_to" , "" , - 1 , setting .AppSubURL , "" , setting . SessionConfig . Secure , true )
481481 if obeyRedirect {
482482 ctx .RedirectToFirst (redirectTo )
483483 }
@@ -558,7 +558,7 @@ func handleOAuth2SignIn(u *models.User, gothUser goth.User, ctx *context.Context
558558 ctx .Session .Set ("uname" , u .Name )
559559
560560 // Clear whatever CSRF has right now, force to generate a new one
561- ctx .SetCookie (setting .CSRFCookieName , "" , - 1 , setting .AppSubURL )
561+ ctx .SetCookie (setting .CSRFCookieName , "" , - 1 , setting .AppSubURL , "" , setting . SessionConfig . Secure , true )
562562
563563 // Register last login
564564 u .SetLastLogin ()
@@ -568,7 +568,7 @@ func handleOAuth2SignIn(u *models.User, gothUser goth.User, ctx *context.Context
568568 }
569569
570570 if redirectTo , _ := url .QueryUnescape (ctx .GetCookie ("redirect_to" )); len (redirectTo ) > 0 {
571- ctx .SetCookie ("redirect_to" , "" , - 1 , setting .AppSubURL )
571+ ctx .SetCookie ("redirect_to" , "" , - 1 , setting .AppSubURL , "" , setting . SessionConfig . Secure , true )
572572 ctx .RedirectToFirst (redirectTo )
573573 return
574574 }
@@ -844,10 +844,10 @@ func SignOut(ctx *context.Context) {
844844 ctx .Session .Delete ("socialId" )
845845 ctx .Session .Delete ("socialName" )
846846 ctx .Session .Delete ("socialEmail" )
847- ctx .SetCookie (setting .CookieUserName , "" , - 1 , setting .AppSubURL )
848- ctx .SetCookie (setting .CookieRememberName , "" , - 1 , setting .AppSubURL )
849- ctx .SetCookie (setting .CSRFCookieName , "" , - 1 , setting .AppSubURL )
850- ctx .SetCookie ("lang" , "" , - 1 , setting .AppSubURL ) // Setting the lang cookie will trigger the middleware to reset the language ot previous state.
847+ ctx .SetCookie (setting .CookieUserName , "" , - 1 , setting .AppSubURL , "" , setting . SessionConfig . Secure , true )
848+ ctx .SetCookie (setting .CookieRememberName , "" , - 1 , setting .AppSubURL , "" , setting . SessionConfig . Secure , true )
849+ ctx .SetCookie (setting .CSRFCookieName , "" , - 1 , setting .AppSubURL , "" , setting . SessionConfig . Secure , true )
850+ ctx .SetCookie ("lang" , "" , - 1 , setting .AppSubURL , "" , setting . SessionConfig . Secure , true ) // Setting the lang cookie will trigger the middleware to reset the language ot previous state.
851851 ctx .Redirect (setting .AppSubURL + "/" )
852852}
853853
0 commit comments