From 739d3013dd49f7b26ce25771763cbf9ef4ae02e7 Mon Sep 17 00:00:00 2001 From: Peter Sanchez Date: Fri, 3 Nov 2023 13:07:55 -0600 Subject: [PATCH] More work to test Safari session cookie bug --- sessions/echo_scs.go | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/sessions/echo_scs.go b/sessions/echo_scs.go index e97ac0b..c306c50 100644 --- a/sessions/echo_scs.go +++ b/sessions/echo_scs.go @@ -68,15 +68,20 @@ func LoadAndSaveWithConfig(config SessionConfig) echo.MiddlewareFunc { c.Response().Before(func() { if config.SessionManager.Status(ctx) != scs.Unmodified { - responseCookie := &http.Cookie{ - Name: config.SessionManager.Cookie.Name, - Path: config.SessionManager.Cookie.Path, - Domain: config.SessionManager.Cookie.Domain, - Secure: config.SessionManager.Cookie.Secure, - HttpOnly: config.SessionManager.Cookie.HttpOnly, - SameSite: config.SessionManager.Cookie.SameSite, - MaxAge: int(config.SessionManager.Lifetime), + responseCookie := new(http.Cookie) + responseCookie.Name = config.SessionManager.Cookie.Name + if config.SessionManager.Cookie.Path != "" { + responseCookie.Path = config.SessionManager.Cookie.Path } + if config.SessionManager.Cookie.Domain != "" { + responseCookie.Domain = config.SessionManager.Cookie.Domain + } + if config.SessionManager.Cookie.SameSite != http.SameSiteDefaultMode { + responseCookie.SameSite = config.SessionManager.Cookie.SameSite + } + responseCookie.Expires = time.Now().Add(config.SessionManager.Lifetime) + responseCookie.Secure = config.SessionManager.Cookie.Secure + responseCookie.HttpOnly = config.SessionManager.Cookie.HttpOnly switch config.SessionManager.Status(ctx) { case scs.Modified: -- 2.45.2