我有这样的方法控制器:
def index
state = state_filter()
if state
...
else
@clients = Client.paginate(:page => params[:page], :per_page => 30).order(sort_column + ' ' + sort_direction)
end
end
...
def sort_direction
%w[asc desc].include?(params[:direction]) ? params[:direction] : "asc"
end
def sort_column
Client.column_names.include?(params[:sort]) ? params[:sort] : "title"
end
我通过brakeman gem扫描了我的应用程序,它发现我在排序的索引方法中可能有SQL 注入。我试图解决这个问题来重写我的方法,如下所示:
def sort_direction
case params[:direction]
when "asc" then "asc"
when "desc" then "desc"
else "asc"
end
end
def sort_column
case params[:sort]
when "title" then "title"
when "state" then "state"
when "created_at" then "created_at"
else "title"
end
end
但是 gem 仍然认为我有这个漏洞。解决此问题的正确方法是什么?我真的需要以某种方式处理吗?