-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Add new type encrypted_string for preferences #3676
Add new type encrypted_string for preferences #3676
Conversation
@stefano-sarioli thanks for this PR. I left a few comments, let me know what you think about them. |
@spaghetticode Hi, I've pushed my fix to your comment, thanks again for the feedback. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left a couple minor style-related comments.
backend/app/views/spree/admin/shared/preference_fields/_encrypted_string.html.erb
Outdated
Show resolved
Hide resolved
Encryptor is a thin wrapper around ActiveSupport::MessageEncryptor, it can be used when a simple encryption solution is needed. Encryptor does not have key management features, you have to generate, store, and rotate key by hand, if needed.
The new type encrypted_string encrypt the content of the preferences, the original value can be read-only using the preferences accessor method. It's still recommended to use env variables to manage secrets, but if it's needed to save the preference on the database, now it's possible to use encrypted_string to add a security layer. The encryption key can be passed using the encryption_key option of the preference, if the option is missing the system fallback to the env variable SOLIDUS_PREFERENCES_MASTER_KEY, it even this env variable is missing the system will use the Rails master key. If a default value it's assigned to an encrypted_string preference, this will not be encrypted.
On the backend encrypted_string preferences are treated like normal string, the are no differences for the end-user.
Update the documentation section about Preferences, now it explains all the setter/getter methods created for the preferences. The update is inspired by the Spree documentation about Preferences.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@stefano-sarioli thank you 👍
And thank you for updating the doc as well ❤️
Hi @jarednorman, does the change I made thanks to your feedbacks looks good to you? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, looks all good to me.
Description
This pull request wants to resolve the issue Ref #3652 adding a new type encrypted_string as a possible type when declaring preferences.
The new type encrypted_string would encrypt the value assigned to the preference so that when saved to a Database the value would be safe if a malicious actor gets access to the DB or a dump.
The value to be encrypted need to be set/get using the preferences setter and getter method, the encryption would be skipped if the preferences hash is accessed directly.
The idea behind this is that the value would always be encrypted inside the preferences' hash so that the end-user doesn't need to change the way it interacts with the preferences.
This implementation would not handle the encryption key, it's up to the end-user to safely generate, store, and rotate the key.
The key can be passed as an option to the preference (encryption_key), it the option is missing the system would look for an environment variable called SOLIDUS_PREFERENCES_MASTER_KEY, if even this variable is missing the system will use the Rails secret key.
I'm not sure that this solution would cover all the use cases that the author of the original issue had in mind, so I open the pull request as a draft to ask for feedback about possible missing use cases.
Checklist: