brakeman 5.0.4 → 5.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGES.md +27 -0
  3. data/bundle/load.rb +1 -0
  4. data/bundle/ruby/2.7.0/gems/parallel-1.20.1/MIT-LICENSE.txt +20 -0
  5. data/bundle/ruby/2.7.0/gems/parallel-1.20.1/lib/parallel.rb +523 -0
  6. data/bundle/ruby/2.7.0/gems/parallel-1.20.1/lib/parallel/processor_count.rb +42 -0
  7. data/bundle/ruby/2.7.0/gems/parallel-1.20.1/lib/parallel/version.rb +3 -0
  8. data/lib/brakeman.rb +12 -4
  9. data/lib/brakeman/checks/check_detailed_exceptions.rb +1 -1
  10. data/lib/brakeman/checks/check_evaluation.rb +1 -1
  11. data/lib/brakeman/checks/check_execute.rb +10 -0
  12. data/lib/brakeman/checks/check_render.rb +15 -1
  13. data/lib/brakeman/checks/check_sql.rb +58 -8
  14. data/lib/brakeman/checks/check_verb_confusion.rb +1 -1
  15. data/lib/brakeman/commandline.rb +1 -1
  16. data/lib/brakeman/file_parser.rb +45 -15
  17. data/lib/brakeman/options.rb +7 -2
  18. data/lib/brakeman/processors/alias_processor.rb +85 -9
  19. data/lib/brakeman/processors/controller_alias_processor.rb +6 -43
  20. data/lib/brakeman/processors/lib/call_conversion_helper.rb +10 -6
  21. data/lib/brakeman/processors/library_processor.rb +9 -0
  22. data/lib/brakeman/processors/model_processor.rb +31 -0
  23. data/lib/brakeman/report.rb +4 -1
  24. data/lib/brakeman/report/ignore/config.rb +4 -4
  25. data/lib/brakeman/report/ignore/interactive.rb +1 -1
  26. data/lib/brakeman/report/report_github.rb +31 -0
  27. data/lib/brakeman/report/report_sarif.rb +21 -2
  28. data/lib/brakeman/rescanner.rb +1 -1
  29. data/lib/brakeman/scanner.rb +4 -1
  30. data/lib/brakeman/tracker.rb +33 -4
  31. data/lib/brakeman/tracker/collection.rb +57 -7
  32. data/lib/brakeman/tracker/method_info.rb +70 -0
  33. data/lib/brakeman/util.rb +34 -18
  34. data/lib/brakeman/version.rb +1 -1
  35. data/lib/ruby_parser/bm_sexp.rb +14 -0
  36. metadata +8 -2
@@ -0,0 +1,70 @@
1
+ require 'brakeman/util'
2
+
3
+ module Brakeman
4
+ class MethodInfo
5
+ include Brakeman::Util
6
+
7
+ attr_reader :name, :src, :owner, :file, :type
8
+
9
+ def initialize name, src, owner, file
10
+ @name = name
11
+ @src = src
12
+ @owner = owner
13
+ @file = file
14
+ @type = case src.node_type
15
+ when :defn
16
+ :instance
17
+ when :defs
18
+ :class
19
+ else
20
+ raise "Expected sexp type: #{src.node_type}"
21
+ end
22
+
23
+ @simple_method = nil
24
+ end
25
+
26
+ # To support legacy code that expected a Hash
27
+ def [] attr
28
+ self.send(attr)
29
+ end
30
+
31
+ def very_simple_method?
32
+ return @simple_method == :very unless @simple_method.nil?
33
+
34
+ # Very simple methods have one (simple) expression in the body and
35
+ # no arguments
36
+ if src.formal_args.length == 1 # no args
37
+ if src.method_length == 1 # Single expression in body
38
+ value = first_body # First expression in body
39
+
40
+ if simple_literal? value or
41
+ (array? value and all_literals? value) or
42
+ (hash? value and all_literals? value, :hash)
43
+
44
+ @return_value = value
45
+ @simple_method = :very
46
+ end
47
+ end
48
+ end
49
+
50
+ @simple_method ||= false
51
+ end
52
+
53
+ def return_value env = nil
54
+ if very_simple_method?
55
+ return @return_value
56
+ else
57
+ nil
58
+ end
59
+ end
60
+
61
+ def first_body
62
+ case @type
63
+ when :class
64
+ src[4]
65
+ when :instance
66
+ src[3]
67
+ end
68
+ end
69
+ end
70
+ end
data/lib/brakeman/util.rb CHANGED
@@ -50,7 +50,11 @@ module Brakeman::Util
50
50
 
51
51
  # stupid simple, used to delegate to ActiveSupport
52
52
  def pluralize word
53
- word + "s"
53
+ if word.end_with? 's'
54
+ word + 'es'
55
+ else
56
+ word + 's'
57
+ end
54
58
  end
55
59
 
56
60
  #Returns a class name as a Symbol.
@@ -142,6 +146,14 @@ module Brakeman::Util
142
146
  nil
143
147
  end
144
148
 
149
+ def hash_values hash
150
+ values = hash.each_sexp.each_slice(2).map do |_, value|
151
+ value
152
+ end
153
+
154
+ Sexp.new(:array).concat(values).line(hash.line)
155
+ end
156
+
145
157
  #These are never modified
146
158
  PARAMS_SEXP = Sexp.new(:params)
147
159
  SESSION_SEXP = Sexp.new(:session)
@@ -230,30 +242,22 @@ module Brakeman::Util
230
242
 
231
243
  #Check if _exp_ is a params hash
232
244
  def params? exp
233
- if exp.is_a? Sexp
234
- return true if exp.node_type == :params or ALL_PARAMETERS.include? exp
235
-
236
- if call? exp
237
- if params? exp[1]
238
- return true
239
- elsif exp[2] == :[]
240
- return params? exp[1]
241
- end
242
- end
243
- end
244
-
245
- false
245
+ recurse_check?(exp) { |child| child.node_type == :params or ALL_PARAMETERS.include? child }
246
246
  end
247
247
 
248
248
  def cookies? exp
249
+ recurse_check?(exp) { |child| child.node_type == :cookies or ALL_COOKIES.include? child }
250
+ end
251
+
252
+ def recurse_check? exp, &check
249
253
  if exp.is_a? Sexp
250
- return true if exp.node_type == :cookies or ALL_COOKIES.include? exp
254
+ return true if yield(exp)
251
255
 
252
256
  if call? exp
253
- if cookies? exp[1]
257
+ if recurse_check? exp[1], &check
254
258
  return true
255
259
  elsif exp[2] == :[]
256
- return cookies? exp[1]
260
+ return recurse_check? exp[1], &check
257
261
  end
258
262
  end
259
263
  end
@@ -293,12 +297,24 @@ module Brakeman::Util
293
297
  exp.is_a? Sexp and types.include? exp.node_type
294
298
  end
295
299
 
296
- LITERALS = [:lit, :false, :str, :true, :array, :hash]
300
+ SIMPLE_LITERALS = [:lit, :false, :str, :true]
301
+
302
+ def simple_literal? exp
303
+ exp.is_a? Sexp and SIMPLE_LITERALS.include? exp.node_type
304
+ end
305
+
306
+ LITERALS = [*SIMPLE_LITERALS, :array, :hash]
297
307
 
298
308
  def literal? exp
299
309
  exp.is_a? Sexp and LITERALS.include? exp.node_type
300
310
  end
301
311
 
312
+ def all_literals? exp, expected_type = :array
313
+ node_type? exp, expected_type and
314
+ exp.length > 1 and
315
+ exp.all? { |e| e.is_a? Symbol or node_type? e, :lit, :str }
316
+ end
317
+
302
318
  DIR_CONST = s(:const, :Dir)
303
319
 
304
320
  # Dir.glob(...).whatever
@@ -1,3 +1,3 @@
1
1
  module Brakeman
2
- Version = "5.0.4"
2
+ Version = "5.1.0"
3
3
  end
@@ -543,6 +543,20 @@ class Sexp
543
543
  self.body.unshift :rlist
544
544
  end
545
545
 
546
+ # Number of "statements" in a method.
547
+ # This is more effecient than `Sexp#body.length`
548
+ # because `Sexp#body` creates a new Sexp.
549
+ def method_length
550
+ expect :defn, :defs
551
+
552
+ case self.node_type
553
+ when :defn
554
+ self.length - 3
555
+ when :defs
556
+ self.length - 4
557
+ end
558
+ end
559
+
546
560
  def render_type
547
561
  expect :render
548
562
  self[1]
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: brakeman
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.0.4
4
+ version: 5.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Collins
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-06-08 00:00:00.000000000 Z
11
+ date: 2021-07-19 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Brakeman detects security vulnerabilities in Ruby on Rails applications
14
14
  via static analysis.
@@ -132,6 +132,10 @@ files:
132
132
  - bundle/ruby/2.7.0/gems/highline-2.0.3/lib/highline/terminal/unix_stty.rb
133
133
  - bundle/ruby/2.7.0/gems/highline-2.0.3/lib/highline/version.rb
134
134
  - bundle/ruby/2.7.0/gems/highline-2.0.3/lib/highline/wrapper.rb
135
+ - bundle/ruby/2.7.0/gems/parallel-1.20.1/MIT-LICENSE.txt
136
+ - bundle/ruby/2.7.0/gems/parallel-1.20.1/lib/parallel.rb
137
+ - bundle/ruby/2.7.0/gems/parallel-1.20.1/lib/parallel/processor_count.rb
138
+ - bundle/ruby/2.7.0/gems/parallel-1.20.1/lib/parallel/version.rb
135
139
  - bundle/ruby/2.7.0/gems/rexml-3.2.5/LICENSE.txt
136
140
  - bundle/ruby/2.7.0/gems/rexml-3.2.5/NEWS.md
137
141
  - bundle/ruby/2.7.0/gems/rexml-3.2.5/README.md
@@ -568,6 +572,7 @@ files:
568
572
  - lib/brakeman/report/report_base.rb
569
573
  - lib/brakeman/report/report_codeclimate.rb
570
574
  - lib/brakeman/report/report_csv.rb
575
+ - lib/brakeman/report/report_github.rb
571
576
  - lib/brakeman/report/report_hash.rb
572
577
  - lib/brakeman/report/report_html.rb
573
578
  - lib/brakeman/report/report_json.rb
@@ -597,6 +602,7 @@ files:
597
602
  - lib/brakeman/tracker/constants.rb
598
603
  - lib/brakeman/tracker/controller.rb
599
604
  - lib/brakeman/tracker/library.rb
605
+ - lib/brakeman/tracker/method_info.rb
600
606
  - lib/brakeman/tracker/model.rb
601
607
  - lib/brakeman/tracker/template.rb
602
608
  - lib/brakeman/util.rb