Rails 3.2アプリでは、Brakeman 1.8.3により、モデル内の次のコードに対して高信頼性SQLインジェクション警告が発生します。
micropost.rb
def self.from_users_followed_by(user)
followed_user_ids = Relationship.select(:followed_id).
where("follower_id = :user_id").
to_sql
where("user_id IN (#{followed_user_ids}) OR user_id = :user_id",
user_id: user.id)
end
ただし、Arel構文を使用しないようにコードを変更しても、警告は発生しません。
def self.from_users_followed_by(user)
followed_user_ids = "SELECT followed_id FROM relationships
WHERE follower_id = :user_id"
where("user_id IN (#{followed_user_ids}) OR user_id = :user_id",
user_id: user.id)
end
これは誤検知ですか、それともArel構文またはto_sql
メソッドと関係がありますか...?警告を正当化する2つの例で実行される実際のコードの違いが何であるかわかりません。