Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generate a URL from non-sanitized request parameters

I am getting this error when i try to use the code below,

link_to params.merge(:sort => column, :direction => direction, :page => nil) do
      "#{title} #{content_tag(:i, "", class: "fa fa-chevron-#{direction == 'asc' ? 'up': 'down'}") }".html_safe
    end

specifically seems to happen when i add params.merge there. What is the real cause and what should i do?

full error message

Attempting to generate a URL from non-sanitized request parameters! An attacker can inject malicious data into the generated URL, such as changing the host. Whitelist and sanitize passed parameters to be secure.

using Rails version 5.

like image 208
Petros Kyriakou Avatar asked Jul 11 '16 13:07

Petros Kyriakou


2 Answers

Just use the normal strong parameters feature of Rails to whitelist good params. You don't have to define a method as suggested in the guide, just call params.permit(...) wherever you need it, e.g.:

link_to "asdf", params.permit(:page, :customer_id).merge(sort: column)

Using params.permit! allows all params (basically dodges the new security check) and is thus not recommended.

like image 72
iGEL Avatar answered Oct 18 '22 09:10

iGEL


For anybody new to rails that hit such thing, it is about doing params.permit! ideally after actually validating these params.

I tried to use smart_lists gem which appears to not be rails 5 compatible yet. For me it was about looking at the backtrace to see where the freakin params are used so I can permit them. Again, depending on usage, permitting should be done after proper validation.

like image 1
akostadinov Avatar answered Oct 18 '22 09:10

akostadinov