Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails Filter Parameters Filtering Too Much

In my filter parameters initializer, I'm filtering out all password related parameters that matter already:

# config/initializers/filter_parameter_logging.rb
Rails.application.config.filter_parameters += [:password, :password_confirmation]

But more parameters are being filtered out than I'd expect. It looks like anything that has "password" in the name filtered from the logs.

 {"password_invite_form"=>"[FILTERED]"}

Is there any way to prevent pattern matching for filtered parameters and match the precise parameters that I have set?

like image 733
fny Avatar asked Dec 19 '22 06:12

fny


1 Answers

You can use a regular expression, rather than a string or symbol, if you want to explicitly control the pattern matching.

# config/initializers/filter_parameter_logging.rb
Rails.application.config.filter_parameters += [/^password$/, /^password_confirmation$/]

This will tell Rails to filter "password" and "password_confirmation" exactly, but not filter other parameters that contain "password" as a substring.

like image 90
Matt Brictson Avatar answered Jan 01 '23 00:01

Matt Brictson