brakeman-lib 3.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGES +872 -0
- data/FEATURES +16 -0
- data/README.md +169 -0
- data/WARNING_TYPES +95 -0
- data/bin/brakeman +89 -0
- data/lib/brakeman.rb +495 -0
- data/lib/brakeman/app_tree.rb +161 -0
- data/lib/brakeman/brakeman.rake +17 -0
- data/lib/brakeman/call_index.rb +219 -0
- data/lib/brakeman/checks.rb +191 -0
- data/lib/brakeman/checks/base_check.rb +518 -0
- data/lib/brakeman/checks/check_basic_auth.rb +88 -0
- data/lib/brakeman/checks/check_basic_auth_timing_attack.rb +33 -0
- data/lib/brakeman/checks/check_content_tag.rb +160 -0
- data/lib/brakeman/checks/check_create_with.rb +75 -0
- data/lib/brakeman/checks/check_cross_site_scripting.rb +385 -0
- data/lib/brakeman/checks/check_default_routes.rb +86 -0
- data/lib/brakeman/checks/check_deserialize.rb +57 -0
- data/lib/brakeman/checks/check_detailed_exceptions.rb +55 -0
- data/lib/brakeman/checks/check_digest_dos.rb +38 -0
- data/lib/brakeman/checks/check_dynamic_finders.rb +49 -0
- data/lib/brakeman/checks/check_escape_function.rb +21 -0
- data/lib/brakeman/checks/check_evaluation.rb +36 -0
- data/lib/brakeman/checks/check_execute.rb +167 -0
- data/lib/brakeman/checks/check_file_access.rb +63 -0
- data/lib/brakeman/checks/check_file_disclosure.rb +35 -0
- data/lib/brakeman/checks/check_filter_skipping.rb +31 -0
- data/lib/brakeman/checks/check_forgery_setting.rb +74 -0
- data/lib/brakeman/checks/check_header_dos.rb +31 -0
- data/lib/brakeman/checks/check_i18n_xss.rb +48 -0
- data/lib/brakeman/checks/check_jruby_xml.rb +38 -0
- data/lib/brakeman/checks/check_json_encoding.rb +47 -0
- data/lib/brakeman/checks/check_json_parsing.rb +107 -0
- data/lib/brakeman/checks/check_link_to.rb +132 -0
- data/lib/brakeman/checks/check_link_to_href.rb +115 -0
- data/lib/brakeman/checks/check_mail_to.rb +49 -0
- data/lib/brakeman/checks/check_mass_assignment.rb +198 -0
- data/lib/brakeman/checks/check_mime_type_dos.rb +39 -0
- data/lib/brakeman/checks/check_model_attr_accessible.rb +55 -0
- data/lib/brakeman/checks/check_model_attributes.rb +119 -0
- data/lib/brakeman/checks/check_model_serialize.rb +67 -0
- data/lib/brakeman/checks/check_nested_attributes.rb +38 -0
- data/lib/brakeman/checks/check_nested_attributes_bypass.rb +58 -0
- data/lib/brakeman/checks/check_number_to_currency.rb +74 -0
- data/lib/brakeman/checks/check_quote_table_name.rb +40 -0
- data/lib/brakeman/checks/check_redirect.rb +215 -0
- data/lib/brakeman/checks/check_regex_dos.rb +69 -0
- data/lib/brakeman/checks/check_render.rb +92 -0
- data/lib/brakeman/checks/check_render_dos.rb +37 -0
- data/lib/brakeman/checks/check_render_inline.rb +54 -0
- data/lib/brakeman/checks/check_response_splitting.rb +21 -0
- data/lib/brakeman/checks/check_route_dos.rb +42 -0
- data/lib/brakeman/checks/check_safe_buffer_manipulation.rb +31 -0
- data/lib/brakeman/checks/check_sanitize_methods.rb +79 -0
- data/lib/brakeman/checks/check_secrets.rb +40 -0
- data/lib/brakeman/checks/check_select_tag.rb +60 -0
- data/lib/brakeman/checks/check_select_vulnerability.rb +60 -0
- data/lib/brakeman/checks/check_send.rb +48 -0
- data/lib/brakeman/checks/check_send_file.rb +19 -0
- data/lib/brakeman/checks/check_session_manipulation.rb +36 -0
- data/lib/brakeman/checks/check_session_settings.rb +170 -0
- data/lib/brakeman/checks/check_simple_format.rb +59 -0
- data/lib/brakeman/checks/check_single_quotes.rb +101 -0
- data/lib/brakeman/checks/check_skip_before_filter.rb +60 -0
- data/lib/brakeman/checks/check_sql.rb +660 -0
- data/lib/brakeman/checks/check_sql_cves.rb +101 -0
- data/lib/brakeman/checks/check_ssl_verify.rb +49 -0
- data/lib/brakeman/checks/check_strip_tags.rb +89 -0
- data/lib/brakeman/checks/check_symbol_dos.rb +64 -0
- data/lib/brakeman/checks/check_symbol_dos_cve.rb +30 -0
- data/lib/brakeman/checks/check_translate_bug.rb +45 -0
- data/lib/brakeman/checks/check_unsafe_reflection.rb +51 -0
- data/lib/brakeman/checks/check_unscoped_find.rb +41 -0
- data/lib/brakeman/checks/check_validation_regex.rb +116 -0
- data/lib/brakeman/checks/check_weak_hash.rb +151 -0
- data/lib/brakeman/checks/check_without_protection.rb +80 -0
- data/lib/brakeman/checks/check_xml_dos.rb +51 -0
- data/lib/brakeman/checks/check_yaml_parsing.rb +121 -0
- data/lib/brakeman/differ.rb +66 -0
- data/lib/brakeman/file_parser.rb +50 -0
- data/lib/brakeman/format/style.css +133 -0
- data/lib/brakeman/options.rb +301 -0
- data/lib/brakeman/parsers/rails2_erubis.rb +6 -0
- data/lib/brakeman/parsers/rails2_xss_plugin_erubis.rb +48 -0
- data/lib/brakeman/parsers/rails3_erubis.rb +74 -0
- data/lib/brakeman/parsers/template_parser.rb +89 -0
- data/lib/brakeman/processor.rb +102 -0
- data/lib/brakeman/processors/alias_processor.rb +1013 -0
- data/lib/brakeman/processors/base_processor.rb +277 -0
- data/lib/brakeman/processors/config_processor.rb +14 -0
- data/lib/brakeman/processors/controller_alias_processor.rb +273 -0
- data/lib/brakeman/processors/controller_processor.rb +326 -0
- data/lib/brakeman/processors/erb_template_processor.rb +80 -0
- data/lib/brakeman/processors/erubis_template_processor.rb +104 -0
- data/lib/brakeman/processors/gem_processor.rb +57 -0
- data/lib/brakeman/processors/haml_template_processor.rb +190 -0
- data/lib/brakeman/processors/lib/basic_processor.rb +37 -0
- data/lib/brakeman/processors/lib/find_all_calls.rb +223 -0
- data/lib/brakeman/processors/lib/find_call.rb +183 -0
- data/lib/brakeman/processors/lib/find_return_value.rb +134 -0
- data/lib/brakeman/processors/lib/processor_helper.rb +75 -0
- data/lib/brakeman/processors/lib/rails2_config_processor.rb +145 -0
- data/lib/brakeman/processors/lib/rails2_route_processor.rb +313 -0
- data/lib/brakeman/processors/lib/rails3_config_processor.rb +132 -0
- data/lib/brakeman/processors/lib/rails3_route_processor.rb +308 -0
- data/lib/brakeman/processors/lib/render_helper.rb +181 -0
- data/lib/brakeman/processors/lib/render_path.rb +107 -0
- data/lib/brakeman/processors/lib/route_helper.rb +68 -0
- data/lib/brakeman/processors/lib/safe_call_helper.rb +16 -0
- data/lib/brakeman/processors/library_processor.rb +119 -0
- data/lib/brakeman/processors/model_processor.rb +191 -0
- data/lib/brakeman/processors/output_processor.rb +171 -0
- data/lib/brakeman/processors/route_processor.rb +17 -0
- data/lib/brakeman/processors/slim_template_processor.rb +107 -0
- data/lib/brakeman/processors/template_alias_processor.rb +116 -0
- data/lib/brakeman/processors/template_processor.rb +74 -0
- data/lib/brakeman/report.rb +78 -0
- data/lib/brakeman/report/config/remediation.yml +71 -0
- data/lib/brakeman/report/ignore/config.rb +135 -0
- data/lib/brakeman/report/ignore/interactive.rb +311 -0
- data/lib/brakeman/report/renderer.rb +24 -0
- data/lib/brakeman/report/report_base.rb +286 -0
- data/lib/brakeman/report/report_codeclimate.rb +70 -0
- data/lib/brakeman/report/report_csv.rb +55 -0
- data/lib/brakeman/report/report_hash.rb +23 -0
- data/lib/brakeman/report/report_html.rb +216 -0
- data/lib/brakeman/report/report_json.rb +42 -0
- data/lib/brakeman/report/report_markdown.rb +156 -0
- data/lib/brakeman/report/report_table.rb +107 -0
- data/lib/brakeman/report/report_tabs.rb +17 -0
- data/lib/brakeman/report/templates/controller_overview.html.erb +22 -0
- data/lib/brakeman/report/templates/controller_warnings.html.erb +21 -0
- data/lib/brakeman/report/templates/error_overview.html.erb +29 -0
- data/lib/brakeman/report/templates/header.html.erb +58 -0
- data/lib/brakeman/report/templates/ignored_warnings.html.erb +25 -0
- data/lib/brakeman/report/templates/model_warnings.html.erb +21 -0
- data/lib/brakeman/report/templates/overview.html.erb +38 -0
- data/lib/brakeman/report/templates/security_warnings.html.erb +23 -0
- data/lib/brakeman/report/templates/template_overview.html.erb +21 -0
- data/lib/brakeman/report/templates/view_warnings.html.erb +34 -0
- data/lib/brakeman/report/templates/warning_overview.html.erb +17 -0
- data/lib/brakeman/rescanner.rb +483 -0
- data/lib/brakeman/scanner.rb +317 -0
- data/lib/brakeman/tracker.rb +347 -0
- data/lib/brakeman/tracker/collection.rb +93 -0
- data/lib/brakeman/tracker/config.rb +101 -0
- data/lib/brakeman/tracker/constants.rb +101 -0
- data/lib/brakeman/tracker/controller.rb +161 -0
- data/lib/brakeman/tracker/library.rb +17 -0
- data/lib/brakeman/tracker/model.rb +90 -0
- data/lib/brakeman/tracker/template.rb +33 -0
- data/lib/brakeman/util.rb +481 -0
- data/lib/brakeman/version.rb +3 -0
- data/lib/brakeman/warning.rb +255 -0
- data/lib/brakeman/warning_codes.rb +111 -0
- data/lib/ruby_parser/bm_sexp.rb +610 -0
- data/lib/ruby_parser/bm_sexp_processor.rb +116 -0
- 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
|