@@ -57,8 +57,8 @@ func AutoSignIn(ctx *context.Context) (bool, error) {
5757 defer func () {
5858 if ! isSucceed {
5959 log .Trace ("auto-login cookie cleared: %s" , uname )
60- ctx .SetCookie (setting .CookieUserName , "" , - 1 , setting .AppSubURL )
61- ctx .SetCookie (setting .CookieRememberName , "" , - 1 , setting .AppSubURL )
60+ ctx .SetCookie (setting .CookieUserName , "" , - 1 , setting .AppSubURL , "" , setting . SessionConfig . Secure , true )
61+ ctx .SetCookie (setting .CookieRememberName , "" , - 1 , setting .AppSubURL , "" , setting . SessionConfig . Secure , true )
6262 }
6363 }()
6464
@@ -78,7 +78,7 @@ func AutoSignIn(ctx *context.Context) (bool, error) {
7878 isSucceed = true
7979 ctx .Session .Set ("uid" , u .ID )
8080 ctx .Session .Set ("uname" , u .Name )
81- ctx .SetCookie (setting .CSRFCookieName , "" , - 1 , setting .AppSubURL )
81+ ctx .SetCookie (setting .CSRFCookieName , "" , - 1 , setting .AppSubURL , "" , setting . SessionConfig . Secure , true )
8282 return true , nil
8383}
8484
@@ -92,13 +92,13 @@ func checkAutoLogin(ctx *context.Context) bool {
9292
9393 redirectTo := ctx .Query ("redirect_to" )
9494 if len (redirectTo ) > 0 {
95- ctx .SetCookie ("redirect_to" , redirectTo , 0 , setting .AppSubURL )
95+ ctx .SetCookie ("redirect_to" , redirectTo , 0 , setting .AppSubURL , "" , setting . SessionConfig . Secure , true )
9696 } else {
9797 redirectTo , _ = url .QueryUnescape (ctx .GetCookie ("redirect_to" ))
9898 }
9999
100100 if isSucceed {
101- ctx .SetCookie ("redirect_to" , "" , - 1 , setting .AppSubURL )
101+ ctx .SetCookie ("redirect_to" , "" , - 1 , setting .AppSubURL , "" , setting . SessionConfig . Secure , true )
102102 ctx .RedirectToFirst (redirectTo , setting .AppSubURL + string (setting .LandingPageURL ))
103103 return true
104104 }
@@ -443,9 +443,9 @@ func handleSignIn(ctx *context.Context, u *models.User, remember bool) {
443443func handleSignInFull (ctx * context.Context , u * models.User , remember bool , obeyRedirect bool ) string {
444444 if remember {
445445 days := 86400 * setting .LogInRememberDays
446- ctx .SetCookie (setting .CookieUserName , u .Name , days , setting .AppSubURL )
446+ ctx .SetCookie (setting .CookieUserName , u .Name , days , setting .AppSubURL , "" , setting . SessionConfig . Secure , true )
447447 ctx .SetSuperSecureCookie (base .EncodeMD5 (u .Rands + u .Passwd ),
448- setting .CookieRememberName , u .Name , days , setting .AppSubURL )
448+ setting .CookieRememberName , u .Name , days , setting .AppSubURL , "" , setting . SessionConfig . Secure , true )
449449 }
450450
451451 ctx .Session .Delete ("openid_verified_uri" )
@@ -469,10 +469,10 @@ func handleSignInFull(ctx *context.Context, u *models.User, remember bool, obeyR
469469 }
470470 }
471471
472- ctx .SetCookie ("lang" , u .Language , nil , setting .AppSubURL )
472+ ctx .SetCookie ("lang" , u .Language , nil , setting .AppSubURL , "" , setting . SessionConfig . Secure , true )
473473
474474 // Clear whatever CSRF has right now, force to generate a new one
475- ctx .SetCookie (setting .CSRFCookieName , "" , - 1 , setting .AppSubURL )
475+ ctx .SetCookie (setting .CSRFCookieName , "" , - 1 , setting .AppSubURL , "" , setting . SessionConfig . Secure , true )
476476
477477 // Register last login
478478 u .SetLastLogin ()
@@ -482,7 +482,7 @@ func handleSignInFull(ctx *context.Context, u *models.User, remember bool, obeyR
482482 }
483483
484484 if redirectTo , _ := url .QueryUnescape (ctx .GetCookie ("redirect_to" )); len (redirectTo ) > 0 && ! util .IsExternalURL (redirectTo ) {
485- ctx .SetCookie ("redirect_to" , "" , - 1 , setting .AppSubURL )
485+ ctx .SetCookie ("redirect_to" , "" , - 1 , setting .AppSubURL , "" , setting . SessionConfig . Secure , true )
486486 if obeyRedirect {
487487 ctx .RedirectToFirst (redirectTo )
488488 }
@@ -563,7 +563,7 @@ func handleOAuth2SignIn(u *models.User, gothUser goth.User, ctx *context.Context
563563 ctx .Session .Set ("uname" , u .Name )
564564
565565 // Clear whatever CSRF has right now, force to generate a new one
566- ctx .SetCookie (setting .CSRFCookieName , "" , - 1 , setting .AppSubURL )
566+ ctx .SetCookie (setting .CSRFCookieName , "" , - 1 , setting .AppSubURL , "" , setting . SessionConfig . Secure , true )
567567
568568 // Register last login
569569 u .SetLastLogin ()
@@ -573,7 +573,7 @@ func handleOAuth2SignIn(u *models.User, gothUser goth.User, ctx *context.Context
573573 }
574574
575575 if redirectTo , _ := url .QueryUnescape (ctx .GetCookie ("redirect_to" )); len (redirectTo ) > 0 {
576- ctx .SetCookie ("redirect_to" , "" , - 1 , setting .AppSubURL )
576+ ctx .SetCookie ("redirect_to" , "" , - 1 , setting .AppSubURL , "" , setting . SessionConfig . Secure , true )
577577 ctx .RedirectToFirst (redirectTo )
578578 return
579579 }
@@ -864,10 +864,10 @@ func SignOut(ctx *context.Context) {
864864 ctx .Session .Delete ("socialId" )
865865 ctx .Session .Delete ("socialName" )
866866 ctx .Session .Delete ("socialEmail" )
867- ctx .SetCookie (setting .CookieUserName , "" , - 1 , setting .AppSubURL )
868- ctx .SetCookie (setting .CookieRememberName , "" , - 1 , setting .AppSubURL )
869- ctx .SetCookie (setting .CSRFCookieName , "" , - 1 , setting .AppSubURL )
870- ctx .SetCookie ("lang" , "" , - 1 , setting .AppSubURL ) // Setting the lang cookie will trigger the middleware to reset the language ot previous state.
867+ ctx .SetCookie (setting .CookieUserName , "" , - 1 , setting .AppSubURL , "" , setting . SessionConfig . Secure , true )
868+ ctx .SetCookie (setting .CookieRememberName , "" , - 1 , setting .AppSubURL , "" , setting . SessionConfig . Secure , true )
869+ ctx .SetCookie (setting .CSRFCookieName , "" , - 1 , setting .AppSubURL , "" , setting . SessionConfig . Secure , true )
870+ 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.
871871 ctx .Redirect (setting .AppSubURL + "/" )
872872}
873873
0 commit comments