提交 156555bf 编写于 作者: J Justin Collins

Only warn on subclasses of ActiveRecord::Base

in SQL injection, format validation, mass assignment,
and CVE-2010-3933 checks.

Should fix #107
上级 4624cd1c
...@@ -27,7 +27,7 @@ class Brakeman::CheckNestedAttributes < Brakeman::BaseCheck ...@@ -27,7 +27,7 @@ class Brakeman::CheckNestedAttributes < Brakeman::BaseCheck
end end
def uses_nested_attributes? def uses_nested_attributes?
tracker.models.each do |name, model| active_record_models.each do |name, model|
return true if model[:options][:accepts_nested_attributes_for] return true if model[:options][:accepts_nested_attributes_for]
end end
......
...@@ -24,7 +24,7 @@ class Brakeman::CheckSQL < Brakeman::BaseCheck ...@@ -24,7 +24,7 @@ class Brakeman::CheckSQL < Brakeman::BaseCheck
end end
Brakeman.debug "Finding possible SQL calls on models" Brakeman.debug "Finding possible SQL calls on models"
calls = tracker.find_call :targets => tracker.models.keys, calls = tracker.find_call :targets => active_record_models.keys,
:methods => @sql_targets, :methods => @sql_targets,
:chained => true :chained => true
...@@ -57,7 +57,7 @@ class Brakeman::CheckSQL < Brakeman::BaseCheck ...@@ -57,7 +57,7 @@ class Brakeman::CheckSQL < Brakeman::BaseCheck
scope_calls = [] scope_calls = []
if version_between? "2.1.0", "3.0.9" if version_between? "2.1.0", "3.0.9"
tracker.models.each do |name, model| active_record_models.each do |name, model|
if model[:options][:named_scope] if model[:options][:named_scope]
model[:options][:named_scope].each do |args| model[:options][:named_scope].each do |args|
call = Sexp.new(:call, nil, :named_scope, args).line(args.line) call = Sexp.new(:call, nil, :named_scope, args).line(args.line)
...@@ -66,7 +66,7 @@ class Brakeman::CheckSQL < Brakeman::BaseCheck ...@@ -66,7 +66,7 @@ class Brakeman::CheckSQL < Brakeman::BaseCheck
end end
end end
elsif version_between? "3.1.0", "3.9.9" elsif version_between? "3.1.0", "3.9.9"
tracker.models.each do |name, model| active_record_models.each do |name, model|
if model[:options][:scope] if model[:options][:scope]
model[:options][:scope].each do |args| model[:options][:scope].each do |args|
second_arg = args[2] second_arg = args[2]
......
...@@ -15,7 +15,7 @@ class Brakeman::CheckValidationRegex < Brakeman::BaseCheck ...@@ -15,7 +15,7 @@ class Brakeman::CheckValidationRegex < Brakeman::BaseCheck
WITH = Sexp.new(:lit, :with) WITH = Sexp.new(:lit, :with)
def run_check def run_check
tracker.models.each do |name, model| active_record_models.each do |name, model|
@current_model = name @current_model = name
format_validations = model[:options][:validates_format_of] format_validations = model[:options][:validates_format_of]
if format_validations if format_validations
......
...@@ -14,17 +14,10 @@ class Brakeman::CheckWithoutProtection < Brakeman::BaseCheck ...@@ -14,17 +14,10 @@ class Brakeman::CheckWithoutProtection < Brakeman::BaseCheck
return return
end end
models = [] return if active_record_models.empty?
tracker.models.each do |name, m|
if ancestor? m, :"ActiveRecord::Base"
models << name
end
end
return if models.empty?
Brakeman.debug "Finding all mass assignments" Brakeman.debug "Finding all mass assignments"
calls = tracker.find_call :targets => models, :methods => [:new, calls = tracker.find_call :targets => active_record_models.keys, :methods => [:new,
:attributes=, :attributes=,
:update_attributes, :update_attributes,
:update_attributes!, :update_attributes!,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册