提交 0c37f7de 编写于 作者: J Justin

Merge pull request #439 from presidentbeef/active_record_base_connect_sqli

Also catch #connection calls on ActiveRecord::Base
...@@ -40,7 +40,7 @@ class Brakeman::CheckSQL < Brakeman::BaseCheck ...@@ -40,7 +40,7 @@ class Brakeman::CheckSQL < Brakeman::BaseCheck
Brakeman.debug "Finding possible SQL calls using constantized()" Brakeman.debug "Finding possible SQL calls using constantized()"
calls.concat tracker.find_call(:methods => @sql_targets).select { |result| constantize_call? result } calls.concat tracker.find_call(:methods => @sql_targets).select { |result| constantize_call? result }
connect_targets = active_record_models.keys << nil connect_targets = active_record_models.keys + [nil, :"ActiveRecord::Base"]
calls.concat tracker.find_call(:targets => connect_targets, :methods => @connection_calls, :chained => true).select { |result| connect_call? result } calls.concat tracker.find_call(:targets => connect_targets, :methods => @connection_calls, :chained => true).select { |result| connect_call? result }
Brakeman.debug "Finding calls to named_scope or scope" Brakeman.debug "Finding calls to named_scope or scope"
...@@ -556,11 +556,13 @@ class Brakeman::CheckSQL < Brakeman::BaseCheck ...@@ -556,11 +556,13 @@ class Brakeman::CheckSQL < Brakeman::BaseCheck
if call? target and target.method == :connection if call? target and target.method == :connection
target = target.target target = target.target
klass = class_name(target)
target.nil? or target.nil? or
target == SELF_CLASS or target == SELF_CLASS or
node_type? target, :self or node_type? target, :self or
active_record_models.include? class_name(target) klass == :"ActiveRecord::Base" or
active_record_models.include? klass
end end
end end
......
...@@ -21,4 +21,13 @@ class User < ActiveRecord::Base ...@@ -21,4 +21,13 @@ class User < ActiveRecord::Base
User.find(:all, :conditions => self.merge_conditions(some_conditions)) User.find(:all, :conditions => self.merge_conditions(some_conditions))
find(:all, :conditions => User.merge_conditions(some_conditions)) find(:all, :conditions => User.merge_conditions(some_conditions))
end end
def self.some_method(value)
results = ActiveRecord::Base.connection.execute(%Q(SELECT
id
FROM
table t
WHERE
t.something = '#{value}'))
end
end end
...@@ -12,13 +12,13 @@ class Rails2Tests < Test::Unit::TestCase ...@@ -12,13 +12,13 @@ class Rails2Tests < Test::Unit::TestCase
:controller => 1, :controller => 1,
:model => 3, :model => 3,
:template => 45, :template => 45,
:generic => 48 } :generic => 49 }
else else
@expected ||= { @expected ||= {
:controller => 1, :controller => 1,
:model => 3, :model => 3,
:template => 45, :template => 45,
:generic => 49 } :generic => 50 }
end end
end end
...@@ -611,6 +611,18 @@ class Rails2Tests < Test::Unit::TestCase ...@@ -611,6 +611,18 @@ class Rails2Tests < Test::Unit::TestCase
:file => /user\.rb/, :file => /user\.rb/,
:relative_path => "app/models/user.rb" :relative_path => "app/models/user.rb"
end end
def test_sql_injection_active_record_base_connection
assert_warning :type => :warning,
:warning_code => 0,
:fingerprint => "37885d589fc5c41553dcc38b36b506c2e508d1f37ce040eb6dca92a958f858fb",
:warning_type => "SQL Injection",
:line => 26,
:message => /^Possible\ SQL\ injection/,
:confidence => 1,
:relative_path => "app/models/user.rb",
:user_input => s(:lvar, :value)
end
def test_escape_once def test_escape_once
results = find :type => :template, results = find :type => :template,
...@@ -1252,13 +1264,13 @@ class Rails2WithOptionsTests < Test::Unit::TestCase ...@@ -1252,13 +1264,13 @@ class Rails2WithOptionsTests < Test::Unit::TestCase
:controller => 1, :controller => 1,
:model => 4, :model => 4,
:template => 45, :template => 45,
:generic => 48 } :generic => 49 }
else else
@expected ||= { @expected ||= {
:controller => 1, :controller => 1,
:model => 4, :model => 4,
:template => 45, :template => 45,
:generic => 49 } :generic => 50 }
end end
end end
......
...@@ -3,9 +3,9 @@ class TestTabsOutput < Test::Unit::TestCase ...@@ -3,9 +3,9 @@ class TestTabsOutput < Test::Unit::TestCase
def test_reported_warnings def test_reported_warnings
if Brakeman::Scanner::RUBY_1_9 if Brakeman::Scanner::RUBY_1_9
assert_equal 98, Report.lines.to_a.count
else
assert_equal 99, Report.lines.to_a.count assert_equal 99, Report.lines.to_a.count
else
assert_equal 100, Report.lines.to_a.count
end end
end end
end end
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册