How can I avoid a brakeman warning in Rails when constructing an order method from parameters?
def index
@methods = [:name, :manager, :deadline]
assignments = Assignment.order(sort_column(@methods) + " " + sort_direction).received(current_user).root
end
def sort_column(column_names)
column_names.each do |column|
return column if column == params[:sort]
end
return 'updated_at'
end
def sort_direction
params[:direction] == 'asc' ? 'asc' : 'desc'
end
I'm working hard to avoid ever putting user-generated code directly into the query, but brakeman still alerts (medium confidence) that this is a SQL injection vulnerability.
Is this a false positive? If not, how do I correct the vulnerability?
If so, is there an easy way to avoid the false positive?