Revert "DEV: Migrate existing cookies to Rails 7 format"

This reverts commit 66e8fe9cc63b86ce83b380a2c9563723affefffa as it
unexpectedly caused some users to be logged out. We are investigating
the problem.
This commit is contained in:
Loïc Guitaut
2023-01-12 12:01:20 +01:00
committed by Loïc Guitaut
parent 66e8fe9cc6
commit 4093fc6074
4 changed files with 4 additions and 64 deletions

View File

@ -1,34 +0,0 @@
# frozen_string_literal: true
# Implementing cookies rotator for Rails 7+ as a middleware because this will
# work in single site mode AND in multisite mode without leaking anything in
# `Rails.application.config.action_dispatch.cookies_rotations`.
module Middleware
class CookiesRotator
def initialize(app)
@app = app
end
def call(env)
request = ActionDispatch::Request.new(env)
env[
ActionDispatch::Cookies::COOKIES_ROTATIONS
] = ActiveSupport::Messages::RotationConfiguration.new.tap do |cookies|
key_generator =
ActiveSupport::KeyGenerator.new(
request.secret_key_base,
iterations: 1000,
hash_digest_class: OpenSSL::Digest::SHA1,
)
key_len = ActiveSupport::MessageEncryptor.key_len
cookies.rotate(
:encrypted,
key_generator.generate_key(request.authenticated_encrypted_cookie_salt, key_len),
)
cookies.rotate(:signed, key_generator.generate_key(request.signed_cookie_salt))
end
@app.call(env)
end
end
end