-
Notifications
You must be signed in to change notification settings - Fork 21.9k
Description
Steps to reproduce
Add an initiator with the following code as given in the documentation (https://api.rubyonrails.org/v8.0/classes/ActiveSupport/ParameterFilter.html )
Restart the server.
Save a record to the DB.
Check the server log and see that it does not filter the params value as expected.
#custom_logging_filter.rb
ActiveSupport::ParameterFilter.new([-> (k, v) do
v.reverse! if /test_field/i.match?(k)
end])
Expected behavior
Params value for the hash key test_field
should be reversed.
Actual behavior
They are untouched in both the http request log and in the DB save log.
System configuration
Rails version:
8.0.1
Ruby version:
ruby 3.3.0 (2023-12-25 revision 5124f9ac75) [x86_64-darwin24]
I removed the custom_logging_filter.rb
and added the Proc to the filter_parameter_logging.rb
initializer:
Rails.application.config.filter_parameters += [
:passw, :email, :secret, :token, :_key, :crypt, :salt, :certificate, :otp, :ssn, :cvv, :cvc, -> (k, v) do
v.reverse! if /test_field/i.match?(k)
end
]
On submitting the form with the value "goodbye" you get the filtering in the request log:
Processing by TestModelsController#update as TURBO_STREAM
Parameters: {"authenticity_token"=>"[FILTERED]", "test_model"=>{"test_field"=>"eybdoog"}, "commit"...
But the DB log still shows:
TRANSACTION (0.1ms) BEGIN immediate TRANSACTION /*action='update',application='FilteringTest',controller='test_models'*/
↳ app/controllers/test_models_controller.rb:40:in `block in update'
TestModel Update (3.4ms) UPDATE "test_models" SET "test_field" = 'goodbye', "updated_at" = '2025-01-02 ...
Strangely I used this same code in a new Rails 7.0.8.7 app with ruby 3.2.4 (2024-04-23 revision af471c0e01) [x86_64-darwin23] and the results are that the filtering happens in the DB call but NOT the browser request. So the opposite of what is happening with Rails 8.