私はそのような方法のコントローラーを持っています:
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
ブレーキマンジェムを介してアプリをスキャンしたところ、並べ替えのインデックスメソッドで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はまだ私が脆弱性を持っていると考えています。この問題を解決する正しい方法は何ですか?私は本当にそれをどうにかして対処する必要がありますか?