提交 7d20655c 编写于 作者: J Justin Collins

CheckSQL: Add check for Model#select

上级 f494d0fd
......@@ -20,7 +20,7 @@ class Brakeman::CheckSQL < Brakeman::BaseCheck
:find, :find_by_sql, :first, :last, :maximum, :minimum, :sum]
if tracker.options[:rails3]
@sql_targets.concat [:from, :group, :having, :joins, :lock, :order, :reorder, :where]
@sql_targets.concat [:from, :group, :having, :joins, :lock, :order, :reorder, :select, :where]
end
Brakeman.debug "Finding possible SQL calls on models"
......@@ -159,7 +159,7 @@ class Brakeman::CheckSQL < Brakeman::BaseCheck
check_order_arguments args
when :joins
check_joins_arguments args[1]
when :from
when :from, :select
unsafe_sql? args[1]
when :lock
check_lock_arguments args[1]
......
......@@ -142,4 +142,12 @@ class Product < ActiveRecord::Base
Product.average(:price, :conditions => ["blah = #{params[:columns]} and x = ?", x])
Product.sum(params[:columns])
end
def test_select
#Should not warn
Product.select([:price, :sku])
#Should warn
Product.select params[:columns]
end
end
......@@ -15,7 +15,7 @@ class Rails31Tests < Test::Unit::TestCase
:model => 0,
:template => 2,
:controller => 1,
:warning => 35 }
:warning => 36 }
end
def test_without_protection
......@@ -351,6 +351,15 @@ class Rails31Tests < Test::Unit::TestCase
:file => /product\.rb/
end
def test_sql_injection_in_select
assert_warning :type => :warning,
:warning_type => "SQL Injection",
:line => 151,
:message => /^Possible\ SQL\ injection/,
:confidence => 0,
:file => /product\.rb/
end
def test_select_vulnerability
assert_warning :type => :template,
:warning_type => "Cross Site Scripting",
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册