brakeman-min 4.9.1 → 5.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGES.md +46 -0
  3. data/README.md +11 -2
  4. data/lib/brakeman.rb +21 -4
  5. data/lib/brakeman/app_tree.rb +36 -3
  6. data/lib/brakeman/checks/base_check.rb +7 -1
  7. data/lib/brakeman/checks/check_execute.rb +2 -1
  8. data/lib/brakeman/checks/check_mass_assignment.rb +4 -6
  9. data/lib/brakeman/checks/check_regex_dos.rb +1 -1
  10. data/lib/brakeman/checks/check_sql.rb +1 -1
  11. data/lib/brakeman/checks/check_unsafe_reflection_methods.rb +68 -0
  12. data/lib/brakeman/checks/check_verb_confusion.rb +75 -0
  13. data/lib/brakeman/file_parser.rb +24 -18
  14. data/lib/brakeman/options.rb +5 -1
  15. data/lib/brakeman/parsers/template_parser.rb +26 -3
  16. data/lib/brakeman/processors/alias_processor.rb +40 -13
  17. data/lib/brakeman/processors/base_processor.rb +4 -4
  18. data/lib/brakeman/processors/controller_processor.rb +1 -1
  19. data/lib/brakeman/processors/haml_template_processor.rb +8 -1
  20. data/lib/brakeman/processors/lib/file_type_detector.rb +64 -0
  21. data/lib/brakeman/processors/lib/rails3_config_processor.rb +16 -16
  22. data/lib/brakeman/processors/lib/rails4_config_processor.rb +2 -1
  23. data/lib/brakeman/processors/output_processor.rb +1 -1
  24. data/lib/brakeman/processors/template_alias_processor.rb +5 -0
  25. data/lib/brakeman/report.rb +15 -0
  26. data/lib/brakeman/report/report_base.rb +0 -2
  27. data/lib/brakeman/report/report_csv.rb +37 -60
  28. data/lib/brakeman/report/report_junit.rb +2 -2
  29. data/lib/brakeman/report/report_sarif.rb +114 -0
  30. data/lib/brakeman/report/report_sonar.rb +38 -0
  31. data/lib/brakeman/report/report_tabs.rb +1 -1
  32. data/lib/brakeman/report/report_text.rb +1 -1
  33. data/lib/brakeman/rescanner.rb +7 -5
  34. data/lib/brakeman/scanner.rb +44 -18
  35. data/lib/brakeman/tracker.rb +6 -0
  36. data/lib/brakeman/tracker/config.rb +73 -0
  37. data/lib/brakeman/tracker/controller.rb +1 -1
  38. data/lib/brakeman/util.rb +9 -4
  39. data/lib/brakeman/version.rb +1 -1
  40. data/lib/brakeman/warning.rb +10 -2
  41. data/lib/brakeman/warning_codes.rb +2 -0
  42. data/lib/ruby_parser/bm_sexp.rb +9 -9
  43. metadata +8 -3
@@ -68,6 +68,12 @@ class Brakeman::Tracker
68
68
  }
69
69
  end
70
70
 
71
+ def add_errors exceptions
72
+ exceptions.each do |e|
73
+ error(e)
74
+ end
75
+ end
76
+
71
77
  #Run a set of checks on the current information. Results will be stored
72
78
  #in Tracker#checks.
73
79
  def run_checks
@@ -149,5 +149,78 @@ module Brakeman
149
149
  def session_settings
150
150
  @rails.dig(:action_controller, :session)
151
151
  end
152
+
153
+
154
+ # Set Rails config option value
155
+ # where path is an array of attributes, e.g.
156
+ #
157
+ # :action_controller, :perform_caching
158
+ #
159
+ # then this will set
160
+ #
161
+ # rails[:action_controller][:perform_caching] = value
162
+ def set_rails_config value, *path
163
+ config = self.rails
164
+
165
+ path[0..-2].each do |o|
166
+ config[o] ||= {}
167
+
168
+ option = config[o]
169
+
170
+ if not option.is_a? Hash
171
+ Brakeman.debug "[Notice] Skipping config setting: #{path.map(&:to_s).join(".")}"
172
+ return
173
+ end
174
+
175
+ config = option
176
+ end
177
+
178
+ config[path.last] = value
179
+ end
180
+
181
+ # Load defaults based on config.load_defaults value
182
+ # as documented here: https://guides.rubyonrails.org/configuring.html#results-of-config-load-defaults
183
+ def load_rails_defaults
184
+ return unless number? tracker.config.rails[:load_defaults]
185
+
186
+ version = tracker.config.rails[:load_defaults].value
187
+ true_value = Sexp.new(:true)
188
+ false_value = Sexp.new(:false)
189
+
190
+ if version >= 5.0
191
+ set_rails_config(true_value, :action_controller, :per_form_csrf_tokens)
192
+ set_rails_config(true_value, :action_controller, :forgery_protection_origin_check)
193
+ set_rails_config(true_value, :active_record, :belongs_to_required_by_default)
194
+ # Note: this may need to be changed, because ssl_options is a Hash
195
+ set_rails_config(true_value, :ssl_options, :hsts, :subdomains)
196
+ end
197
+
198
+ if version >= 5.1
199
+ set_rails_config(false_value, :assets, :unknown_asset_fallback)
200
+ set_rails_config(true_value, :action_view, :form_with_generates_remote_forms)
201
+ end
202
+
203
+ if version >= 5.2
204
+ set_rails_config(true_value, :active_record, :cache_versioning)
205
+ set_rails_config(true_value, :action_dispatch, :use_authenticated_cookie_encryption)
206
+ set_rails_config(true_value, :active_support, :use_authenticated_message_encryption)
207
+ set_rails_config(true_value, :active_support, :use_sha1_digests)
208
+ set_rails_config(true_value, :action_controller, :default_protect_from_forgery)
209
+ set_rails_config(true_value, :action_view, :form_with_generates_ids)
210
+ end
211
+
212
+ if version >= 6.0
213
+ set_rails_config(Sexp.new(:lit, :zeitwerk), :autoloader)
214
+ set_rails_config(false_value, :action_view, :default_enforce_utf8)
215
+ set_rails_config(true_value, :action_dispatch, :use_cookies_with_metadata)
216
+ set_rails_config(false_value, :action_dispatch, :return_only_media_type_on_content_type)
217
+ set_rails_config(Sexp.new(:str, 'ActionMailer::MailDeliveryJob'), :action_mailer, :delivery_job)
218
+ set_rails_config(true_value, :active_job, :return_false_on_aborted_enqueue)
219
+ set_rails_config(Sexp.new(:lit, :active_storage_analysis), :active_storage, :queues, :analysis)
220
+ set_rails_config(Sexp.new(:lit, :active_storage_purge), :active_storage, :queues, :purge)
221
+ set_rails_config(true_value, :active_storage, :replace_on_assign_to_many)
222
+ set_rails_config(true_value, :active_record, :collection_cache_versioning)
223
+ end
224
+ end
152
225
  end
153
226
  end
@@ -125,7 +125,7 @@ module Brakeman
125
125
  value = args[-1][2]
126
126
  case value.node_type
127
127
  when :array
128
- filter[option] = value[1..-1].map {|v| v[1] }
128
+ filter[option] = value.sexp_body.map {|v| v[1] }
129
129
  when :lit, :str
130
130
  filter[option] = value[1]
131
131
  else
data/lib/brakeman/util.rb CHANGED
@@ -321,7 +321,7 @@ module Brakeman::Util
321
321
  if node_type? current, :class
322
322
  return true
323
323
  elsif sexp? current
324
- todo = current[1..-1].concat todo
324
+ todo = current.sexp_body.concat todo
325
325
  end
326
326
  end
327
327
 
@@ -334,7 +334,7 @@ module Brakeman::Util
334
334
  if args.empty? or args.first.empty?
335
335
  #nothing to do
336
336
  elsif node_type? args.first, :arglist
337
- call.concat args.first[1..-1]
337
+ call.concat args.first.sexp_body
338
338
  elsif args.first.node_type.is_a? Sexp #just a list of args
339
339
  call.concat args.first
340
340
  else
@@ -368,8 +368,13 @@ module Brakeman::Util
368
368
  #
369
369
  # views/test/something.html.erb -> test/something
370
370
  def template_path_to_name path
371
- names = path.relative.split("/")
371
+ names = path.relative.split('/')
372
372
  names.last.gsub!(/(\.(html|js)\..*|\.(rhtml|haml|erb|slim))$/, '')
373
- names[(names.index("views") + 1)..-1].join("/").to_sym
373
+
374
+ if names.include? 'views'
375
+ names[(names.index('views') + 1)..-1]
376
+ else
377
+ names
378
+ end.join('/').to_sym
374
379
  end
375
380
  end
@@ -1,3 +1,3 @@
1
1
  module Brakeman
2
- Version = "4.9.1"
2
+ Version = "5.0.1"
3
3
  end
@@ -275,6 +275,14 @@ class Brakeman::Warning
275
275
  self.file.relative
276
276
  end
277
277
 
278
+ def check_name
279
+ @check_name ||= self.check.sub(/^Brakeman::Check/, '')
280
+ end
281
+
282
+ def confidence_name
283
+ TEXT_CONFIDENCE[self.confidence]
284
+ end
285
+
278
286
  def to_hash absolute_paths: true
279
287
  if self.called_from and not absolute_paths
280
288
  render_path = self.called_from.with_relative_paths
@@ -285,7 +293,7 @@ class Brakeman::Warning
285
293
  { :warning_type => self.warning_type,
286
294
  :warning_code => @warning_code,
287
295
  :fingerprint => self.fingerprint,
288
- :check_name => self.check.gsub(/^Brakeman::Check/, ''),
296
+ :check_name => self.check_name,
289
297
  :message => self.message.to_s,
290
298
  :file => (absolute_paths ? self.file.absolute : self.file.relative),
291
299
  :line => self.line,
@@ -294,7 +302,7 @@ class Brakeman::Warning
294
302
  :render_path => render_path,
295
303
  :location => self.location(false),
296
304
  :user_input => (@user_input && self.format_user_input(false)),
297
- :confidence => TEXT_CONFIDENCE[self.confidence]
305
+ :confidence => self.confidence_name
298
306
  }
299
307
  end
300
308
 
@@ -119,6 +119,8 @@ module Brakeman::WarningCodes
119
119
  :CVE_2020_8159 => 115,
120
120
  :CVE_2020_8166 => 116,
121
121
  :erb_template_injection => 117,
122
+ :http_verb_confusion => 118,
123
+ :unsafe_method_reflection => 119,
122
124
 
123
125
  :custom_check => 9090,
124
126
  }
@@ -175,7 +175,7 @@ class Sexp
175
175
  start_index = 3
176
176
 
177
177
  if exp.is_a? Sexp and exp.node_type == :arglist
178
- exp = exp[1..-1]
178
+ exp = exp.sexp_body
179
179
  end
180
180
 
181
181
  exp.each_with_index do |e, i|
@@ -198,10 +198,10 @@ class Sexp
198
198
 
199
199
  case self.node_type
200
200
  when :call, :attrasgn, :safe_call, :safe_attrasgn
201
- self[3..-1].unshift :arglist
201
+ self.sexp_body(3).unshift :arglist
202
202
  when :super, :zsuper
203
203
  if self[1]
204
- self[1..-1].unshift :arglist
204
+ self.sexp_body.unshift :arglist
205
205
  else
206
206
  Sexp.new(:arglist)
207
207
  end
@@ -218,13 +218,13 @@ class Sexp
218
218
  case self.node_type
219
219
  when :call, :attrasgn, :safe_call, :safe_attrasgn
220
220
  if self[3]
221
- self[3..-1]
221
+ self.sexp_body(3)
222
222
  else
223
223
  Sexp.new
224
224
  end
225
225
  when :super, :zsuper
226
226
  if self[1]
227
- self[1..-1]
227
+ self.sexp_body
228
228
  else
229
229
  Sexp.new
230
230
  end
@@ -512,7 +512,7 @@ class Sexp
512
512
  self.slice!(index..-1) #Remove old body
513
513
 
514
514
  if exp.first == :rlist
515
- exp = exp[1..-1]
515
+ exp = exp.sexp_body
516
516
  end
517
517
 
518
518
  #Insert new body
@@ -529,11 +529,11 @@ class Sexp
529
529
 
530
530
  case self.node_type
531
531
  when :defn, :class
532
- self[3..-1]
532
+ self.sexp_body(3)
533
533
  when :defs
534
- self[4..-1]
534
+ self.sexp_body(4)
535
535
  when :module
536
- self[2..-1]
536
+ self.sexp_body(2)
537
537
  end
538
538
  end
539
539
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: brakeman-min
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.9.1
4
+ version: 5.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Collins
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-09-04 00:00:00.000000000 Z
11
+ date: 2021-04-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest
@@ -225,8 +225,10 @@ files:
225
225
  - lib/brakeman/checks/check_template_injection.rb
226
226
  - lib/brakeman/checks/check_translate_bug.rb
227
227
  - lib/brakeman/checks/check_unsafe_reflection.rb
228
+ - lib/brakeman/checks/check_unsafe_reflection_methods.rb
228
229
  - lib/brakeman/checks/check_unscoped_find.rb
229
230
  - lib/brakeman/checks/check_validation_regex.rb
231
+ - lib/brakeman/checks/check_verb_confusion.rb
230
232
  - lib/brakeman/checks/check_weak_hash.rb
231
233
  - lib/brakeman/checks/check_without_protection.rb
232
234
  - lib/brakeman/checks/check_xml_dos.rb
@@ -257,6 +259,7 @@ files:
257
259
  - lib/brakeman/processors/haml_template_processor.rb
258
260
  - lib/brakeman/processors/lib/basic_processor.rb
259
261
  - lib/brakeman/processors/lib/call_conversion_helper.rb
262
+ - lib/brakeman/processors/lib/file_type_detector.rb
260
263
  - lib/brakeman/processors/lib/find_all_calls.rb
261
264
  - lib/brakeman/processors/lib/find_call.rb
262
265
  - lib/brakeman/processors/lib/find_return_value.rb
@@ -292,6 +295,8 @@ files:
292
295
  - lib/brakeman/report/report_json.rb
293
296
  - lib/brakeman/report/report_junit.rb
294
297
  - lib/brakeman/report/report_markdown.rb
298
+ - lib/brakeman/report/report_sarif.rb
299
+ - lib/brakeman/report/report_sonar.rb
295
300
  - lib/brakeman/report/report_table.rb
296
301
  - lib/brakeman/report/report_tabs.rb
297
302
  - lib/brakeman/report/report_text.rb
@@ -341,7 +346,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
341
346
  requirements:
342
347
  - - ">="
343
348
  - !ruby/object:Gem::Version
344
- version: '0'
349
+ version: 2.4.0
345
350
  required_rubygems_version: !ruby/object:Gem::Requirement
346
351
  requirements:
347
352
  - - ">="