我有一个方法,下面一行
@noticias = Noticia.where(:tags.all => array).paginate(:page => params[:page])
碰巧brakeman
说它有一个可能的SQL注入。我尝试了以下方法:
array = params[:query].split(' ')
array.each_with_index do |query, index|
array[index] = array[index].gsub(/</?[^>]*>/, "").downcase
end
array.each do |tag|
@noticias << Noticia.where(:tags => tag)
end
但我得到了类似"nil:NilClass
的未定义<<"之类的东西我错过了什么?
如果你使用的是Mongodb,你可以确定你的代码是无SQL注入的。
尽管MongoDB不容易受到SQL注入之类的攻击,但可能值得检查搜索字符串是否存在任何恶意内容。 蒙戈德布教程