-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Support for extra whitelisted params #1827
Comments
Oh, interesting! I don't think I've tried a subdomain for many years. I wonder if a configurable list is the best option here. Would you be able to provide an example of what that might look like? It'd be easier to think about with a sample. |
@nickcharlton I actually had a 2nd possible solution that I came up with in the meantime. So I'll leave both here 1 configurable listMy thinking would be something along these lines: class Administrate::ApplicationController
protected
def ignored_params
[]
end
end naming up for debate of course This would be the default implemented by the gem, which would give me the ability to override that method to return 2 Don't use strong parameters at allI was diving a bit more into administrate's code, and noticed that, while the strong_parameters API is used internally only within those 2 functions, the plain version (weak parameters?) is used in several places, to refer to So it actually looks to me like these functions are using strong_parameters, not for the security benefits, but for automatically filtering only the params they're interested in. So this 2nd proposal would be to refactor those two functions to not use strong_parameters, but instead use This would both fix the original issue, as well as make the gem's code more consistent, and compatible with suspenders' defaults (which, with both being thoughtbot projects, I imagine is something you'd want) Thoughts? |
Removing strong parameters does have some merit here, after looking at the code. I'm not seeing any obvious security issues if done correctly, and I'd prefer it over adding new interfaces. If only strong parameters had |
I'd support the idea of removing strong parameters as the right solution here. Is this something you might be able to take a look at, @naps62? |
I'm not actively using administrate anymore, but this is simple enough. I can give it a shot 👍 |
@nickcharlton After going a bit through the code, and the documentation for Taking one example: def sanitized_order_params(page, current_field_name)
collection_names = page.item_includes + [current_field_name]
association_params = collection_names.map do |assoc_name|
{ assoc_name => %i[order direction page per_page] }
end
params.permit(:search, :id, :_page, :per_page, association_params)
end We don't want to just revert to using raw so the "easy" way to get the same behaviour, but still allow for the possibility of extra params, would be the weird: permitted = [:search, :id, :_page, :per_page, association_params]
# take out the extra params before the #permit call
params.slice(*permitted).permit(*permitted) Which looks... weird, to say the least Thoughts? |
Thanks for looking into this! Yeah, agreed. It does look a little weird. I think my biggest concern here is opening up ourselves to a security vulnerability because we’re needing to work around something Rails does for us — which I’d expect an explicit allow list wouldn’t have (unless, I suppose, you allowed something you shouldn’t, but that’s on the user). For your original problem, would setting that sub domain parameter allowed on Administrate’s |
I think it would yes |
Sounds good to me. Want to provide a PR? |
Does someone have news about this feature request? 🙏 I'm in a similar situation: I have an Administrate plugin to use Ransack for some extra filters, but it requires a So as a workaround I have to override the I also think that removing strong parameters from index page queries looks like a good improvement. |
There may be a way to make this work while the "proper" feature is being developed. I just had to deal with it myself, and it may be of use to others. I had a param class Admin::ApplicationController < Administrate::ApplicationController
# ...
before_action :read_special_order
def read_special_order
@special_order = params.key?("special-order")
params.delete("special-order")
end
end Would this solve your problem? |
@pablobm: nice idea, thanks! 👍 |
Nevermind, in my case removing the query parameter in |
@blocknotes - It looks like the progress of that PR has stalled. Would you be able to provide your own one? |
I'm building an app based on both suspenders and administrate.
This means I have
config.action_controller.action_on_unpermitted_parameters = :raise
, and I'd like to keep it that wayAnother thing I have is the administrate panel under a subdomain:
This creates an unfortunate combination, where
subdomain: "admin"
is automatically added to the list of params, and the app later fails because administrate's own functionssanitized_order_params
andclear_search_params
don't expect extra params to be there, causing an exceptionSo far, I had to override those methods on
Admin::ApplicationController
:But I'm guessing a good solution would be to add a configurable list of permitted params, and have those two functions take that into account.
Or is there a better solution I might be missing?
PS: I'm willing to implement this myself, it's fairly straightforward. But I wanted feedback on the idea first
The text was updated successfully, but these errors were encountered: