2012-06-17 68 views
0

那時我有以下行零級搜索標籤

@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 

,但我得到像`未定義,< <爲無:NilClass
我失去了什麼?

回答

1

如果你使用的是Mongodb,你可以確定你的代碼是免費的SQL注入。

儘管MongoDB不像SQL注入那樣容易受到攻擊,但它可能值得檢查搜索字符串是否有任何惡意。 mongodb tutorial

+0

這就是我的想法,但錯誤呢?我的代碼有什麼問題? –