Skip to content

Commit

Permalink
feat: add CHIPS (partitioned) cookies
Browse files Browse the repository at this point in the history
  • Loading branch information
aeneasr committed Mar 1, 2024
1 parent 0421fda commit 282dedb
Show file tree
Hide file tree
Showing 4 changed files with 362 additions and 0 deletions.
1 change: 1 addition & 0 deletions consent/strategy_default.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ func (s *DefaultStrategy) revokeAuthenticationCookie(w http.ResponseWriter, r *h
cookie.Options.Path = s.c.SessionCookiePath(ctx)
cookie.Options.SameSite = s.c.CookieSameSiteMode(ctx)
cookie.Options.Secure = s.c.CookieSecure(ctx)
cookie.Options.Secure = s.c.CookieSecure(ctx)
cookie.Options.Domain = s.c.CookieDomain(ctx)
cookie.Options.MaxAge = -1

Expand Down
8 changes: 8 additions & 0 deletions driver/config/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ const (
KeyCookieSameSiteLegacyWorkaround = "serve.cookies.same_site_legacy_workaround"
KeyCookieDomain = "serve.cookies.domain"
KeyCookieSecure = "serve.cookies.secure"
KeyCookiePartitioned = "serve.cookies.partitioned"
KeyCookieLoginCSRFName = "serve.cookies.names.login_csrf"
KeyCookieConsentCSRFName = "serve.cookies.names.consent_csrf"
KeyCookieSessionName = "serve.cookies.names.session"
Expand Down Expand Up @@ -290,6 +291,13 @@ func (p *DefaultProvider) CookieSecure(ctx context.Context) bool {
return p.getProvider(ctx).BoolF(KeyCookieSecure, false)
}

func (p *DefaultProvider) CookiePartitioned(ctx context.Context) bool {
if !p.IsDevelopmentMode(ctx) {
return false

Check warning on line 296 in driver/config/provider.go

View check run for this annotation

Codecov / codecov/patch

driver/config/provider.go#L294-L296

Added lines #L294 - L296 were not covered by tests
}
return p.getProvider(ctx).BoolF(KeyCookiePartitioned, false)

Check warning on line 298 in driver/config/provider.go

View check run for this annotation

Codecov / codecov/patch

driver/config/provider.go#L298

Added line #L298 was not covered by tests
}

func (p *DefaultProvider) CookieSameSiteMode(ctx context.Context) http.SameSite {
sameSiteModeStr := p.getProvider(ctx).String(KeyCookieSameSiteMode)
switch strings.ToLower(sameSiteModeStr) {
Expand Down
Loading

0 comments on commit 282dedb

Please sign in to comment.