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

ActiveSupport::KeyGenerator hash digest class differs during and after application initialization #51750

Open
victordesjardins opened this issue May 7, 2024 · 1 comment

Comments

@victordesjardins
Copy link

victordesjardins commented May 7, 2024

Since rails 7.0, default hash digest class for ActiveSupport::KeyGenerator is SHA256.
This SHA256 hash digest class is set through configuration in an after_initialize as found in ActiveSupport railtie.

The problem is that the source code for ActiveSupport::KeyGenerator defines a default SHA1 hash digest class if the configuration hash digest class have not been set up.
It means that using this KeyGenerator during application initialization (with SHA1) differs from using it after initialization (with SHA256).

Steps to reproduce

In any initializer file, print the hash digest class for ActiveSupport::KeyGenerator, let's say in app/config/initializers/digest_class.rb

p ActiveSupport::KeyGenerator.hash_digest_class

Then open a rails console in your local environment with config.eager_load = true
=> The initializer will print SHA1.
But if you print the same code in the console, it will print SHA256.

Expected behavior

I would expect the KeyGenerator to have the same behaviour during and after initialization.
Because for instance, if we generate a key in an initializer using ActiveSupport::KeyGenerator#generate_key, it will be a key generated with SHA1 hash digest class whereas we expect it to be generated with a SHA256 hash digest class.

Is there a reason why the hash digest class is set in an after_initialize ?

System configuration

Rails version:
7.0.7

Ruby version:
3.0.6

@zzak
Copy link
Member

zzak commented May 19, 2024

This is just how config and initialization works, I don't think we can change it.

The default value depends on the config.load_defaults target version

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants