Sha256: 2cdaf30c19503754359d71e2d71d3e476a2854a3bce865e6eaa626c2cb3f0058

Contents?: true

Size: 1.13 KB

Versions: 36

Compression:

Stored size: 1.13 KB

Contents

require 'checks/base_check'

#Check if mass assignment is used with models
#which inherit from ActiveRecord::Base.
#
#If OPTIONS[:collapse_mass_assignment] is +true+ (default), all models which do
#not use attr_accessible will be reported in a single warning
class CheckModelAttributes < BaseCheck
  Checks.add self

  def run_check
    return if mass_assign_disabled? tracker

    names = []

    tracker.models.each do |name, model|
      if model[:attr_accessible].nil? and parent? tracker, model, :"ActiveRecord::Base"
        if OPTIONS[:collapse_mass_assignment]
          names << name.to_s
        else
          warn :model => name, 
            :warning_type => "Attribute Restriction",
            :message => "Mass assignment is not restricted using attr_accessible", 
            :confidence => CONFIDENCE[:high]
        end
      end
    end

    if OPTIONS[:collapse_mass_assignment] and not names.empty?
      warn :model => names.sort.join(", "), 
        :warning_type => "Attribute Restriction", 
        :message => "Mass assignment is not restricted using attr_accessible", 
        :confidence => CONFIDENCE[:high]
    end
  end
end

Version data entries

36 entries across 36 versions & 2 rubygems

Version Path
brakeman-0.8.4 lib/checks/check_model_attributes.rb
brakeman-0.8.3 lib/checks/check_model_attributes.rb
brakeman-0.8.2 lib/checks/check_model_attributes.rb
brakeman-0.8.1 lib/checks/check_model_attributes.rb
brakeman-0.8.0 lib/checks/check_model_attributes.rb
brakeman-0.7.2 lib/checks/check_model_attributes.rb
brakeman-0.7.1 lib/checks/check_model_attributes.rb
brakeman-0.7.0 lib/checks/check_model_attributes.rb
brakeman-0.6.1 lib/checks/check_model_attributes.rb
brakeman-0.6.0 lib/checks/check_model_attributes.rb
brakeman-min-0.5.2 lib/checks/check_model_attributes.rb
brakeman-0.5.2 lib/checks/check_model_attributes.rb
brakeman-min-0.5.1 lib/checks/check_model_attributes.rb
brakeman-0.5.1 lib/checks/check_model_attributes.rb
brakeman-min-0.5.0 lib/checks/check_model_attributes.rb
brakeman-0.5.0 lib/checks/check_model_attributes.rb
brakeman-0.4.1 lib/checks/check_model_attributes.rb
brakeman-min-0.4.1 lib/checks/check_model_attributes.rb
brakeman-min-0.4.0 lib/checks/check_model_attributes.rb
brakeman-0.4.0 lib/checks/check_model_attributes.rb