Class: Brakeman::CheckModelAttributes
- Inherits:
-
BaseCheck
- Object
- SexpProcessor
- BaseCheck
- Brakeman::CheckModelAttributes
- Defined in:
- lib/brakeman/checks/check_model_attributes.rb
Overview
Check if mass assignment is used with models which inherit from ActiveRecord::Base.
If tracker.options is true
(default), all models which do not use attr_accessible will be reported in a single warning
Constant Summary
Constants inherited from BaseCheck
Constants included from Util
Util::ALL_PARAMETERS, Util::COOKIES, Util::PARAMETERS, Util::PATH_PARAMETERS, Util::QUERY_PARAMETERS, Util::REQUEST_ENV, Util::REQUEST_PARAMETERS, Util::REQUEST_PARAMS, Util::SESSION
Constants inherited from SexpProcessor
Instance Attribute Summary
Attributes inherited from BaseCheck
Attributes inherited from SexpProcessor
Instance Method Summary collapse
Methods inherited from BaseCheck
#add_result, #initialize, #process_call, #process_cookies, #process_default, #process_if, #process_params
Methods included from Util
#array?, #call?, #camelize, #contains_class?, #context_for, #cookies?, #false?, #file_by_name, #file_for, #hash?, #hash_access, #hash_insert, #hash_iterate, #integer?, #node_type?, #number?, #params?, #pluralize, #regexp?, #request_env?, #request_value?, #result?, #set_env_defaults, #sexp?, #string?, #symbol?, #table_to_csv, #true?, #truncate_table, #underscore
Methods included from ProcessorHelper
#class_name, #process_all, #process_module
Methods inherited from SexpProcessor
#error_handler, #in_context, #initialize, #process, #process_dummy, #scope
Constructor Details
This class inherits a constructor from Brakeman::BaseCheck
Instance Method Details
#check_models ⇒ Object
63 64 65 66 67 68 69 |
# File 'lib/brakeman/checks/check_model_attributes.rb', line 63 def check_models tracker.models.each do |name, model| if unprotected_model? model yield name, model end end end |
#run_check ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/brakeman/checks/check_model_attributes.rb', line 13 def run_check return if mass_assign_disabled? #Roll warnings into one warning for all models if tracker.[:collapse_mass_assignment] no_accessible_names = [] protected_names = [] check_models do |name, model| if model[:options][:attr_protected].nil? no_accessible_names << name.to_s elsif not tracker.[:ignore_attr_protected] protected_names << name.to_s end end unless no_accessible_names.empty? warn :model => no_accessible_names.sort.join(", "), :warning_type => "Attribute Restriction", :message => "Mass assignment is not restricted using attr_accessible", :confidence => CONFIDENCE[:high] end unless protected_names.empty? warn :model => protected_names.sort.join(", "), :warning_type => "Attribute Restriction", :message => "attr_accessible is recommended over attr_protected", :confidence => CONFIDENCE[:low] end else #Output one warning per model check_models do |name, model| if model[:options][:attr_protected].nil? warn :model => name, :file => model[:file], :warning_type => "Attribute Restriction", :message => "Mass assignment is not restricted using attr_accessible", :confidence => CONFIDENCE[:high] elsif not tracker.[:ignore_attr_protected] warn :model => name, :file => model[:file], :line => model[:options][:attr_protected].first.line, :warning_type => "Attribute Restriction", :message => "attr_accessible is recommended over attr_protected", :confidence => CONFIDENCE[:low] end end end end |