fix(19.3-06): zero CookieConfig writes SameSite=Lax and Secure (WR-09)

- withDefaults gives the zero config Secure and every unset SameSite Lax;
  a config with any field set keeps its Secure value
This commit is contained in:
Jakub Zych
2026-10-15 22:27:31 +02:00
parent 4dae8331c5
commit 85d8b6a85a
4 changed files with 30 additions and 8 deletions

View File

@@ -29,10 +29,12 @@ type CookieConfig struct {
Domain string
// Path is the cookie path (auth.cookie.path, default "/").
Path string
// Secure sends the cookie over https only.
// Secure sends the cookie over https only. It has no default except for
// the zero CookieConfig, which writes a Secure cookie; LoadCookieConfig
// derives it from app.url unless auth.cookie.secure is set.
Secure bool
// SameSite is http.SameSiteLaxMode unless auth.cookie.same_site says
// otherwise.
// SameSite is http.SameSiteLaxMode when unset (also on a hand-built
// config) and otherwise what auth.cookie.same_site says.
SameSite http.SameSite
}
@@ -263,9 +265,18 @@ func CookieLogoutHandler(opts CookieLogoutOptions) (http.Handler, error) {
}), nil
}
// withDefaults fills an empty Name and Path, so a zero CookieConfig writes
// the default token cookie on "/".
// withDefaults fills an empty Name and Path and an unset SameSite (Lax). The
// zero CookieConfig also gets Secure, so it writes the default token cookie
// on "/" with HttpOnly, SameSite=Lax and Secure; a config with any field set
// keeps its Secure value (LoadCookieConfig derives it from app.url).
// TokenCookie, ForgetTokenCookie and both handlers go through it.
func (c CookieConfig) withDefaults() CookieConfig {
if c == (CookieConfig{}) {
c.Secure = true
}
if c.SameSite == 0 {
c.SameSite = http.SameSiteLaxMode
}
if strings.TrimSpace(c.Name) == "" {
c.Name = DefaultCookieName
}