Strip subdomains from session cookie host

This commit is contained in:
Matt-Yorkley
2021-09-01 23:21:52 +01:00
parent fd8de65749
commit dc8939c35f
2 changed files with 9 additions and 3 deletions

View File

@@ -39,7 +39,7 @@ module Openfoodnetwork
SessionCookieUpgrader, {
old_key: "_session_id",
new_key: "_ofn_session_id",
domain: "." + ENV["SITE_URL"].delete_prefix("www.")
domain: ".#{ENV['SITE_URL'].gsub(/^(www\.)|^(app\.)|^(staging\.)|^(stg\.)/, '')}"
}
) if Rails.env.staging? || Rails.env.production?

View File

@@ -3,9 +3,15 @@
# Use the database for sessions instead of the cookie-based default,
# which shouldn't be used to store highly confidential information
# (create the session table with "rails generate session_migration")
domain = if Rails.env.staging? || Rails.env.production?
".#{ENV['SITE_URL'].gsub(/^(www\.)|^(app\.)|^(staging\.)|^(stg\.)/, '')}"
else
:all
end
Openfoodnetwork::Application.config.session_store(
:active_record_store,
key: "_ofn_session_id",
domain: :all,
tld_length: 2
domain: domain
)