Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix default SameSite for session cookies #45688

Merged

Conversation

jonathanhefner
Copy link
Member

Follow-up to #45501.

The Rack base class that CookieStore inherits from always sets :same_site. Thus, options.key?(:same_site) always returns true for session cookies, preventing a default value from being set.

It would be possible to change Rack to conditionally set :same_site, but, from Rack's perspective, it has no reason to not set :same_site, because it treats a nil value the same as no value.

Therefore, this commit specifies a default :same_site in CookieStore, which simply defers to request.cookies_same_site_protection as CookieJar does.

Fixes #45681.

@rails-bot rails-bot bot added the actionpack label Jul 28, 2022
Follow-up to rails#45501.

The Rack base class that `CookieStore` inherits from [always sets
`:same_site`][1].  Thus, `options.key?(:same_site)` always returns true
for session cookies, preventing a default value from being set.

It would be possible to change Rack to conditionally set `:same_site`,
but, from Rack's perspective, it has no reason to not set `:same_site`,
because it treats a `nil` value the same as no value.

Therefore, this commit specifies a default `:same_site` in `CookieStore`,
which simply defers to `request.cookies_same_site_protection` as
`CookieJar` does.

Fixes rails#45681.

[1]: https://github.com/rack/rack/blob/2.2.4/lib/rack/session/abstract/id.rb#L398-L402
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

SameSite error logged in Firefox (rails/main)
1 participant