Class: Brakeman::CheckDynamicFinders
- Inherits:
-
BaseCheck
- Object
- BaseCheck
- Brakeman::CheckDynamicFinders
- Defined in:
- lib/brakeman/checks/check_dynamic_finders.rb
Overview
This check looks for regexes that include user input.
Instance Method Summary collapse
- #potentially_dangerous?(method_name) ⇒ Boolean
- #process_result(result) ⇒ Object
- #run_check ⇒ Object
- #safe_call?(arg) ⇒ Boolean
Instance Method Details
#potentially_dangerous?(method_name) ⇒ Boolean
46 47 48 |
# File 'lib/brakeman/checks/check_dynamic_finders.rb', line 46 def potentially_dangerous? method_name method_name.match(/^find_by_.*(token|guid|password|api_key|activation|code|private|reset)/) end |
#process_result(result) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/brakeman/checks/check_dynamic_finders.rb', line 17 def process_result result return unless original? result call = result[:call] if potentially_dangerous? call.method call.each_arg do |arg| if params? arg and not safe_call? arg warn :result => result, :warning_type => "SQL Injection", :warning_code => :sql_injection_dynamic_finder, :message => "MySQL integer conversion may cause 0 to match any string", :confidence => :medium, :user_input => arg, :cwe_id => [89] break end end end end |
#run_check ⇒ Object
9 10 11 12 13 14 15 |
# File 'lib/brakeman/checks/check_dynamic_finders.rb', line 9 def run_check if tracker.config.has_gem? :mysql and version_between? '2.0.0', '4.1.99' tracker.find_call(:method => /^find_by_/).each do |result| process_result result end end end |
#safe_call?(arg) ⇒ Boolean
39 40 41 42 43 44 |
# File 'lib/brakeman/checks/check_dynamic_finders.rb', line 39 def safe_call? arg return false unless call? arg meth = arg.method meth == :to_s or meth == :to_i end |