-
Notifications
You must be signed in to change notification settings - Fork 145
Remove unpermitted parameters warning #1301
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a fan of permitting everything and then slicing... Kind of goes against the right way to use action params. I preferred the original way.
That being said I thought params had a form of slice without the except 🤔
|
@Fryguy Yea, I don't like this either. Original codeparams.permit(:action, :controller, :format).to_hReads: Give me all parameters, and complain if there are any parameters besides Since there is almost always I wantedPlease give me params.slice(:action, :controller, :format)This was an error. Closest I could comeparams.permit!.to_h.slice(:action, :controller, :format)Punt on strong parameters. Just give me these 3 parameters.. |
| log_request("Request", @req.to_hash) | ||
| unfiltered_params = request.query_parameters | ||
| .merge(params.permit(:action, :controller, :format).to_h) | ||
| .merge(params.permit!.to_h.slice(:action, :controller, :format)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Think you can do
| .merge(params.permit!.to_h.slice(:action, :controller, :format)) | |
| .merge(params.slice(:action, :controller, :format).permit!) |
|
@kbrock How do you get the warning to appear for this with test code? I tried the following in rails console and I don't see anything: vmdb(dev)> p = ActionController::Parameters.new(:a => "1", :b => "2", :c => 3)
=> #<ActionController::Parameters {"a"=>"1", "b"=>"2", "c"=>3} permitted: false>
vmdb(dev)> p.permit(:a, :b).to_h
=> {"a"=>"1", "b"=>"2"} |
|
Oh i found a way after setting vmdb(dev)> p = ActionController::Parameters.new(:a => "1", :b => "2", :c => 3)
=> #<ActionController::Parameters {"a"=>"1", "b"=>"2", "c"=>3} permitted: false>
vmdb(dev)> p.permit(:a, :b).to_h
actionpack (7.2.3) lib/action_controller/metal/strong_parameters.rb:1112:in `unpermitted_parameters!': found unpermitted parameter: :c (ActionController::UnpermittedParameters)
vmdb(dev)> p.slice(:a, :b).permit!.to_h
=> {"a"=>"1", "b"=>"2"} |
We always pass a few parameters. these parameters come from query_parameters. These were triggering a warning in our logging. Rails adds parameters from routes and actionpack. like :c_id, :s_id, :action, :controller, :format We only care about a few of these. So only outputting the ones we care about and ignoring the rest ``` [----] D, [2025-10-28T23:00:25.289277#13035:5200] DEBUG -- : Unpermitted parameters: :expand, :attributes, :c_id. [...] ```
73e91a9 to
e4eec5c
Compare
|
Update:
This solution looked much closer to my preferred solution. Thanks for the help with a console reproducer. |
|
@kbrock Is there a spec that covers this line? |
|
@Fryguy So Post requests go through this. (Think Get requests do not - which is odd) I can't find a good way to test this. |
|
as long as tests would fail if an error was in there then I think we're covered. I was concerned specifically with the |
|
ugh I read |
|
Yes, |
pulled out of #1300 - it is unrelated
We always pass a few parameters. these parameters come from query_parameters.
These were triggering a warning in our logging.
Rails adds parameters from routes and actionpack. like :c_id, :s_id, :action, :controller, :format
We only care about a few of these. So only outputting the ones we care about and ignoring the rest
/cc @jrafanie not sure if you have an opinion on this