Skip to content

Commit

Permalink
Use SameSite=None for cookies.
Browse files Browse the repository at this point in the history
Chrome requires this (along with the Secure attribute and delivery over
HTTPS) for all third-party cookies (as of February).

https://web.dev/samesite-cookies-explained/
GabeIsman committed Sep 11, 2020

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 76cdf18 commit a49ec90
Showing 4 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
@@ -39,7 +39,7 @@ def current_user

user = User.find_by(id: cookies.signed[:user_id])
if user.present?
cookies.signed[:user_id] = { value: user.id, expires: 7.days.from_now, httponly: true }
cookies.signed[:user_id] = { value: user.id, expires: 7.days.from_now, httponly: true, same_site: :none, secure: true }
@current_user = user
else
cookies.signed[:user_id] = nil
2 changes: 1 addition & 1 deletion app/controllers/sessions_controller.rb
Original file line number Diff line number Diff line change
@@ -21,7 +21,7 @@ def token
if user[:expired]
redirect_to expired_token_path(user[:user].id)
else
cookies.signed[:user_id] = { value: user.id, expires: 7.days.from_now, httponly: true }
cookies.signed[:user_id] = { value: user.id, expires: 7.days.from_now, httponly: true, same_site: :none, secure: true }
redirect_to root_path
end
else
4 changes: 4 additions & 0 deletions config/environments/development.rb
Original file line number Diff line number Diff line change
@@ -38,6 +38,10 @@

config.action_mailer.delivery_method = :letter_opener

config.hosts << "klaxon.test"

config.force_ssl = (ENV.fetch('KLAXON_FORCE_SSL', 'false').to_s.downcase == 'true')

# Raises error for missing translations
# config.action_view.raise_on_missing_translations = true

2 changes: 1 addition & 1 deletion config/initializers/session_store.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Be sure to restart your server when you modify this file.

Rails.application.config.session_store :cookie_store, key: '_klaxon_session'
Rails.application.config.session_store :cookie_store, key: '_klaxon_session', same_site: :none, secure: true

0 comments on commit a49ec90

Please sign in to comment.