2023-07-13 07:36:07 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2023-07-21 11:17:43 +00:00
|
|
|
# TODO: Remove after 4.2.0
|
|
|
|
Rails.application.configure do
|
|
|
|
config.active_support.key_generator_hash_digest_class = OpenSSL::Digest::SHA1
|
|
|
|
end
|
|
|
|
|
2023-07-13 07:36:07 +00:00
|
|
|
Rails.application.config.after_initialize do
|
|
|
|
Rails.application.config.action_dispatch.cookies_rotations.tap do |cookies|
|
|
|
|
authenticated_encrypted_cookie_salt = Rails.application.config.action_dispatch.authenticated_encrypted_cookie_salt
|
|
|
|
signed_cookie_salt = Rails.application.config.action_dispatch.signed_cookie_salt
|
|
|
|
|
|
|
|
secret_key_base = Rails.application.secret_key_base
|
|
|
|
|
2023-07-21 11:17:43 +00:00
|
|
|
# TODO: Switch to SHA1 after 4.2.0
|
2023-07-13 07:36:07 +00:00
|
|
|
key_generator = ActiveSupport::KeyGenerator.new(
|
2023-07-21 11:17:43 +00:00
|
|
|
secret_key_base, iterations: 1000, hash_digest_class: OpenSSL::Digest::SHA256
|
2023-07-13 07:36:07 +00:00
|
|
|
)
|
|
|
|
key_len = ActiveSupport::MessageEncryptor.key_len
|
|
|
|
|
|
|
|
old_encrypted_secret = key_generator.generate_key(authenticated_encrypted_cookie_salt, key_len)
|
|
|
|
old_signed_secret = key_generator.generate_key(signed_cookie_salt)
|
|
|
|
|
|
|
|
cookies.rotate :encrypted, old_encrypted_secret
|
|
|
|
cookies.rotate :signed, old_signed_secret
|
|
|
|
end
|
|
|
|
end
|