Sha256: 37357de974744132b935e7ea285892a4189038a86f5eb8eb3a6790d1c89c9250
Contents?: true
Size: 1.63 KB
Versions: 2
Compression:
Stored size: 1.63 KB
Contents
require 'brakeman/checks/base_check' #Check for bypassing mass assignment protection #with without_protection => true # #Only for Rails 3.1 class Brakeman::CheckWithoutProtection < Brakeman::BaseCheck Brakeman::Checks.add self def run_check if version_between? "0.0.0", "3.0.99" return end models = [] tracker.models.each do |name, m| if parent?(tracker, m, :"ActiveRecord::Base") models << name end end return if models.empty? @results = Set.new Brakeman.debug "Finding all mass assignments" calls = tracker.find_call :targets => models, :methods => [:new, :attributes=, :update_attribute, :update_attributes, :update_attributes!, :create, :create!] Brakeman.debug "Processing all mass assignments" calls.each do |result| process_result result end end #All results should be Model.new(...) or Model.attributes=() calls def process_result res call = res[:call] last_arg = call[3][-1] if hash? last_arg and not @results.include? call hash_iterate(last_arg) do |k,v| if symbol? k and k[1] == :without_protection and v[0] == :true @results << call if include_user_input? call[3] confidence = CONFIDENCE[:high] else confidence = CONFIDENCE[:med] end warn :result => res, :warning_type => "Mass Assignment", :message => "Unprotected mass assignment", :line => call.line, :code => call, :confidence => confidence break end end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
brakeman-1.2.2 | lib/brakeman/checks/check_without_protection.rb |
brakeman-1.2.1 | lib/brakeman/checks/check_without_protection.rb |