brakeman-min 7.1.2 → 8.0.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.
- checksums.yaml +4 -4
- data/CHANGES.md +15 -0
- data/README.md +1 -1
- data/lib/brakeman/app_tree.rb +7 -2
- data/lib/brakeman/checks/check_model_attributes.rb +1 -1
- data/lib/brakeman/checks/check_render.rb +1 -27
- data/lib/brakeman/checks/check_render_rce.rb +43 -0
- data/lib/brakeman/checks/check_session_settings.rb +1 -1
- data/lib/brakeman/checks.rb +31 -25
- data/lib/brakeman/commandline.rb +8 -1
- data/lib/brakeman/file_parser.rb +3 -2
- data/lib/brakeman/logger.rb +264 -0
- data/lib/brakeman/options.rb +0 -9
- data/lib/brakeman/parsers/rails_erubi.rb +82 -0
- data/lib/brakeman/parsers/template_parser.rb +7 -15
- data/lib/brakeman/processor.rb +2 -2
- data/lib/brakeman/processors/controller_alias_processor.rb +1 -1
- data/lib/brakeman/processors/controller_processor.rb +3 -3
- data/lib/brakeman/processors/{erubis_template_processor.rb → erubi_template_procesor.rb} +3 -3
- data/lib/brakeman/processors/lib/rails2_config_processor.rb +4 -3
- data/lib/brakeman/processors/lib/rails2_route_processor.rb +1 -1
- data/lib/brakeman/processors/lib/render_helper.rb +1 -1
- data/lib/brakeman/processors/lib/render_path.rb +1 -1
- data/lib/brakeman/processors/model_processor.rb +1 -1
- data/lib/brakeman/report/ignore/config.rb +1 -1
- data/lib/brakeman/scanner.rb +25 -49
- data/lib/brakeman/tracker/collection.rb +12 -2
- data/lib/brakeman/tracker/config.rb +17 -13
- data/lib/brakeman/tracker/constants.rb +17 -2
- data/lib/brakeman/tracker/controller.rb +1 -1
- data/lib/brakeman/tracker.rb +7 -15
- data/lib/brakeman/version.rb +1 -1
- data/lib/brakeman.rb +89 -49
- metadata +6 -7
- data/lib/brakeman/parsers/erubis_patch.rb +0 -11
- data/lib/brakeman/parsers/rails2_erubis.rb +0 -9
- data/lib/brakeman/parsers/rails2_xss_plugin_erubis.rb +0 -52
- data/lib/brakeman/parsers/rails3_erubis.rb +0 -85
|
@@ -21,7 +21,7 @@ module Brakeman
|
|
|
21
21
|
begin
|
|
22
22
|
src = case type
|
|
23
23
|
when :erb
|
|
24
|
-
type = :
|
|
24
|
+
type = :erubi if erubi?
|
|
25
25
|
parse_erb path, text
|
|
26
26
|
when :haml
|
|
27
27
|
type = :haml6 if haml6?
|
|
@@ -46,17 +46,9 @@ module Brakeman
|
|
|
46
46
|
end
|
|
47
47
|
|
|
48
48
|
def parse_erb path, text
|
|
49
|
-
if
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
Brakeman::Rails3Erubis.new(text, :filename => path).src
|
|
53
|
-
else
|
|
54
|
-
require 'brakeman/parsers/rails2_xss_plugin_erubis'
|
|
55
|
-
Brakeman::Rails2XSSPluginErubis.new(text, :filename => path).src
|
|
56
|
-
end
|
|
57
|
-
elsif tracker.config.erubis?
|
|
58
|
-
require 'brakeman/parsers/rails2_erubis'
|
|
59
|
-
Brakeman::ScannerErubis.new(text, :filename => path).src
|
|
49
|
+
if erubi?
|
|
50
|
+
require 'brakeman/parsers/rails_erubi'
|
|
51
|
+
Brakeman::Erubi.new(text, :filename => path).src
|
|
60
52
|
else
|
|
61
53
|
require 'erb'
|
|
62
54
|
src = if ERB.instance_method(:initialize).parameters.assoc(:key) # Ruby 2.6+
|
|
@@ -69,9 +61,9 @@ module Brakeman
|
|
|
69
61
|
end
|
|
70
62
|
end
|
|
71
63
|
|
|
72
|
-
def
|
|
64
|
+
def erubi?
|
|
73
65
|
tracker.config.escape_html? or
|
|
74
|
-
tracker.config.
|
|
66
|
+
tracker.config.erubi?
|
|
75
67
|
end
|
|
76
68
|
|
|
77
69
|
def parse_haml path, text
|
|
@@ -148,7 +140,7 @@ module Brakeman
|
|
|
148
140
|
fp = Brakeman::FileParser.new(tracker.app_tree, tracker.options[:parser_timeout])
|
|
149
141
|
tp = self.new(tracker, fp)
|
|
150
142
|
src = tp.parse_erb '_inline_', text
|
|
151
|
-
type = tp.
|
|
143
|
+
type = tp.erubi? ? :erubi : :erb
|
|
152
144
|
|
|
153
145
|
return type, fp.parse_ruby(src, "_inline_")
|
|
154
146
|
end
|
data/lib/brakeman/processor.rb
CHANGED
|
@@ -65,8 +65,8 @@ module Brakeman
|
|
|
65
65
|
result = HamlTemplateProcessor.new(@tracker, name, called_from, file_name).process src
|
|
66
66
|
when :haml6
|
|
67
67
|
result = Haml6TemplateProcessor.new(@tracker, name, called_from, file_name).process src
|
|
68
|
-
when :
|
|
69
|
-
result =
|
|
68
|
+
when :erubi
|
|
69
|
+
result = ErubiTemplateProcessor.new(@tracker, name, called_from, file_name).process src
|
|
70
70
|
when :slim
|
|
71
71
|
result = SlimTemplateProcessor.new(@tracker, name, called_from, file_name).process src
|
|
72
72
|
else
|
|
@@ -146,7 +146,7 @@ class Brakeman::ControllerAliasProcessor < Brakeman::AliasProcessor
|
|
|
146
146
|
filter = tracker.find_method name, @current_class
|
|
147
147
|
|
|
148
148
|
if filter.nil?
|
|
149
|
-
Brakeman.debug "
|
|
149
|
+
Brakeman.debug "Could not find filter #{name}"
|
|
150
150
|
return
|
|
151
151
|
end
|
|
152
152
|
|
|
@@ -30,13 +30,13 @@ class Brakeman::ControllerProcessor < Brakeman::BaseProcessor
|
|
|
30
30
|
#But if not inside a controller already, then the class may include
|
|
31
31
|
#a real controller, so we can't take this shortcut.
|
|
32
32
|
if @current_class and @current_class.name.to_s.end_with? "Controller"
|
|
33
|
-
Brakeman.debug "
|
|
33
|
+
Brakeman.debug "Treating inner class as library: #{name}"
|
|
34
34
|
Brakeman::LibraryProcessor.new(@tracker).process_library exp, @current_file
|
|
35
35
|
return exp
|
|
36
36
|
end
|
|
37
37
|
|
|
38
38
|
if not name.to_s.end_with? "Controller"
|
|
39
|
-
Brakeman.debug "
|
|
39
|
+
Brakeman.debug "Adding noncontroller as library: #{name}"
|
|
40
40
|
#Set the class to be a module in order to get the right namespacing.
|
|
41
41
|
#Add class to libraries, in case it is needed later (e.g. it's used
|
|
42
42
|
#as a parent class for a controller.)
|
|
@@ -124,7 +124,7 @@ class Brakeman::ControllerProcessor < Brakeman::BaseProcessor
|
|
|
124
124
|
if @app_tree.layout_exists?(name)
|
|
125
125
|
@current_class.layout = "layouts/#{name}"
|
|
126
126
|
else
|
|
127
|
-
Brakeman.debug "
|
|
127
|
+
Brakeman.debug "Layout not found: #{name}"
|
|
128
128
|
end
|
|
129
129
|
elsif node_type? last_arg, :nil, :false
|
|
130
130
|
#layout :false or layout nil
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
require 'brakeman/processors/template_processor'
|
|
2
2
|
|
|
3
|
-
#Processes ERB templates using
|
|
4
|
-
class Brakeman::
|
|
3
|
+
#Processes ERB templates using Erubi instead of erb.
|
|
4
|
+
class Brakeman::ErubiTemplateProcessor < Brakeman::TemplateProcessor
|
|
5
5
|
|
|
6
6
|
#s(:call, TARGET, :method, ARGS)
|
|
7
7
|
def process_call exp
|
|
@@ -14,7 +14,7 @@ class Brakeman::ErubisTemplateProcessor < Brakeman::TemplateProcessor
|
|
|
14
14
|
exp.arglist = process exp.arglist
|
|
15
15
|
method = exp.method
|
|
16
16
|
|
|
17
|
-
#_buf is the default output variable for
|
|
17
|
+
#_buf is the default output variable for Erubi
|
|
18
18
|
if node_type?(target, :lvar, :ivar) and (target.value == :_buf or target.value == :@output_buffer)
|
|
19
19
|
if method == :<< or method == :safe_concat
|
|
20
20
|
|
|
@@ -33,14 +33,15 @@ class Brakeman::Rails2ConfigProcessor < Brakeman::BasicProcessor
|
|
|
33
33
|
process res
|
|
34
34
|
end
|
|
35
35
|
|
|
36
|
-
#Check if config is set to use Erubis
|
|
36
|
+
# Check if config is set to use Erubis
|
|
37
|
+
# but because it's 2026 we're going to use Erubi
|
|
37
38
|
def process_call exp
|
|
38
39
|
target = exp.target
|
|
39
40
|
target = process target if sexp? target
|
|
40
41
|
|
|
41
42
|
if exp.method == :gem and exp.first_arg.value == "erubis"
|
|
42
|
-
Brakeman.
|
|
43
|
-
@tracker.config.
|
|
43
|
+
Brakeman.debug "[Notice] Using Erubi for ERB templates"
|
|
44
|
+
@tracker.config.erubi = true
|
|
44
45
|
end
|
|
45
46
|
|
|
46
47
|
exp
|
|
@@ -131,7 +131,7 @@ class Brakeman::Rails2RoutesProcessor < Brakeman::BasicProcessor
|
|
|
131
131
|
when :except
|
|
132
132
|
process_option_except value
|
|
133
133
|
else
|
|
134
|
-
Brakeman.
|
|
134
|
+
Brakeman.alert "Unhandled resource option, please report: #{option}"
|
|
135
135
|
end
|
|
136
136
|
end
|
|
137
137
|
end
|
|
@@ -98,7 +98,7 @@ module Brakeman::RenderHelper
|
|
|
98
98
|
name = name.to_s.gsub(/^\//, "")
|
|
99
99
|
template = @tracker.templates[name.to_sym]
|
|
100
100
|
unless template
|
|
101
|
-
Brakeman.debug "
|
|
101
|
+
Brakeman.debug "No such template: #{name}"
|
|
102
102
|
return
|
|
103
103
|
end
|
|
104
104
|
|
|
@@ -27,7 +27,7 @@ class Brakeman::ModelProcessor < Brakeman::BaseProcessor
|
|
|
27
27
|
|
|
28
28
|
#If inside an inner class we treat it as a library.
|
|
29
29
|
if @current_class
|
|
30
|
-
Brakeman.debug "
|
|
30
|
+
Brakeman.debug "Treating inner class as library: #{name}"
|
|
31
31
|
Brakeman::LibraryProcessor.new(@tracker).process_library exp, @current_file
|
|
32
32
|
return exp
|
|
33
33
|
end
|
|
@@ -107,7 +107,7 @@ module Brakeman
|
|
|
107
107
|
raise e, "\nError[#{e.class}] while reading brakeman ignore file: #{file}\n"
|
|
108
108
|
end
|
|
109
109
|
else
|
|
110
|
-
Brakeman.
|
|
110
|
+
Brakeman.alert "Could not find ignore configuration in #{file} (no file)"
|
|
111
111
|
@already_ignored = []
|
|
112
112
|
end
|
|
113
113
|
|
data/lib/brakeman/scanner.rb
CHANGED
|
@@ -31,8 +31,6 @@ class Brakeman::Scanner
|
|
|
31
31
|
end
|
|
32
32
|
|
|
33
33
|
@processor = processor || Brakeman::Processor.new(@app_tree, options)
|
|
34
|
-
@show_timing = tracker.options[:debug] || tracker.options[:show_timing]
|
|
35
|
-
@per_file_timing = tracker.options[:debug] && tracker.options[:show_timing]
|
|
36
34
|
end
|
|
37
35
|
|
|
38
36
|
#Returns the Tracker generated from the scan
|
|
@@ -44,32 +42,12 @@ class Brakeman::Scanner
|
|
|
44
42
|
tracker.file_cache
|
|
45
43
|
end
|
|
46
44
|
|
|
47
|
-
def process_step
|
|
48
|
-
Brakeman.
|
|
49
|
-
|
|
50
|
-
if @show_timing
|
|
51
|
-
start_t = Time.now
|
|
52
|
-
yield
|
|
53
|
-
duration = Time.now - start_t
|
|
54
|
-
|
|
55
|
-
Brakeman.notify "(#{description}) Duration: #{duration} seconds"
|
|
56
|
-
else
|
|
57
|
-
yield
|
|
58
|
-
end
|
|
45
|
+
def process_step(description, &)
|
|
46
|
+
Brakeman.process_step(description, &)
|
|
59
47
|
end
|
|
60
48
|
|
|
61
|
-
def process_step_file
|
|
62
|
-
|
|
63
|
-
Brakeman.notify "Processing #{description}"
|
|
64
|
-
|
|
65
|
-
start_t = Time.now
|
|
66
|
-
yield
|
|
67
|
-
duration = Time.now - start_t
|
|
68
|
-
|
|
69
|
-
Brakeman.notify "(#{description}) Duration: #{duration} seconds"
|
|
70
|
-
else
|
|
71
|
-
yield
|
|
72
|
-
end
|
|
49
|
+
def process_step_file(description, &)
|
|
50
|
+
Brakeman.logger.single_context(description, &)
|
|
73
51
|
end
|
|
74
52
|
|
|
75
53
|
#Process everything in the Rails application
|
|
@@ -111,7 +89,7 @@ class Brakeman::Scanner
|
|
|
111
89
|
process_initializers
|
|
112
90
|
end
|
|
113
91
|
|
|
114
|
-
process_step 'Processing
|
|
92
|
+
process_step 'Processing libraries' do
|
|
115
93
|
process_libs
|
|
116
94
|
end
|
|
117
95
|
|
|
@@ -123,7 +101,7 @@ class Brakeman::Scanner
|
|
|
123
101
|
process_templates
|
|
124
102
|
end
|
|
125
103
|
|
|
126
|
-
process_step 'Processing data flow
|
|
104
|
+
process_step 'Processing data flow' do
|
|
127
105
|
process_template_data_flows
|
|
128
106
|
end
|
|
129
107
|
|
|
@@ -135,11 +113,11 @@ class Brakeman::Scanner
|
|
|
135
113
|
process_controllers
|
|
136
114
|
end
|
|
137
115
|
|
|
138
|
-
process_step 'Processing data flow
|
|
116
|
+
process_step 'Processing data flow' do
|
|
139
117
|
process_controller_data_flows
|
|
140
118
|
end
|
|
141
119
|
|
|
142
|
-
process_step 'Indexing
|
|
120
|
+
process_step 'Indexing method calls' do
|
|
143
121
|
index_call_sites
|
|
144
122
|
end
|
|
145
123
|
|
|
@@ -154,6 +132,7 @@ class Brakeman::Scanner
|
|
|
154
132
|
template_parser = Brakeman::TemplateParser.new(tracker, fp)
|
|
155
133
|
|
|
156
134
|
fp.read_files(template_paths) do |path, contents|
|
|
135
|
+
Brakeman.logger.spin
|
|
157
136
|
template_parser.parse_template(path, contents)
|
|
158
137
|
end
|
|
159
138
|
|
|
@@ -167,6 +146,8 @@ class Brakeman::Scanner
|
|
|
167
146
|
detector = Brakeman::FileTypeDetector.new
|
|
168
147
|
|
|
169
148
|
astfiles.each do |file|
|
|
149
|
+
Brakeman.logger.spin
|
|
150
|
+
|
|
170
151
|
if file.is_a? Brakeman::TemplateParser::TemplateFile
|
|
171
152
|
file_cache.add_file file, :template
|
|
172
153
|
else
|
|
@@ -202,7 +183,7 @@ class Brakeman::Scanner
|
|
|
202
183
|
options[:rails3] or options[:escape_html]
|
|
203
184
|
|
|
204
185
|
tracker.config.escape_html = true
|
|
205
|
-
Brakeman.
|
|
186
|
+
Brakeman.debug 'Escaping HTML by default'
|
|
206
187
|
end
|
|
207
188
|
|
|
208
189
|
if @app_tree.exists? ".ruby-version"
|
|
@@ -222,7 +203,7 @@ class Brakeman::Scanner
|
|
|
222
203
|
end
|
|
223
204
|
|
|
224
205
|
rescue => e
|
|
225
|
-
Brakeman.
|
|
206
|
+
Brakeman.alert "Error while processing #{path}"
|
|
226
207
|
tracker.error e.exception(e.message + "\nwhile processing #{path}"), e.backtrace
|
|
227
208
|
end
|
|
228
209
|
|
|
@@ -264,7 +245,7 @@ class Brakeman::Scanner
|
|
|
264
245
|
@processor.process_gems gem_files
|
|
265
246
|
end
|
|
266
247
|
rescue => e
|
|
267
|
-
Brakeman.
|
|
248
|
+
Brakeman.alert 'Error while processing Gemfile'
|
|
268
249
|
tracker.error e.exception(e.message + "\nWhile processing Gemfile"), e.backtrace
|
|
269
250
|
end
|
|
270
251
|
|
|
@@ -273,16 +254,16 @@ class Brakeman::Scanner
|
|
|
273
254
|
unless tracker.options[:rails3] or tracker.options[:rails4]
|
|
274
255
|
if @app_tree.exists?("script/rails")
|
|
275
256
|
tracker.options[:rails3] = true
|
|
276
|
-
Brakeman.
|
|
257
|
+
Brakeman.debug 'Detected Rails 3 application'
|
|
277
258
|
elsif @app_tree.exists?("app/channels")
|
|
278
259
|
tracker.options[:rails3] = true
|
|
279
260
|
tracker.options[:rails4] = true
|
|
280
261
|
tracker.options[:rails5] = true
|
|
281
|
-
Brakeman.
|
|
262
|
+
Brakeman.debug 'Detected Rails 5 application'
|
|
282
263
|
elsif not @app_tree.exists?("script")
|
|
283
264
|
tracker.options[:rails3] = true
|
|
284
265
|
tracker.options[:rails4] = true
|
|
285
|
-
Brakeman.
|
|
266
|
+
Brakeman.debug 'Detected Rails 4 application'
|
|
286
267
|
end
|
|
287
268
|
end
|
|
288
269
|
end
|
|
@@ -303,15 +284,10 @@ class Brakeman::Scanner
|
|
|
303
284
|
@processor.process_initializer(init.path, init.ast)
|
|
304
285
|
end
|
|
305
286
|
|
|
306
|
-
#
|
|
307
|
-
#
|
|
308
|
-
#
|
|
287
|
+
# Adds parsed information to tracker.libs.
|
|
288
|
+
# This is a catch-all for any Ruby files that weren't determined
|
|
289
|
+
# to be a specific type of file (like a controller).
|
|
309
290
|
def process_libs
|
|
310
|
-
if options[:skip_libs]
|
|
311
|
-
Brakeman.notify '[Skipping]'
|
|
312
|
-
return
|
|
313
|
-
end
|
|
314
|
-
|
|
315
291
|
libs = file_cache.libs.sort_by { |path, _| path }
|
|
316
292
|
|
|
317
293
|
track_progress libs do |path, lib|
|
|
@@ -335,11 +311,11 @@ class Brakeman::Scanner
|
|
|
335
311
|
if routes_sexp = parse_ruby_file(file)
|
|
336
312
|
@processor.process_routes routes_sexp
|
|
337
313
|
else
|
|
338
|
-
Brakeman.
|
|
314
|
+
Brakeman.alert 'Error while processing routes - assuming all public controller methods are actions.'
|
|
339
315
|
options[:assume_all_routes] = true
|
|
340
316
|
end
|
|
341
317
|
else
|
|
342
|
-
Brakeman.
|
|
318
|
+
Brakeman.alert 'No route information found'
|
|
343
319
|
end
|
|
344
320
|
end
|
|
345
321
|
|
|
@@ -427,15 +403,15 @@ class Brakeman::Scanner
|
|
|
427
403
|
total = list.length
|
|
428
404
|
current = 0
|
|
429
405
|
list.each do |item|
|
|
430
|
-
report_progress current, total
|
|
406
|
+
report_progress current, total
|
|
431
407
|
current += 1
|
|
432
408
|
yield item
|
|
433
409
|
end
|
|
434
410
|
end
|
|
435
411
|
|
|
436
|
-
def report_progress(current, total
|
|
412
|
+
def report_progress(current, total)
|
|
437
413
|
return unless @options[:report_progress]
|
|
438
|
-
|
|
414
|
+
Brakeman.logger.update_progress(current, total)
|
|
439
415
|
end
|
|
440
416
|
|
|
441
417
|
def index_call_sites
|
|
@@ -55,13 +55,23 @@ module Brakeman
|
|
|
55
55
|
if src.node_type == :defs
|
|
56
56
|
@class_methods[name] = meth_info
|
|
57
57
|
|
|
58
|
-
|
|
59
|
-
name = :"#{src[1]}.#{name}"
|
|
58
|
+
name = :"#{method_definition_receiver(src[1])}.#{name}"
|
|
60
59
|
end
|
|
61
60
|
|
|
62
61
|
@methods[visibility][name] = meth_info
|
|
63
62
|
end
|
|
64
63
|
|
|
64
|
+
def method_definition_receiver(receiver)
|
|
65
|
+
return receiver if receiver.is_a?(Symbol)
|
|
66
|
+
|
|
67
|
+
case receiver.sexp_type
|
|
68
|
+
when :self
|
|
69
|
+
"self"
|
|
70
|
+
else
|
|
71
|
+
receiver[1].to_s
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
|
|
65
75
|
def each_method
|
|
66
76
|
@methods.each do |_vis, meths|
|
|
67
77
|
meths.each do |name, info|
|
|
@@ -5,7 +5,7 @@ module Brakeman
|
|
|
5
5
|
include Util
|
|
6
6
|
|
|
7
7
|
attr_reader :gems, :rails, :ruby_version, :tracker
|
|
8
|
-
attr_writer :
|
|
8
|
+
attr_writer :erubi, :escape_html
|
|
9
9
|
|
|
10
10
|
def initialize tracker
|
|
11
11
|
@tracker = tracker
|
|
@@ -13,7 +13,7 @@ module Brakeman
|
|
|
13
13
|
@gems = {}
|
|
14
14
|
@settings = {}
|
|
15
15
|
@escape_html = nil
|
|
16
|
-
@
|
|
16
|
+
@erubi = nil
|
|
17
17
|
@ruby_version = nil
|
|
18
18
|
@rails_version = nil
|
|
19
19
|
end
|
|
@@ -28,8 +28,8 @@ module Brakeman
|
|
|
28
28
|
false
|
|
29
29
|
end
|
|
30
30
|
|
|
31
|
-
def
|
|
32
|
-
@
|
|
31
|
+
def erubi?
|
|
32
|
+
@erubi
|
|
33
33
|
end
|
|
34
34
|
|
|
35
35
|
def escape_html?
|
|
@@ -88,29 +88,29 @@ module Brakeman
|
|
|
88
88
|
if tracker.options[:rails3].nil? and tracker.options[:rails4].nil?
|
|
89
89
|
if @rails_version.start_with? "3"
|
|
90
90
|
tracker.options[:rails3] = true
|
|
91
|
-
|
|
91
|
+
notify_version 3
|
|
92
92
|
elsif @rails_version.start_with? "4"
|
|
93
93
|
tracker.options[:rails3] = true
|
|
94
94
|
tracker.options[:rails4] = true
|
|
95
|
-
|
|
95
|
+
notify_version 4
|
|
96
96
|
elsif @rails_version.start_with? "5"
|
|
97
97
|
tracker.options[:rails3] = true
|
|
98
98
|
tracker.options[:rails4] = true
|
|
99
99
|
tracker.options[:rails5] = true
|
|
100
|
-
|
|
100
|
+
notify_version 5
|
|
101
101
|
elsif @rails_version.start_with? "6"
|
|
102
102
|
tracker.options[:rails3] = true
|
|
103
103
|
tracker.options[:rails4] = true
|
|
104
104
|
tracker.options[:rails5] = true
|
|
105
105
|
tracker.options[:rails6] = true
|
|
106
|
-
|
|
106
|
+
notify_version 6
|
|
107
107
|
elsif @rails_version.start_with? "7"
|
|
108
108
|
tracker.options[:rails3] = true
|
|
109
109
|
tracker.options[:rails4] = true
|
|
110
110
|
tracker.options[:rails5] = true
|
|
111
111
|
tracker.options[:rails6] = true
|
|
112
112
|
tracker.options[:rails7] = true
|
|
113
|
-
|
|
113
|
+
notify_version 7
|
|
114
114
|
elsif @rails_version.start_with? "8"
|
|
115
115
|
tracker.options[:rails3] = true
|
|
116
116
|
tracker.options[:rails4] = true
|
|
@@ -118,14 +118,14 @@ module Brakeman
|
|
|
118
118
|
tracker.options[:rails6] = true
|
|
119
119
|
tracker.options[:rails7] = true
|
|
120
120
|
tracker.options[:rails8] = true
|
|
121
|
-
|
|
121
|
+
notify_version 8
|
|
122
122
|
end
|
|
123
123
|
end
|
|
124
124
|
end
|
|
125
125
|
|
|
126
126
|
if get_gem :rails_xss
|
|
127
127
|
@escape_html = true
|
|
128
|
-
Brakeman.
|
|
128
|
+
Brakeman.debug "Escaping HTML by default"
|
|
129
129
|
end
|
|
130
130
|
end
|
|
131
131
|
|
|
@@ -182,7 +182,7 @@ module Brakeman
|
|
|
182
182
|
option = config[o]
|
|
183
183
|
|
|
184
184
|
if not option.is_a? Hash
|
|
185
|
-
Brakeman.debug "
|
|
185
|
+
Brakeman.debug "Skipping config setting: #{path.map(&:to_s).join(".")}"
|
|
186
186
|
return
|
|
187
187
|
end
|
|
188
188
|
|
|
@@ -202,7 +202,7 @@ module Brakeman
|
|
|
202
202
|
version = tracker.config.rails[:load_defaults].value.to_s
|
|
203
203
|
|
|
204
204
|
unless version.match?(/^\d+\.\d+$/)
|
|
205
|
-
Brakeman.
|
|
205
|
+
Brakeman.alert "Unknown version: #{tracker.config.rails[:load_defaults]}"
|
|
206
206
|
return
|
|
207
207
|
end
|
|
208
208
|
|
|
@@ -284,5 +284,9 @@ module Brakeman
|
|
|
284
284
|
set_rails_config(value: true_value, path: [:active_support, :use_rfc4122_namespaced_uuids])
|
|
285
285
|
end
|
|
286
286
|
end
|
|
287
|
+
|
|
288
|
+
private def notify_version version
|
|
289
|
+
Brakeman.debug "Detected Rails #{version} application"
|
|
290
|
+
end
|
|
287
291
|
end
|
|
288
292
|
end
|
|
@@ -29,7 +29,7 @@ module Brakeman
|
|
|
29
29
|
|
|
30
30
|
def set_name name, context
|
|
31
31
|
@name = name
|
|
32
|
-
@name_array = Constants.constant_as_array(name)
|
|
32
|
+
@name_array = Constants.constant_as_array(name, context)
|
|
33
33
|
end
|
|
34
34
|
|
|
35
35
|
def match? name
|
|
@@ -129,7 +129,22 @@ module Brakeman
|
|
|
129
129
|
end
|
|
130
130
|
end
|
|
131
131
|
|
|
132
|
-
def self.constant_as_array exp
|
|
132
|
+
def self.constant_as_array exp, context = nil
|
|
133
|
+
# Only prepend context for simple (unqualified) constants
|
|
134
|
+
if context && (exp.is_a?(Symbol) || (exp.is_a?(Sexp) && exp.node_type == :const))
|
|
135
|
+
context_name = context[:module] || context[:class]
|
|
136
|
+
context_name = context_name.name if context_name.respond_to?(:name)
|
|
137
|
+
if context_name
|
|
138
|
+
# Build colon2 chain: A::B becomes s(:colon2, s(:const, :A), :B)
|
|
139
|
+
parts = context_name.to_s.split("::")
|
|
140
|
+
base = Sexp.new(:const, parts.first.to_sym)
|
|
141
|
+
parts[1..].each do |part|
|
|
142
|
+
base = Sexp.new(:colon2, base, part.to_sym)
|
|
143
|
+
end
|
|
144
|
+
exp = Sexp.new(:colon2, base, exp)
|
|
145
|
+
end
|
|
146
|
+
end
|
|
147
|
+
|
|
133
148
|
res = []
|
|
134
149
|
while exp
|
|
135
150
|
if exp.is_a? Sexp
|
|
@@ -132,7 +132,7 @@ module Brakeman
|
|
|
132
132
|
when :lit, :str
|
|
133
133
|
filter[option.value] = value[1]
|
|
134
134
|
else
|
|
135
|
-
Brakeman.debug "
|
|
135
|
+
Brakeman.debug "Unknown before_filter value: #{option} => #{value}"
|
|
136
136
|
end
|
|
137
137
|
end
|
|
138
138
|
else
|
data/lib/brakeman/tracker.rb
CHANGED
|
@@ -101,15 +101,9 @@ class Brakeman::Tracker
|
|
|
101
101
|
@app_path ||= File.expand_path @options[:app_path]
|
|
102
102
|
end
|
|
103
103
|
|
|
104
|
-
#Iterate over all methods
|
|
104
|
+
#Iterate over all methods
|
|
105
105
|
def each_method
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
if @options[:index_libs]
|
|
109
|
-
classes << self.libs
|
|
110
|
-
end
|
|
111
|
-
|
|
112
|
-
classes.each do |set|
|
|
106
|
+
[self.controllers, self.models, self.libs].each do |set|
|
|
113
107
|
set.each do |set_name, collection|
|
|
114
108
|
collection.each_method do |method_name, definition|
|
|
115
109
|
src = definition.src
|
|
@@ -137,13 +131,7 @@ class Brakeman::Tracker
|
|
|
137
131
|
|
|
138
132
|
|
|
139
133
|
def each_class
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
if @options[:index_libs]
|
|
143
|
-
classes << self.libs
|
|
144
|
-
end
|
|
145
|
-
|
|
146
|
-
classes.each do |set|
|
|
134
|
+
[self.controllers, self.models, self.libs].each do |set|
|
|
147
135
|
set.each do |set_name, collection|
|
|
148
136
|
collection.src.each do |file, src|
|
|
149
137
|
yield src, set_name, file
|
|
@@ -329,6 +317,8 @@ class Brakeman::Tracker
|
|
|
329
317
|
finder = Brakeman::FindAllCalls.new self
|
|
330
318
|
|
|
331
319
|
method_sets.each do |set|
|
|
320
|
+
Brakeman.logger.spin
|
|
321
|
+
|
|
332
322
|
set.each do |set_name, info|
|
|
333
323
|
info.each_method do |method_name, definition|
|
|
334
324
|
src = definition.src
|
|
@@ -339,12 +329,14 @@ class Brakeman::Tracker
|
|
|
339
329
|
|
|
340
330
|
if locations.include? :templates
|
|
341
331
|
self.each_template do |_name, template|
|
|
332
|
+
Brakeman.logger.spin
|
|
342
333
|
finder.process_source template.src, :template => template, :file => template.file
|
|
343
334
|
end
|
|
344
335
|
end
|
|
345
336
|
|
|
346
337
|
if locations.include? :initializers
|
|
347
338
|
self.initializers.each do |file_name, src|
|
|
339
|
+
Brakeman.logger.spin
|
|
348
340
|
finder.process_all_source src, :file => file_name
|
|
349
341
|
end
|
|
350
342
|
end
|
data/lib/brakeman/version.rb
CHANGED