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

Encrypts :value encrypts every column named :value #106

Open
cmaxw opened this issue Nov 29, 2023 · 2 comments
Open

Encrypts :value encrypts every column named :value #106

cmaxw opened this issue Nov 29, 2023 · 2 comments

Comments

@cmaxw
Copy link

cmaxw commented Nov 29, 2023

My initializer: config/initializers/solid_cache.rb

# frozen_string_literal: true

ActiveSupport.on_load(:solid_cache_entry) do
  encrypts :value
end

I'm using the rails-settings-cached gem which creates a table with a :value column.

I have a setting called domain that I use in my from address in my mailer:

app/mailers/user_mailer.rb

class UserMailer < ApplicationMailer
  default from: "no-reply@#{Setting.domain}"

  def invite
    # do work
  end
end

The app failed to boot up because it was loading the domain setting from the Setting table and trying to decrypt my plaintext setting.

I removed the line from the mailer and it booted up and started getting ActiveRecord::Encryption::Errors::Decryption: ActiveRecord::Encryption::Errors::Decryption errors wherever I called the cache method in my views.

I removed the initializer and it went back to working albeit with the cache now running in plaintext.

Nothing I'm caching at the moment is sensitive. It's mostly just to speed up the website. However, if I end up needing it encrypted, I'd like it to work.

@brunoprietog
Copy link
Contributor

I wonder if it's a bug from rails-settings-cached. I made a sample repository and I can't reproduce it. Here it's.

Active Record Encryption was configured, the same initializer was set and there is a Setting model with key and value attributes.

Then, in the Rails console:

Setting.create(key: "cache_store", value: "solid_cache")

I don't see that it encrypts anything:

bruno@SurfaceBruno:~/solid_cache_encrypt$ bin/rails db
SQLite version 3.37.2 2022-01-06 13:25:41
Enter ".help" for usage hints.
sqlite> select * from settings;
1|cache_store|solid_cache|2023-12-20 10:49:15.694176|2023-12-20 10:49:15.694176
sqlite>

@cmaxw
Copy link
Author

cmaxw commented Dec 20, 2023

I'm wondering if it's because I already had values in settings and solid cache. I talked to someone who mentioned that I should try again with optional encryption turned on so it can read values that already exist in clear. I just haven't had a moment to see if that works.

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