Class: Brakeman::CheckVerbConfusion

Inherits:
BaseCheck
  • Object
show all
Defined in:
lib/brakeman/checks/check_verb_confusion.rb

Instance Method Summary collapse

Instance Method Details

#process_if(exp) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/brakeman/checks/check_verb_confusion.rb', line 38

def process_if exp
  if exp.condition == @matched_call
    # Found `if request.get?`

    # Do not warn if there is an `elsif` clause
    if node_type? exp.else_clause, :if
      return exp
    end

    warn_about_result @current_result, exp
  end

  exp
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
# File 'lib/brakeman/checks/check_verb_confusion.rb', line 17

def process_result result
  @current_result = result
  @matched_call = result[:call]
  klass = tracker.find_class(result[:location][:class])

  # TODO: abstract into tracker.find_location ?
  if klass.nil?
    Brakeman.debug "No class found: #{result[:location][:class]}"
    return
  end

  method = klass.get_method(result[:location][:method])

  if method.nil?
    Brakeman.debug "No method found: #{result[:location][:method]}"
    return
  end

  process method.src
end

#run_checkObject

Process calls



9
10
11
12
13
14
15
# File 'lib/brakeman/checks/check_verb_confusion.rb', line 9

def run_check
  calls = tracker.find_call(target: :request, methods: [:get?])

  calls.each do |call|
    process_result call
  end
end

#warn_about_result(result, code) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/brakeman/checks/check_verb_confusion.rb', line 53

def warn_about_result result, code
  return unless original? result

  confidence = :weak
  message = msg('Potential HTTP verb confusion. ',
                msg_code('HEAD'),
                ' is routed like ',
                msg_code('GET'),
                ' but ',
                msg_code('request.get?'),
                ' will return ',
                msg_code('false')
               )

  warn :result => result,
    :warning_type => "HTTP Verb Confusion",
    :warning_code => :http_verb_confusion,
    :message => message,
    :code => code,
    :user_input => result[:call],
    :confidence => confidence,
    :cwe_id => [352]
end