Skip to content

Commit 8137932

Browse files
committed
Merge PR rails#44361
2 parents fb88db5 + 67d6183 commit 8137932

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

activerecord/lib/active_record/encryption/configurable.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,15 @@ def encrypted_attribute_was_declared(klass, name) # :nodoc:
5050

5151
def install_auto_filtered_parameters_hook(application) # :nodoc:
5252
ActiveRecord::Encryption.on_encrypted_attribute_declared do |klass, encrypted_attribute_name|
53-
application.config.filter_parameters << encrypted_attribute_name unless ActiveRecord::Encryption.config.excluded_from_filter_parameters.include?(encrypted_attribute_name)
53+
filter_parameter = [("#{klass.model_name.element}" if klass.name), encrypted_attribute_name.to_s].compact.join(".")
54+
application.config.filter_parameters << filter_parameter unless excluded_from_filter_parameters?(filter_parameter)
5455
end
5556
end
57+
58+
private
59+
def excluded_from_filter_parameters?(filter_parameter)
60+
ActiveRecord::Encryption.config.excluded_from_filter_parameters.find { |excluded_filter| excluded_filter.to_s == filter_parameter }
61+
end
5662
end
5763
end
5864
end

activerecord/test/cases/encryption/configurable_test.rb

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,19 @@ class ActiveRecord::Encryption::ConfigurableTest < ActiveRecord::EncryptionTestC
4141
assert_equal :isbn, @attribute_name
4242
end
4343

44-
test "install autofiltered params" do
44+
test "installing autofiltered parameters will add the encrypted attribute as a filter parameter using the dot notation" do
45+
application = OpenStruct.new(config: OpenStruct.new(filter_parameters: []))
46+
ActiveRecord::Encryption.install_auto_filtered_parameters_hook(application)
47+
48+
NamedPirate = Class.new(Pirate) do
49+
self.table_name = "pirates"
50+
end
51+
NamedPirate.encrypts :catchphrase
52+
53+
assert_includes application.config.filter_parameters, "named_pirate.catchphrase"
54+
end
55+
56+
test "installing autofiltered parameters will work with unnamed classes" do
4557
application = OpenStruct.new(config: OpenStruct.new(filter_parameters: []))
4658
ActiveRecord::Encryption.install_auto_filtered_parameters_hook(application)
4759

@@ -50,7 +62,7 @@ class ActiveRecord::Encryption::ConfigurableTest < ActiveRecord::EncryptionTestC
5062
encrypts :catchphrase
5163
end
5264

53-
assert_includes application.config.filter_parameters, :catchphrase
65+
assert_includes application.config.filter_parameters, "catchphrase"
5466
end
5567

5668
test "exclude the installation of autofiltered params" do

guides/source/active_record_encryption.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,8 @@ end
241241

242242
By default, encrypted columns are configured to be [automatically filtered in Rails logs](https://guides.rubyonrails.org/action_controller_overview.html#parameters-filtering). You can disable this behavior by adding the following to your `application.rb`:
243243

244+
When generating the filter parameter, it will use the model name as a prefix. E.g: For `Person#name` the filter parameter will be `person.name`.
245+
244246
```ruby
245247
config.active_record.encryption.add_to_filter_parameters = false
246248
```

0 commit comments

Comments
 (0)