Class: Brakeman::CheckUnsafeReflectionMethods
- Inherits:
-
BaseCheck
- Object
- BaseCheck
- Brakeman::CheckUnsafeReflectionMethods
- Defined in:
- lib/brakeman/checks/check_unsafe_reflection_methods.rb
Instance Method Summary collapse
- #check_method ⇒ Object
- #check_tap ⇒ Object
- #check_to_proc ⇒ Object
- #run_check ⇒ Object
- #warn_unsafe_reflection(result, input) ⇒ Object
Instance Method Details
#check_method ⇒ Object
14 15 16 17 18 19 20 21 22 |
# File 'lib/brakeman/checks/check_unsafe_reflection_methods.rb', line 14 def check_method tracker.find_call(method: :method, nested: true).each do |result| argument = result[:call].first_arg if user_input = include_user_input?(argument) warn_unsafe_reflection(result, user_input) end end end |
#check_tap ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/brakeman/checks/check_unsafe_reflection_methods.rb', line 24 def check_tap tracker.find_call(method: :tap, nested: true).each do |result| argument = result[:call].first_arg # Argument is passed like a.tap(&argument) if node_type? argument, :block_pass argument = argument.value end if user_input = include_user_input?(argument) warn_unsafe_reflection(result, user_input) end end end |
#check_to_proc ⇒ Object
39 40 41 42 43 44 45 46 47 |
# File 'lib/brakeman/checks/check_unsafe_reflection_methods.rb', line 39 def check_to_proc tracker.find_call(method: :to_proc, nested: true).each do |result| target = result[:call].target if user_input = include_user_input?(target) warn_unsafe_reflection(result, user_input) end end end |
#run_check ⇒ Object
8 9 10 11 12 |
# File 'lib/brakeman/checks/check_unsafe_reflection_methods.rb', line 8 def run_check check_method check_tap check_to_proc end |
#warn_unsafe_reflection(result, input) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/brakeman/checks/check_unsafe_reflection_methods.rb', line 49 def warn_unsafe_reflection result, input return unless original? result method = result[:call].method confidence = if input.type == :params :high else :medium end = msg("Unsafe reflection method ", msg_code(method), " called with ", msg_input(input)) warn :result => result, :warning_type => "Remote Code Execution", :warning_code => :unsafe_method_reflection, :message => , :user_input => input, :confidence => confidence, :cwe_id => [470] end |