Suggestion: It would be nice to have full control over ActionDispatch parameter filtering

Hello,

I needed to filter a “data” parameter for one of my controllers, but this is a very generic word, so I didn’t really want to filter every instance of this key for all of my controllers.

The current implementation of “config.filter_parameters” was not flexible enough for me to write this kind of custom logic. So I wrote a monkey patch for ‘action_dispatch/http/parameter_filter’, and added the concept of CustomFilter classes (name needs some work.) My idea is that you can create a subclass from ActionDispatch::Http::ParameterFilter::CustomFilter, and then write a custom filter method that receives the params Hash, and returns a filtered hash.

I use this to look at the “controller” and “action” keys, so I can set up different filtering for different controllers.

Here is a Gist with the code that I’m using: https://gist.github.com/ndbroadbent/0f9e01af5f03be81580e7792e85ffbb7

I think this does the job for my application, so I wanted to see if this might be useful for other people. If so, I would be happy to work on a PR.

Thanks,

Nathan