brakeman-lib 3.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (159) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGES +872 -0
  3. data/FEATURES +16 -0
  4. data/README.md +169 -0
  5. data/WARNING_TYPES +95 -0
  6. data/bin/brakeman +89 -0
  7. data/lib/brakeman.rb +495 -0
  8. data/lib/brakeman/app_tree.rb +161 -0
  9. data/lib/brakeman/brakeman.rake +17 -0
  10. data/lib/brakeman/call_index.rb +219 -0
  11. data/lib/brakeman/checks.rb +191 -0
  12. data/lib/brakeman/checks/base_check.rb +518 -0
  13. data/lib/brakeman/checks/check_basic_auth.rb +88 -0
  14. data/lib/brakeman/checks/check_basic_auth_timing_attack.rb +33 -0
  15. data/lib/brakeman/checks/check_content_tag.rb +160 -0
  16. data/lib/brakeman/checks/check_create_with.rb +75 -0
  17. data/lib/brakeman/checks/check_cross_site_scripting.rb +385 -0
  18. data/lib/brakeman/checks/check_default_routes.rb +86 -0
  19. data/lib/brakeman/checks/check_deserialize.rb +57 -0
  20. data/lib/brakeman/checks/check_detailed_exceptions.rb +55 -0
  21. data/lib/brakeman/checks/check_digest_dos.rb +38 -0
  22. data/lib/brakeman/checks/check_dynamic_finders.rb +49 -0
  23. data/lib/brakeman/checks/check_escape_function.rb +21 -0
  24. data/lib/brakeman/checks/check_evaluation.rb +36 -0
  25. data/lib/brakeman/checks/check_execute.rb +167 -0
  26. data/lib/brakeman/checks/check_file_access.rb +63 -0
  27. data/lib/brakeman/checks/check_file_disclosure.rb +35 -0
  28. data/lib/brakeman/checks/check_filter_skipping.rb +31 -0
  29. data/lib/brakeman/checks/check_forgery_setting.rb +74 -0
  30. data/lib/brakeman/checks/check_header_dos.rb +31 -0
  31. data/lib/brakeman/checks/check_i18n_xss.rb +48 -0
  32. data/lib/brakeman/checks/check_jruby_xml.rb +38 -0
  33. data/lib/brakeman/checks/check_json_encoding.rb +47 -0
  34. data/lib/brakeman/checks/check_json_parsing.rb +107 -0
  35. data/lib/brakeman/checks/check_link_to.rb +132 -0
  36. data/lib/brakeman/checks/check_link_to_href.rb +115 -0
  37. data/lib/brakeman/checks/check_mail_to.rb +49 -0
  38. data/lib/brakeman/checks/check_mass_assignment.rb +198 -0
  39. data/lib/brakeman/checks/check_mime_type_dos.rb +39 -0
  40. data/lib/brakeman/checks/check_model_attr_accessible.rb +55 -0
  41. data/lib/brakeman/checks/check_model_attributes.rb +119 -0
  42. data/lib/brakeman/checks/check_model_serialize.rb +67 -0
  43. data/lib/brakeman/checks/check_nested_attributes.rb +38 -0
  44. data/lib/brakeman/checks/check_nested_attributes_bypass.rb +58 -0
  45. data/lib/brakeman/checks/check_number_to_currency.rb +74 -0
  46. data/lib/brakeman/checks/check_quote_table_name.rb +40 -0
  47. data/lib/brakeman/checks/check_redirect.rb +215 -0
  48. data/lib/brakeman/checks/check_regex_dos.rb +69 -0
  49. data/lib/brakeman/checks/check_render.rb +92 -0
  50. data/lib/brakeman/checks/check_render_dos.rb +37 -0
  51. data/lib/brakeman/checks/check_render_inline.rb +54 -0
  52. data/lib/brakeman/checks/check_response_splitting.rb +21 -0
  53. data/lib/brakeman/checks/check_route_dos.rb +42 -0
  54. data/lib/brakeman/checks/check_safe_buffer_manipulation.rb +31 -0
  55. data/lib/brakeman/checks/check_sanitize_methods.rb +79 -0
  56. data/lib/brakeman/checks/check_secrets.rb +40 -0
  57. data/lib/brakeman/checks/check_select_tag.rb +60 -0
  58. data/lib/brakeman/checks/check_select_vulnerability.rb +60 -0
  59. data/lib/brakeman/checks/check_send.rb +48 -0
  60. data/lib/brakeman/checks/check_send_file.rb +19 -0
  61. data/lib/brakeman/checks/check_session_manipulation.rb +36 -0
  62. data/lib/brakeman/checks/check_session_settings.rb +170 -0
  63. data/lib/brakeman/checks/check_simple_format.rb +59 -0
  64. data/lib/brakeman/checks/check_single_quotes.rb +101 -0
  65. data/lib/brakeman/checks/check_skip_before_filter.rb +60 -0
  66. data/lib/brakeman/checks/check_sql.rb +660 -0
  67. data/lib/brakeman/checks/check_sql_cves.rb +101 -0
  68. data/lib/brakeman/checks/check_ssl_verify.rb +49 -0
  69. data/lib/brakeman/checks/check_strip_tags.rb +89 -0
  70. data/lib/brakeman/checks/check_symbol_dos.rb +64 -0
  71. data/lib/brakeman/checks/check_symbol_dos_cve.rb +30 -0
  72. data/lib/brakeman/checks/check_translate_bug.rb +45 -0
  73. data/lib/brakeman/checks/check_unsafe_reflection.rb +51 -0
  74. data/lib/brakeman/checks/check_unscoped_find.rb +41 -0
  75. data/lib/brakeman/checks/check_validation_regex.rb +116 -0
  76. data/lib/brakeman/checks/check_weak_hash.rb +151 -0
  77. data/lib/brakeman/checks/check_without_protection.rb +80 -0
  78. data/lib/brakeman/checks/check_xml_dos.rb +51 -0
  79. data/lib/brakeman/checks/check_yaml_parsing.rb +121 -0
  80. data/lib/brakeman/differ.rb +66 -0
  81. data/lib/brakeman/file_parser.rb +50 -0
  82. data/lib/brakeman/format/style.css +133 -0
  83. data/lib/brakeman/options.rb +301 -0
  84. data/lib/brakeman/parsers/rails2_erubis.rb +6 -0
  85. data/lib/brakeman/parsers/rails2_xss_plugin_erubis.rb +48 -0
  86. data/lib/brakeman/parsers/rails3_erubis.rb +74 -0
  87. data/lib/brakeman/parsers/template_parser.rb +89 -0
  88. data/lib/brakeman/processor.rb +102 -0
  89. data/lib/brakeman/processors/alias_processor.rb +1013 -0
  90. data/lib/brakeman/processors/base_processor.rb +277 -0
  91. data/lib/brakeman/processors/config_processor.rb +14 -0
  92. data/lib/brakeman/processors/controller_alias_processor.rb +273 -0
  93. data/lib/brakeman/processors/controller_processor.rb +326 -0
  94. data/lib/brakeman/processors/erb_template_processor.rb +80 -0
  95. data/lib/brakeman/processors/erubis_template_processor.rb +104 -0
  96. data/lib/brakeman/processors/gem_processor.rb +57 -0
  97. data/lib/brakeman/processors/haml_template_processor.rb +190 -0
  98. data/lib/brakeman/processors/lib/basic_processor.rb +37 -0
  99. data/lib/brakeman/processors/lib/find_all_calls.rb +223 -0
  100. data/lib/brakeman/processors/lib/find_call.rb +183 -0
  101. data/lib/brakeman/processors/lib/find_return_value.rb +134 -0
  102. data/lib/brakeman/processors/lib/processor_helper.rb +75 -0
  103. data/lib/brakeman/processors/lib/rails2_config_processor.rb +145 -0
  104. data/lib/brakeman/processors/lib/rails2_route_processor.rb +313 -0
  105. data/lib/brakeman/processors/lib/rails3_config_processor.rb +132 -0
  106. data/lib/brakeman/processors/lib/rails3_route_processor.rb +308 -0
  107. data/lib/brakeman/processors/lib/render_helper.rb +181 -0
  108. data/lib/brakeman/processors/lib/render_path.rb +107 -0
  109. data/lib/brakeman/processors/lib/route_helper.rb +68 -0
  110. data/lib/brakeman/processors/lib/safe_call_helper.rb +16 -0
  111. data/lib/brakeman/processors/library_processor.rb +119 -0
  112. data/lib/brakeman/processors/model_processor.rb +191 -0
  113. data/lib/brakeman/processors/output_processor.rb +171 -0
  114. data/lib/brakeman/processors/route_processor.rb +17 -0
  115. data/lib/brakeman/processors/slim_template_processor.rb +107 -0
  116. data/lib/brakeman/processors/template_alias_processor.rb +116 -0
  117. data/lib/brakeman/processors/template_processor.rb +74 -0
  118. data/lib/brakeman/report.rb +78 -0
  119. data/lib/brakeman/report/config/remediation.yml +71 -0
  120. data/lib/brakeman/report/ignore/config.rb +135 -0
  121. data/lib/brakeman/report/ignore/interactive.rb +311 -0
  122. data/lib/brakeman/report/renderer.rb +24 -0
  123. data/lib/brakeman/report/report_base.rb +286 -0
  124. data/lib/brakeman/report/report_codeclimate.rb +70 -0
  125. data/lib/brakeman/report/report_csv.rb +55 -0
  126. data/lib/brakeman/report/report_hash.rb +23 -0
  127. data/lib/brakeman/report/report_html.rb +216 -0
  128. data/lib/brakeman/report/report_json.rb +42 -0
  129. data/lib/brakeman/report/report_markdown.rb +156 -0
  130. data/lib/brakeman/report/report_table.rb +107 -0
  131. data/lib/brakeman/report/report_tabs.rb +17 -0
  132. data/lib/brakeman/report/templates/controller_overview.html.erb +22 -0
  133. data/lib/brakeman/report/templates/controller_warnings.html.erb +21 -0
  134. data/lib/brakeman/report/templates/error_overview.html.erb +29 -0
  135. data/lib/brakeman/report/templates/header.html.erb +58 -0
  136. data/lib/brakeman/report/templates/ignored_warnings.html.erb +25 -0
  137. data/lib/brakeman/report/templates/model_warnings.html.erb +21 -0
  138. data/lib/brakeman/report/templates/overview.html.erb +38 -0
  139. data/lib/brakeman/report/templates/security_warnings.html.erb +23 -0
  140. data/lib/brakeman/report/templates/template_overview.html.erb +21 -0
  141. data/lib/brakeman/report/templates/view_warnings.html.erb +34 -0
  142. data/lib/brakeman/report/templates/warning_overview.html.erb +17 -0
  143. data/lib/brakeman/rescanner.rb +483 -0
  144. data/lib/brakeman/scanner.rb +317 -0
  145. data/lib/brakeman/tracker.rb +347 -0
  146. data/lib/brakeman/tracker/collection.rb +93 -0
  147. data/lib/brakeman/tracker/config.rb +101 -0
  148. data/lib/brakeman/tracker/constants.rb +101 -0
  149. data/lib/brakeman/tracker/controller.rb +161 -0
  150. data/lib/brakeman/tracker/library.rb +17 -0
  151. data/lib/brakeman/tracker/model.rb +90 -0
  152. data/lib/brakeman/tracker/template.rb +33 -0
  153. data/lib/brakeman/util.rb +481 -0
  154. data/lib/brakeman/version.rb +3 -0
  155. data/lib/brakeman/warning.rb +255 -0
  156. data/lib/brakeman/warning_codes.rb +111 -0
  157. data/lib/ruby_parser/bm_sexp.rb +610 -0
  158. data/lib/ruby_parser/bm_sexp_processor.rb +116 -0
  159. metadata +362 -0
@@ -0,0 +1,277 @@
1
+ require 'brakeman/processors/lib/processor_helper'
2
+ require 'brakeman/processors/lib/safe_call_helper'
3
+ require 'brakeman/util'
4
+
5
+ #Base processor for most processors.
6
+ class Brakeman::BaseProcessor < Brakeman::SexpProcessor
7
+ include Brakeman::ProcessorHelper
8
+ include Brakeman::SafeCallHelper
9
+ include Brakeman::Util
10
+
11
+ IGNORE = Sexp.new :ignore
12
+
13
+ #Return a new Processor.
14
+ def initialize tracker
15
+ super()
16
+ @last = nil
17
+ @tracker = tracker
18
+ @current_template = @current_module = @current_class = @current_method = @file_name = nil
19
+ end
20
+
21
+ def process_file exp, file_name
22
+ @file_name = file_name
23
+ process exp
24
+ end
25
+
26
+ def ignore
27
+ IGNORE
28
+ end
29
+
30
+ #Process a new scope. Removes expressions that are set to nil.
31
+ def process_scope exp
32
+ #NOPE?
33
+ end
34
+
35
+ #Default processing.
36
+ def process_default exp
37
+ exp = exp.dup
38
+
39
+ exp.each_with_index do |e, i|
40
+ if sexp? e and not e.empty?
41
+ exp[i] = process e
42
+ else
43
+ e
44
+ end
45
+ end
46
+
47
+ exp
48
+ end
49
+
50
+ #Process an if statement.
51
+ def process_if exp
52
+ exp = exp.dup
53
+ condition = exp[1] = process exp.condition
54
+
55
+ if true? condition
56
+ exp[2] = process exp.then_clause if exp.then_clause
57
+ exp[3] = nil
58
+ elsif false? condition
59
+ exp[2] = nil
60
+ exp[3] = process exp.else_clause if exp.else_clause
61
+ else
62
+ exp[2] = process exp.then_clause if exp.then_clause
63
+ exp[3] = process exp.else_clause if exp.else_clause
64
+ end
65
+
66
+ exp
67
+ end
68
+
69
+ #Processes calls with blocks.
70
+ #
71
+ #s(:iter, CALL, {:lasgn|:masgn}, BLOCK)
72
+ def process_iter exp
73
+ exp = exp.dup
74
+ call = process exp.block_call
75
+ #deal with assignments somehow
76
+ if exp.block
77
+ block = process exp.block
78
+ block = nil if block.empty?
79
+ else
80
+ block = nil
81
+ end
82
+
83
+ call = Sexp.new(:iter, call, exp.block_args, block).compact
84
+ call.line(exp.line)
85
+ call
86
+ end
87
+
88
+ #String with interpolation.
89
+ def process_dstr exp
90
+ exp = exp.dup
91
+ exp.shift
92
+ exp.map! do |e|
93
+ if e.is_a? String
94
+ e
95
+ else
96
+ res = process e
97
+ if res.empty?
98
+ nil
99
+ else
100
+ res
101
+ end
102
+ end
103
+ end.compact!
104
+
105
+ exp.unshift :dstr
106
+ end
107
+
108
+ #Processes a block. Changes Sexp node type to :rlist
109
+ def process_block exp
110
+ exp = exp.dup
111
+ exp.shift
112
+
113
+ exp.map! do |e|
114
+ process e
115
+ end
116
+
117
+ exp.unshift :rlist
118
+ end
119
+
120
+ #Processes the inside of an interpolated String.
121
+ def process_evstr exp
122
+ exp = exp.dup
123
+ if exp[1]
124
+ exp[1] = process exp[1]
125
+ end
126
+
127
+ exp
128
+ end
129
+
130
+ #Processes a hash
131
+ def process_hash exp
132
+ exp = exp.dup
133
+ exp.shift
134
+ exp.map! do |e|
135
+ if sexp? e
136
+ process e
137
+ else
138
+ e
139
+ end
140
+ end
141
+
142
+ exp.unshift :hash
143
+ end
144
+
145
+ #Processes the values in an argument list
146
+ def process_arglist exp
147
+ exp = exp.dup
148
+ exp.shift
149
+ exp.map! do |e|
150
+ process e
151
+ end
152
+
153
+ exp.unshift :arglist
154
+ end
155
+
156
+ #Processes a local assignment
157
+ def process_lasgn exp
158
+ exp = exp.dup
159
+ exp.rhs = process exp.rhs
160
+ exp
161
+ end
162
+
163
+ alias :process_iasgn :process_lasgn
164
+
165
+ #Processes an instance variable assignment
166
+ def process_iasgn exp
167
+ exp = exp.dup
168
+ exp.rhs = process exp.rhs
169
+ exp
170
+ end
171
+
172
+ #Processes an attribute assignment, which can be either x.y = 1 or x[:y] = 1
173
+ def process_attrasgn exp
174
+ exp = exp.dup
175
+ exp.target = process exp.target
176
+ exp.arglist = process exp.arglist
177
+ exp
178
+ end
179
+
180
+ #Ignore ignore Sexps
181
+ def process_ignore exp
182
+ exp
183
+ end
184
+
185
+ def process_cdecl exp
186
+ file = case
187
+ when @file_name
188
+ @file_name
189
+ when @current_class.is_a?(Brakeman::Collection)
190
+ @current_class.file
191
+ when @current_module.is_a?(Brakeman::Collection)
192
+ @current_module.file
193
+ else
194
+ nil
195
+ end
196
+
197
+ @tracker.add_constant exp.lhs, exp.rhs, :file => file if @tracker
198
+ exp
199
+ end
200
+
201
+ #Convenience method for `make_render exp, true`
202
+ def make_render_in_view exp
203
+ make_render exp, true
204
+ end
205
+
206
+ #Generates :render node from call to render.
207
+ def make_render exp, in_view = false
208
+ render_type, value, rest = find_render_type exp, in_view
209
+ rest = process rest
210
+ result = Sexp.new(:render, render_type, value, rest)
211
+ result.line(exp.line)
212
+ result
213
+ end
214
+
215
+ #Determines the type of a call to render.
216
+ #
217
+ #Possible types are:
218
+ #:action, :default, :file, :inline, :js, :json, :nothing, :partial,
219
+ #:template, :text, :update, :xml
220
+ #
221
+ #And also :layout for inside templates
222
+ def find_render_type call, in_view = false
223
+ rest = Sexp.new(:hash)
224
+ type = nil
225
+ value = nil
226
+ first_arg = call.first_arg
227
+
228
+ if call.second_arg.nil? and first_arg == Sexp.new(:lit, :update)
229
+ return :update, nil, Sexp.new(:arglist, *call.args[0..-2]) #TODO HUH?
230
+ end
231
+
232
+ #Look for render :action, ... or render "action", ...
233
+ if string? first_arg or symbol? first_arg
234
+ if @current_template and @tracker.options[:rails3]
235
+ type = :partial
236
+ value = first_arg
237
+ else
238
+ type = :action
239
+ value = first_arg
240
+ end
241
+ elsif first_arg.is_a? Symbol or first_arg.is_a? String
242
+ type = :action
243
+ value = Sexp.new(:lit, first_arg.to_sym)
244
+ elsif first_arg.nil?
245
+ type = :default
246
+ elsif not hash? first_arg
247
+ type = :action
248
+ value = first_arg
249
+ end
250
+
251
+ types_in_hash = Set[:action, :file, :inline, :js, :json, :nothing, :partial, :template, :text, :update, :xml]
252
+
253
+ #render :layout => "blah" means something else when in a template
254
+ if in_view
255
+ types_in_hash << :layout
256
+ end
257
+
258
+ last_arg = call.last_arg
259
+
260
+ #Look for "type" of render in options hash
261
+ #For example, render :file => "blah"
262
+ if hash? last_arg
263
+ hash_iterate(last_arg) do |key, val|
264
+ if symbol? key and types_in_hash.include? key.value
265
+ type = key.value
266
+ value = val
267
+ else
268
+ rest << key << val
269
+ end
270
+ end
271
+ end
272
+
273
+ type ||= :default
274
+ value ||= :default
275
+ return type, value, rest
276
+ end
277
+ end
@@ -0,0 +1,14 @@
1
+ require 'brakeman/processors/base_processor'
2
+ require 'brakeman/processors/alias_processor'
3
+ require 'brakeman/processors/lib/rails3_config_processor.rb'
4
+ require 'brakeman/processors/lib/rails2_config_processor.rb'
5
+
6
+ class Brakeman::ConfigProcessor
7
+ def self.new tracker
8
+ if tracker.options[:rails3]
9
+ Brakeman::Rails3ConfigProcessor.new tracker
10
+ else
11
+ Brakeman::Rails2ConfigProcessor.new tracker
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,273 @@
1
+ require 'brakeman/processors/alias_processor'
2
+ require 'brakeman/processors/lib/render_helper'
3
+ require 'brakeman/processors/lib/render_path'
4
+ require 'brakeman/processors/lib/find_return_value'
5
+
6
+ #Processes aliasing in controllers, but includes following
7
+ #renders in routes and putting variables into templates
8
+ class Brakeman::ControllerAliasProcessor < Brakeman::AliasProcessor
9
+ include Brakeman::RenderHelper
10
+
11
+ #If only_method is specified, only that method will be processed,
12
+ #other methods will be skipped.
13
+ #This is for rescanning just a single action.
14
+ def initialize app_tree, tracker, only_method = nil
15
+ super tracker
16
+ @app_tree = app_tree
17
+ @only_method = only_method
18
+ @rendered = false
19
+ @current_class = @current_module = @current_method = nil
20
+ @method_cache = {} #Cache method lookups
21
+ end
22
+
23
+ def process_controller name, src, file_name
24
+ if not node_type? src, :class
25
+ Brakeman.debug "#{name} is not a class, it's a #{src.node_type}"
26
+ return
27
+ else
28
+ @current_class = name
29
+ @file_name = file_name
30
+
31
+ process_default src
32
+
33
+ process_mixins
34
+ end
35
+ end
36
+
37
+ #Process modules mixed into the controller, in case they contain actions.
38
+ def process_mixins
39
+ controller = @tracker.controllers[@current_class]
40
+
41
+ controller.includes.each do |i|
42
+ mixin = @tracker.libs[i]
43
+
44
+ next unless mixin
45
+
46
+ #Process methods in alphabetical order for consistency
47
+ methods = mixin.methods_public.keys.map { |n| n.to_s }.sort.map { |n| n.to_sym }
48
+
49
+ methods.each do |name|
50
+ #Need to process the method like it was in a controller in order
51
+ #to get the renders set
52
+ processor = Brakeman::ControllerProcessor.new(@app_tree, @tracker)
53
+ method = mixin.get_method(name)[:src].deep_clone
54
+
55
+ if node_type? method, :defn
56
+ method = processor.process_defn method
57
+ else
58
+ #Should be a defn, but this will catch other cases
59
+ method = processor.process method
60
+ end
61
+
62
+ @file_name = mixin.file
63
+ #Then process it like any other method in the controller
64
+ process method
65
+ end
66
+ end
67
+ end
68
+
69
+ #Skip it, must be an inner class
70
+ def process_class exp
71
+ exp
72
+ end
73
+
74
+ #Processes a method definition, which may include
75
+ #processing any rendered templates.
76
+ def process_defn exp
77
+ meth_name = exp.method_name
78
+
79
+ Brakeman.debug "Processing #{@current_class}##{meth_name}"
80
+
81
+ #Skip if instructed to only process a specific method
82
+ #(but don't skip if this method was called from elsewhere)
83
+ return exp if @current_method.nil? and @only_method and @only_method != meth_name
84
+
85
+ is_route = route? meth_name
86
+ other_method = @current_method
87
+ @current_method = meth_name
88
+ @rendered = false if is_route
89
+
90
+ meth_env do
91
+ if is_route
92
+ before_filter_list(@current_method, @current_class).each do |f|
93
+ process_before_filter f
94
+ end
95
+ end
96
+
97
+ process_all exp.body
98
+
99
+ if is_route and not @rendered
100
+ process_default_render exp
101
+ end
102
+ end
103
+
104
+ @current_method = other_method
105
+ exp
106
+ end
107
+
108
+ #Look for calls to head()
109
+ def process_call exp
110
+ exp = super
111
+ return exp unless call? exp
112
+
113
+ method = exp.method
114
+
115
+ if method == :head
116
+ @rendered = true
117
+ elsif @tracker.options[:interprocedural] and
118
+ @current_method and (exp.target.nil? or exp.target.node_type == :self)
119
+
120
+ exp = get_call_value(exp)
121
+ end
122
+
123
+ exp
124
+ end
125
+
126
+ #Check for +respond_to+
127
+ def process_iter exp
128
+ super
129
+
130
+ if call? exp.block_call and exp.block_call.method == :respond_to
131
+ @rendered = true
132
+ end
133
+
134
+ exp
135
+ end
136
+
137
+ #Processes a call to a before filter.
138
+ #Basically, adds any instance variable assignments to the environment.
139
+ #TODO: method arguments?
140
+ def process_before_filter name
141
+ filter = find_method name, @current_class
142
+
143
+ if filter.nil?
144
+ Brakeman.debug "[Notice] Could not find filter #{name}"
145
+ return
146
+ end
147
+
148
+ method = filter[:method]
149
+
150
+ if ivars = @tracker.filter_cache[[filter[:controller], name]]
151
+ ivars.each do |variable, value|
152
+ env[variable] = value
153
+ end
154
+ else
155
+ processor = Brakeman::AliasProcessor.new @tracker
156
+ processor.process_safely(method.body_list, only_ivars(:include_request_vars))
157
+
158
+ ivars = processor.only_ivars(:include_request_vars).all
159
+
160
+ @tracker.filter_cache[[filter[:controller], name]] = ivars
161
+
162
+ ivars.each do |variable, value|
163
+ env[variable] = value
164
+ end
165
+ end
166
+ end
167
+
168
+ #Processes the default template for the current action
169
+ def process_default_render exp
170
+ process_layout
171
+ process_template template_name, nil, nil, nil
172
+ end
173
+
174
+ #Process template and add the current class and method name as called_from info
175
+ def process_template name, args, _, line
176
+ # If line is null, assume implicit render and set the end of the action
177
+ # method as the line number
178
+ if line.nil? and controller = @tracker.controllers[@current_class]
179
+ if meth = controller.get_method(@current_method)
180
+ line = meth[:src] && meth[:src].last && meth[:src].last.line
181
+ line += 1
182
+ end
183
+ end
184
+
185
+ render_path = Brakeman::RenderPath.new.add_controller_render(@current_class, @current_method, line, relative_path(@file_name))
186
+ super name, args, render_path, line
187
+ end
188
+
189
+ #Turns a method name into a template name
190
+ def template_name name = nil
191
+ name ||= @current_method
192
+ name = name.to_s
193
+ if name.include? "/"
194
+ name
195
+ else
196
+ controller = @current_class.to_s.gsub("Controller", "")
197
+ controller.gsub!("::", "/")
198
+ underscore(controller + "/" + name.to_s)
199
+ end
200
+ end
201
+
202
+ #Determines default layout name
203
+ def layout_name
204
+ controller = @tracker.controllers[@current_class]
205
+
206
+ return controller.layout if controller.layout
207
+ return false if controller.layout == false
208
+
209
+ app_controller = @tracker.controllers[:ApplicationController]
210
+
211
+ return app_controller.layout if app_controller and app_controller.layout
212
+
213
+ nil
214
+ end
215
+
216
+ #Returns true if the given method name is also a route
217
+ def route? method
218
+ if @tracker.routes[:allow_all_actions] or @tracker.options[:assume_all_routes]
219
+ true
220
+ else
221
+ routes = @tracker.routes[@current_class]
222
+ routes and (routes.include? :allow_all_actions or routes.include? method)
223
+ end
224
+ end
225
+
226
+ #Get list of filters, including those that are inherited
227
+ def before_filter_list method, klass
228
+ controller = @tracker.controllers[klass]
229
+
230
+ if controller
231
+ controller.before_filter_list self, method
232
+ else
233
+ []
234
+ end
235
+ end
236
+
237
+ #Finds a method in the given class or a parent class
238
+ #
239
+ #Returns nil if the method could not be found.
240
+ #
241
+ #If found, returns hash table with controller name and method sexp.
242
+ def find_method method_name, klass
243
+ return nil if sexp? method_name
244
+ method_name = method_name.to_sym
245
+
246
+ if method = @method_cache[method_name]
247
+ return method
248
+ end
249
+
250
+ controller = @tracker.controllers[klass]
251
+ controller ||= @tracker.libs[klass]
252
+
253
+ if klass and controller
254
+ method = controller.get_method method_name
255
+
256
+ if method.nil?
257
+ controller.includes.each do |included|
258
+ method = find_method method_name, included
259
+ if method
260
+ @method_cache[method_name] = method
261
+ return method
262
+ end
263
+ end
264
+
265
+ @method_cache[method_name] = find_method method_name, controller.parent
266
+ else
267
+ @method_cache[method_name] = { :controller => controller.name, :method => method[:src] }
268
+ end
269
+ else
270
+ nil
271
+ end
272
+ end
273
+ end