Class: Brakeman::FindAllCalls

Inherits:
BasicProcessor show all
Defined in:
lib/brakeman/processors/lib/find_all_calls.rb

Constant Summary

Constants included from Util

Util::ALL_PARAMETERS, Util::COOKIES, Util::COOKIES_SEXP, Util::PARAMETERS, Util::PARAMS_SEXP, Util::PATH_PARAMETERS, Util::QUERY_PARAMETERS, Util::REQUEST_ENV, Util::REQUEST_PARAMETERS, Util::REQUEST_PARAMS, Util::SESSION, Util::SESSION_SEXP

Constants inherited from SexpProcessor

SexpProcessor::VERSION

Instance Attribute Summary collapse

Attributes inherited from SexpProcessor

#context, #env, #expected

Instance Method Summary collapse

Methods inherited from BasicProcessor

#process_default

Methods included from Util

#array?, #block?, #call?, #camelize, #contains_class?, #context_for, #cookies?, #false?, #file_by_name, #file_for, #github_url, #hash?, #hash_access, #hash_insert, #hash_iterate, #integer?, #make_call, #node_type?, #number?, #params?, #pluralize, #regexp?, #relative_path, #request_env?, #request_value?, #result?, #set_env_defaults, #sexp?, #string?, #symbol?, #table_to_csv, #template_path_to_name, #true?, #truncate_table, #underscore

Methods included from ProcessorHelper

#class_name, #process_all, #process_all!, #process_call_args, #process_class, #process_module

Methods inherited from SexpProcessor

#error_handler, #in_context, #process, #process_dummy, #scope

Constructor Details

#initialize(tracker) ⇒ FindAllCalls

Returns a new instance of FindAllCalls.


6
7
8
9
10
11
12
13
# File 'lib/brakeman/processors/lib/find_all_calls.rb', line 6

def initialize tracker
  super
  @current_class = nil
  @current_method = nil
  @in_target = false
  @calls = []
  @cache = {}
end

Instance Attribute Details

#callsObject (readonly)

Returns the value of attribute calls


4
5
6
# File 'lib/brakeman/processors/lib/find_all_calls.rb', line 4

def calls
  @calls
end

Instance Method Details

#process_attrasgn(exp) ⇒ Object

Process an assignment like a call


123
124
125
# File 'lib/brakeman/processors/lib/find_all_calls.rb', line 123

def process_attrasgn exp
  process_call exp
end

#process_call(exp) ⇒ Object


40
41
42
43
# File 'lib/brakeman/processors/lib/find_all_calls.rb', line 40

def process_call exp
  @calls << create_call_hash(exp)
  exp
end

#process_call_with_block(exp) ⇒ Object Also known as: process_iter


45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/brakeman/processors/lib/find_all_calls.rb', line 45

def process_call_with_block exp
  call = exp.block_call

  if call.node_type == :call
    call_hash = create_call_hash(call)

    call_hash[:block] = exp.block
    call_hash[:block_args] = exp.block_args

    @calls << call_hash

    process exp.block
  else
    #Probably a :render call with block
    process call
    process exp.block
  end

  exp
end

#process_dregx(exp) ⇒ Object

Process a dynamic regex like a call


110
111
112
113
114
115
116
117
118
119
120
# File 'lib/brakeman/processors/lib/find_all_calls.rb', line 110

def process_dregx exp
  exp.each { |arg| process arg if sexp? arg }

  @calls << { :target => nil,
              :method => :brakeman_regex_interp,
              :call => exp,
              :nested => false,
              :location => make_location }

  exp
end

#process_dsym(exp) ⇒ Object

:“string” is equivalent to “string”.to_sym


97
98
99
100
101
102
103
104
105
106
107
# File 'lib/brakeman/processors/lib/find_all_calls.rb', line 97

def process_dsym exp
  exp.each { |arg| process arg if sexp? arg }

  @calls << { :target => nil,
              :method => :literal_to_sym,
              :call => exp,
              :nested => false,
              :location => make_location }

  exp
end

#process_dxstr(exp) ⇒ Object

Technically, “ is call to Kernel#` But we just need them in the call cache for speed


84
85
86
87
88
89
90
91
92
93
94
# File 'lib/brakeman/processors/lib/find_all_calls.rb', line 84

def process_dxstr exp
  process exp.last if sexp? exp.last

  @calls << { :target => nil,
              :method => :`,
              :call => exp,
              :nested => false,
              :location => make_location }

  exp
end

#process_methdef(exp) ⇒ Object

Process body of method


26
27
28
# File 'lib/brakeman/processors/lib/find_all_calls.rb', line 26

def process_methdef exp
  process_all exp.body
end

#process_render(exp) ⇒ Object

Calls to render() are converted to s(:render, …) but we would like them in the call cache still for speed


70
71
72
73
74
75
76
77
78
79
80
# File 'lib/brakeman/processors/lib/find_all_calls.rb', line 70

def process_render exp
  process exp.last if sexp? exp.last

  @calls << { :target => nil,
              :method => :render,
              :call => exp,
              :nested => false,
              :location => make_location }

  exp
end

#process_rlist(exp) ⇒ Object

Process body of block


36
37
38
# File 'lib/brakeman/processors/lib/find_all_calls.rb', line 36

def process_rlist exp
  process_all exp
end

#process_selfdef(exp) ⇒ Object

Process body of method


31
32
33
# File 'lib/brakeman/processors/lib/find_all_calls.rb', line 31

def process_selfdef exp
  process_all exp.body
end

#process_source(exp, opts) ⇒ Object

Process the given source. Provide either class and method being searched or the template. These names are used when reporting results.


17
18
19
20
21
22
23
# File 'lib/brakeman/processors/lib/find_all_calls.rb', line 17

def process_source exp, opts
  @current_class = opts[:class]
  @current_method = opts[:method]
  @current_template = opts[:template]
  @current_file = opts[:file]
  process exp
end