From e1ec0ce7cf7e4f07473c173f31181945da8496ec Mon Sep 17 00:00:00 2001 From: Kensuke Kubo Date: Mon, 8 Nov 2021 17:44:46 +0900 Subject: [PATCH] fix: Session cookie option --- http/middleware/session.go | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/http/middleware/session.go b/http/middleware/session.go index c1612d9..4a362a0 100644 --- a/http/middleware/session.go +++ b/http/middleware/session.go @@ -15,17 +15,20 @@ type SessionOption struct { func Session(name []string, secret string, option *SessionOption) gin.HandlerFunc { var ( - corsSecure bool - corsSameSite http.SameSite + secure bool + sameSite http.SameSite ) switch gin.Mode() { case gin.ReleaseMode: - corsSecure = true - corsSameSite = http.SameSiteStrictMode + secure = true + sameSite = http.SameSiteStrictMode + case gin.TestMode: + secure = true + sameSite = http.SameSiteNoneMode case gin.DebugMode: - corsSecure = false - corsSameSite = http.SameSiteLaxMode + secure = false + sameSite = http.SameSiteLaxMode } var maxAge = time.Hour * 24 * 365 @@ -39,9 +42,9 @@ func Session(name []string, secret string, option *SessionOption) gin.HandlerFun sessions.Options{ Path: "/", MaxAge: int(maxAge), - Secure: corsSecure, + Secure: secure, HttpOnly: true, - SameSite: corsSameSite, + SameSite: sameSite, }, ) return sessions.SessionsMany(name, store)