Repository navigation
Tighten session cookies to SameSite=Lax and centralize the cookie attribute policy - #10
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
cookieauthsetSameSite=Noneon both the registry session-id cookie andNewCookieStore. Combined with no CSRF protection and bodyless POSTrevoke/logout endpoints, that let any site act on a visitor's session — logging
them out everywhere, at minimum. The rest of the library
(
attemptstore/cookie,pendingstore/cookie) was already onLax;cookieauthwas the outlier.What
auth/cookieauth/cookieattrs.gois the single source of truth forPath/HttpOnly/Secure/SameSite, applied byNewCookieStore,NewFsStoreand the registry flavour's hand-built cookie alike. Default isnow
SameSite=Lax.NewFsStoreno longer inherits gorilla's bare defaults, which carried noHttpOnly,SecureorSameSiteat all — weaker than either site the TODOnamed.
Cfg.SameSite(registry flavour, zero value →Lax) restores parity ofconfigurability: the stateless flavour could already reach these attributes
via
Store.Options, the registry flavour had no knob. Setting it alongsideCfg.Storeis a construction error, matching howHashKey/BlockKeyarerejected there; an out-of-range value is rejected too.
clearSIDnow derives the deletion cookie fromsidCookiewith a pastexpiry instead of duplicating the literal. A browser only replaces a cookie
when name/path/domain agree, so one builder is what keeps logout correct — and
it leaves a single
//nolint:gosec(down from two) on the one line thatdecides the policy.
both flavours' emitted cookies and their equality, login/logout attribute
match, the override table, and both rejection paths.
Notes
Behaviour change, no API removed and no data migration —
docs/agents/migration-cookie-samesite.mdcovers the two ways a consumer canbreak: a cross-site deployment (must opt back into
Noneand add its own CSRFprotection) and
NewFsStoreover plain HTTP (its cookies are nowSecure).Nothing in-tree uses
NewFsStore.