0

를 사용하여, Brakeman 1.8.3이 모델에서 다음 코드에 대한 높은 신뢰 SQL 주입 경고 제기레일 동수 SQL 주입 경고 내 레일 3.2 응용 프로그램을 Arel 구문

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 

이 거짓 포지인가 tive 또는 Arel 구문이나 또는 to_sql 메소드와 관련이있는 경우 ...? 두 가지 예에서 실행되는 실제 코드와 경고를 보증하는 코드의 차이점을 이해할 수 없습니다.

답변

3

거짓 긍정입니다.

이 경우 Brakeman은 Relationship이 모델이고 selectwhere이 쿼리 메서드임을 알고 있습니다. 따라서 Relationship.select(...).where(...).to_sql은 레코드 속성 (잠재적으로 위험)이라고 가정합니다. 하지만 to_sql은 언급 한대로 쿼리 용 SQL 코드를 생성하기 때문에 사용해서는 안됩니다. 내가 고칠거야.

물론 두 번째 버전은 문자열 리터럴을 보간하기 때문에 경고하지 않습니다.

+0

내가 대답 할 수있는 최선의 답변! 매우 감사합니다! –

+1

도와 드리겠습니다. 수정은 [여기] (https://github.com/presidentbeef/brakeman/pull/194)입니다. – Justin

관련 문제