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

Filter out decrypted attributes in ActiveRecord #354

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

stevenjackson
Copy link

@stevenjackson stevenjackson commented Aug 21, 2019

e19445a introduced marking
attr_encrypted attributes as virtual attributes to avoid an ActiveRecord
deprecation warning in AR 5.1. This had the side effect of exposing
the decrypted versions of the attributes in
ActiveRecord::Base#attributes. This is problematic since the method
is leveraged for things like #as_json and respond_with, meaning a
user could inadvertely expose sensitive info with an action like:

  def show
    respond_with @user
  end

Closes #353

e19445a introduced marking
attr_encrypted attributes as virtual attributes to avoid an ActiveRecord
deprecation warning in AR 5.1.  This had the side effect of exposing
the decrypted versions of the attributes in
`ActiveRecord::Base#attributes`.  This is problematic since the method
is leveraged for things like `#as_json` and `respond_with`, meaning a
user could inadvertely expose sensitive info with an action like:

```
  def show
    respond_with @user
  end
```
def attributes
encrypted_keys = self.class.encrypted_attributes.keys
attributes_without_attr_encrypted.reject { |k, _| encrypted_keys.include?(k.to_sym) }
end
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess there is an inconsistency. #has_attribute? will return true for encrypted attributes as it relies on @attributes.

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

Successfully merging this pull request may close these issues.

Marking virtual attributes in Rails 5.1 may be exposing decrypted data
2 participants