brakeman-min 3.7.2 → 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (87) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGES +15 -1
  3. data/FEATURES +1 -1
  4. data/lib/brakeman.rb +55 -17
  5. data/lib/brakeman/call_index.rb +2 -2
  6. data/lib/brakeman/checks/base_check.rb +4 -2
  7. data/lib/brakeman/checks/check_basic_auth.rb +3 -3
  8. data/lib/brakeman/checks/check_basic_auth_timing_attack.rb +1 -1
  9. data/lib/brakeman/checks/check_content_tag.rb +12 -12
  10. data/lib/brakeman/checks/check_create_with.rb +5 -5
  11. data/lib/brakeman/checks/check_cross_site_scripting.rb +8 -8
  12. data/lib/brakeman/checks/check_default_routes.rb +4 -4
  13. data/lib/brakeman/checks/check_deserialize.rb +2 -2
  14. data/lib/brakeman/checks/check_detailed_exceptions.rb +4 -4
  15. data/lib/brakeman/checks/check_digest_dos.rb +2 -2
  16. data/lib/brakeman/checks/check_dynamic_finders.rb +1 -1
  17. data/lib/brakeman/checks/check_escape_function.rb +2 -2
  18. data/lib/brakeman/checks/check_evaluation.rb +1 -1
  19. data/lib/brakeman/checks/check_execute.rb +5 -5
  20. data/lib/brakeman/checks/check_file_access.rb +4 -4
  21. data/lib/brakeman/checks/check_file_disclosure.rb +2 -2
  22. data/lib/brakeman/checks/check_filter_skipping.rb +2 -2
  23. data/lib/brakeman/checks/check_forgery_setting.rb +2 -2
  24. data/lib/brakeman/checks/check_header_dos.rb +1 -1
  25. data/lib/brakeman/checks/check_i18n_xss.rb +2 -2
  26. data/lib/brakeman/checks/check_jruby_xml.rb +2 -4
  27. data/lib/brakeman/checks/check_json_encoding.rb +4 -4
  28. data/lib/brakeman/checks/check_json_parsing.rb +6 -6
  29. data/lib/brakeman/checks/check_link_to.rb +5 -5
  30. data/lib/brakeman/checks/check_link_to_href.rb +37 -31
  31. data/lib/brakeman/checks/check_mail_to.rb +2 -2
  32. data/lib/brakeman/checks/check_mass_assignment.rb +6 -6
  33. data/lib/brakeman/checks/check_mime_type_dos.rb +1 -1
  34. data/lib/brakeman/checks/check_model_attr_accessible.rb +5 -5
  35. data/lib/brakeman/checks/check_model_attributes.rb +4 -4
  36. data/lib/brakeman/checks/check_model_serialize.rb +3 -3
  37. data/lib/brakeman/checks/check_nested_attributes.rb +2 -2
  38. data/lib/brakeman/checks/check_nested_attributes_bypass.rb +1 -1
  39. data/lib/brakeman/checks/check_number_to_currency.rb +5 -5
  40. data/lib/brakeman/checks/check_quote_table_name.rb +2 -2
  41. data/lib/brakeman/checks/check_redirect.rb +2 -2
  42. data/lib/brakeman/checks/check_regex_dos.rb +3 -3
  43. data/lib/brakeman/checks/check_render.rb +4 -4
  44. data/lib/brakeman/checks/check_render_dos.rb +1 -1
  45. data/lib/brakeman/checks/check_render_inline.rb +5 -5
  46. data/lib/brakeman/checks/check_response_splitting.rb +1 -1
  47. data/lib/brakeman/checks/check_route_dos.rb +1 -1
  48. data/lib/brakeman/checks/check_safe_buffer_manipulation.rb +2 -2
  49. data/lib/brakeman/checks/check_sanitize_methods.rb +7 -7
  50. data/lib/brakeman/checks/check_secrets.rb +1 -1
  51. data/lib/brakeman/checks/check_select_tag.rb +2 -2
  52. data/lib/brakeman/checks/check_select_vulnerability.rb +3 -3
  53. data/lib/brakeman/checks/check_send.rb +1 -1
  54. data/lib/brakeman/checks/check_session_manipulation.rb +2 -2
  55. data/lib/brakeman/checks/check_session_settings.rb +3 -3
  56. data/lib/brakeman/checks/check_simple_format.rb +4 -4
  57. data/lib/brakeman/checks/check_single_quotes.rb +3 -3
  58. data/lib/brakeman/checks/check_skip_before_filter.rb +3 -3
  59. data/lib/brakeman/checks/check_sql.rb +9 -9
  60. data/lib/brakeman/checks/check_sql_cves.rb +2 -2
  61. data/lib/brakeman/checks/check_ssl_verify.rb +1 -1
  62. data/lib/brakeman/checks/check_strip_tags.rb +7 -7
  63. data/lib/brakeman/checks/check_symbol_dos.rb +2 -2
  64. data/lib/brakeman/checks/check_symbol_dos_cve.rb +1 -1
  65. data/lib/brakeman/checks/check_translate_bug.rb +3 -3
  66. data/lib/brakeman/checks/check_unsafe_reflection.rb +2 -2
  67. data/lib/brakeman/checks/check_unscoped_find.rb +1 -1
  68. data/lib/brakeman/checks/check_validation_regex.rb +1 -1
  69. data/lib/brakeman/checks/check_weak_hash.rb +6 -6
  70. data/lib/brakeman/checks/check_without_protection.rb +2 -2
  71. data/lib/brakeman/checks/check_xml_dos.rb +1 -1
  72. data/lib/brakeman/checks/check_yaml_parsing.rb +2 -2
  73. data/lib/brakeman/commandline.rb +2 -2
  74. data/lib/brakeman/options.rb +9 -5
  75. data/lib/brakeman/processors/alias_processor.rb +3 -1
  76. data/lib/brakeman/processors/lib/rails2_route_processor.rb +8 -8
  77. data/lib/brakeman/processors/lib/render_helper.rb +3 -3
  78. data/lib/brakeman/report.rb +9 -6
  79. data/lib/brakeman/report/report_base.rb +2 -1
  80. data/lib/brakeman/report/report_text.rb +4 -6
  81. data/lib/brakeman/rescanner.rb +8 -8
  82. data/lib/brakeman/tracker.rb +3 -3
  83. data/lib/brakeman/tracker/collection.rb +1 -1
  84. data/lib/brakeman/util.rb +5 -1
  85. data/lib/brakeman/version.rb +1 -1
  86. data/lib/brakeman/warning.rb +49 -21
  87. metadata +2 -2
@@ -62,7 +62,7 @@ module Brakeman::RenderHelper
62
62
  template = @tracker.templates[name.to_sym]
63
63
  unless template
64
64
  Brakeman.debug "[Notice] No such template: #{name}"
65
- return
65
+ return
66
66
  end
67
67
 
68
68
  template_env = only_ivars(:include_request_vars)
@@ -87,7 +87,7 @@ module Brakeman::RenderHelper
87
87
  #nothing
88
88
  elsif not template.name.to_s.match(/[^\/_][^\/]+$/)
89
89
  #Don't do this for partials
90
-
90
+
91
91
  process_layout
92
92
  end
93
93
 
@@ -117,7 +117,7 @@ module Brakeman::RenderHelper
117
117
 
118
118
  #Set original_line for values so it is clear
119
119
  #that values came from another file
120
- template_env.all.each do |var, value|
120
+ template_env.all.each do |_var, value|
121
121
  unless value.original_line
122
122
  #TODO: This has been broken for a while now and no one noticed
123
123
  #so maybe we can skip it
@@ -6,7 +6,7 @@ require 'brakeman/report/report_base'
6
6
  class Brakeman::Report
7
7
  attr_reader :tracker
8
8
 
9
- VALID_FORMATS = [:to_html, :to_pdf, :to_csv, :to_json, :to_tabs, :to_hash, :to_s, :to_markdown, :to_codeclimate, :to_plain]
9
+ VALID_FORMATS = [:to_html, :to_pdf, :to_csv, :to_json, :to_tabs, :to_hash, :to_s, :to_markdown, :to_codeclimate, :to_plain, :to_text]
10
10
 
11
11
  def initialize app_tree, tracker
12
12
  @app_tree = app_tree
@@ -34,10 +34,10 @@ class Brakeman::Report
34
34
  Brakeman::Report::Hash
35
35
  when :to_markdown
36
36
  return self.to_markdown
37
- when :to_plain
37
+ when :to_plain, :to_text, :to_s
38
38
  return self.to_plain
39
- when :to_s
40
- return self.to_s
39
+ when :to_table
40
+ return self.to_table
41
41
  when :to_pdf
42
42
  raise "PDF output is not yet supported."
43
43
  else
@@ -64,7 +64,7 @@ class Brakeman::Report
64
64
  generate Brakeman::Report::JSON
65
65
  end
66
66
 
67
- def to_s
67
+ def to_table
68
68
  require_report 'table'
69
69
  generate Brakeman::Report::Table
70
70
  end
@@ -74,11 +74,14 @@ class Brakeman::Report
74
74
  generate Brakeman::Report::Markdown
75
75
  end
76
76
 
77
- def to_plain
77
+ def to_text
78
78
  require_report 'text'
79
79
  generate Brakeman::Report::Text
80
80
  end
81
81
 
82
+ alias to_plain to_text
83
+ alias to_s to_text
84
+
82
85
  def generate reporter
83
86
  reporter.new(@app_tree, @tracker).generate_report
84
87
  end
@@ -3,6 +3,7 @@ require 'brakeman/util'
3
3
  require 'brakeman/version'
4
4
  require 'brakeman/report/renderer'
5
5
  require 'brakeman/processors/output_processor'
6
+ require 'brakeman/warning'
6
7
 
7
8
  # Base class for report formats
8
9
  class Brakeman::Report::Base
@@ -10,7 +11,7 @@ class Brakeman::Report::Base
10
11
 
11
12
  attr_reader :tracker, :checks
12
13
 
13
- TEXT_CONFIDENCE = [ "High", "Medium", "Weak" ]
14
+ TEXT_CONFIDENCE = Brakeman::Warning::TEXT_CONFIDENCE
14
15
 
15
16
  def initialize app_tree, tracker
16
17
  @app_tree = app_tree
@@ -186,12 +186,10 @@ class Brakeman::Report::Text < Brakeman::Report::Base
186
186
  # ONLY used for generate_controllers to avoid duplication
187
187
  def render_array name, cols, values, locals
188
188
  controllers = values.map do |name, parent, includes, routes|
189
- [
190
- label("Controller", name),
191
- label("Parent", parent),
192
- label("Includes", includes),
193
- label("Routes", routes)
194
- ]
189
+ c = [ label("Controller", name) ]
190
+ c << label("Parent", parent) unless parent.empty?
191
+ c << label("Includes", includes) unless includes.empty?
192
+ c << label("Routes", routes)
195
193
  end
196
194
 
197
195
  double_space "Controller Overview", controllers
@@ -143,7 +143,7 @@ class Brakeman::Rescanner < Brakeman::Scanner
143
143
 
144
144
  #Search for processed template and process it.
145
145
  #Search for rendered versions of template and re-render (if necessary)
146
- tracker.templates.each do |name, template|
146
+ tracker.templates.each do |_name, template|
147
147
  if template.file == path or template.file.nil?
148
148
  next unless template.render_path and template.name.to_sym == template_name.to_sym
149
149
 
@@ -204,7 +204,7 @@ class Brakeman::Rescanner < Brakeman::Scanner
204
204
 
205
205
  lib = nil
206
206
 
207
- tracker.libs.each do |name, library|
207
+ tracker.libs.each do |_name, library|
208
208
  if library.files.include?(path)
209
209
  lib = library
210
210
  break
@@ -267,7 +267,7 @@ class Brakeman::Rescanner < Brakeman::Scanner
267
267
  rendered_from_view = /^#{template_name}\.Template:(.+)/
268
268
 
269
269
  #Remove any rendered versions, or partials rendered from it
270
- tracker.templates.delete_if do |name, template|
270
+ tracker.templates.delete_if do |_name, template|
271
271
  template.file == path or template.name.to_sym == template_name.to_sym
272
272
  end
273
273
  end
@@ -275,7 +275,7 @@ class Brakeman::Rescanner < Brakeman::Scanner
275
275
  def rescan_deleted_lib path
276
276
  deleted_lib = nil
277
277
 
278
- tracker.libs.delete_if do |name, lib|
278
+ tracker.libs.delete_if do |_name, lib|
279
279
  if lib.files.include?(path)
280
280
  deleted_lib = lib
281
281
  true
@@ -295,7 +295,7 @@ class Brakeman::Rescanner < Brakeman::Scanner
295
295
  deleted = false
296
296
 
297
297
  [:controllers, :models, :libs].each do |collection|
298
- tracker.send(collection).delete_if do |name, data|
298
+ tracker.send(collection).delete_if do |_name, data|
299
299
  if data.files.include?(path)
300
300
  deleted = true
301
301
  true
@@ -303,7 +303,7 @@ class Brakeman::Rescanner < Brakeman::Scanner
303
303
  end
304
304
  end
305
305
 
306
- tracker.templates.delete_if do |name, data|
306
+ tracker.templates.delete_if do |_name, data|
307
307
  if data.file == path
308
308
  deleted = true
309
309
  true
@@ -340,14 +340,14 @@ class Brakeman::Rescanner < Brakeman::Scanner
340
340
  def rescan_mixin lib
341
341
  method_names = []
342
342
 
343
- lib.each_method do |name, meth|
343
+ lib.each_method do |name, _meth|
344
344
  method_names << name
345
345
  end
346
346
 
347
347
  to_rescan = []
348
348
 
349
349
  #Rescan controllers that mixed in library
350
- tracker.controllers.each do |name, controller|
350
+ tracker.controllers.each do |_name, controller|
351
351
  if controller.includes.include? lib.name
352
352
  controller.files.each do |path|
353
353
  unless @paths.include? path
@@ -219,7 +219,7 @@ class Brakeman::Tracker
219
219
  finder.process_source definition, :class => set_name, :file => file
220
220
  end
221
221
 
222
- self.each_template do |name, template|
222
+ self.each_template do |_name, template|
223
223
  finder.process_source template.src, :template => template, :file => template.file
224
224
  end
225
225
 
@@ -270,7 +270,7 @@ class Brakeman::Tracker
270
270
  end
271
271
 
272
272
  if locations.include? :templates
273
- self.each_template do |name, template|
273
+ self.each_template do |_name, template|
274
274
  finder.process_source template.src, :template => template, :file => template.file
275
275
  end
276
276
  end
@@ -283,7 +283,7 @@ class Brakeman::Tracker
283
283
  #controllers (but not those rendered from other templates)
284
284
  def reset_templates options = { :only_rendered => false }
285
285
  if options[:only_rendered]
286
- @templates.delete_if do |name, template|
286
+ @templates.delete_if do |_name, template|
287
287
  template.rendered_from_controller?
288
288
  end
289
289
  else
@@ -53,7 +53,7 @@ module Brakeman
53
53
  end
54
54
 
55
55
  def each_method
56
- @methods.each do |vis, meths|
56
+ @methods.each do |_vis, meths|
57
57
  meths.each do |name, info|
58
58
  yield name, info
59
59
  end
@@ -18,10 +18,14 @@ module Brakeman::Util
18
18
 
19
19
  COOKIES = Sexp.new(:call, nil, :cookies)
20
20
 
21
+ REQUEST_COOKIES = s(:call, s(:call, nil, :request), :cookies)
22
+
21
23
  SESSION = Sexp.new(:call, nil, :session)
22
24
 
23
25
  ALL_PARAMETERS = Set[PARAMETERS, QUERY_PARAMETERS, PATH_PARAMETERS, REQUEST_PARAMETERS, REQUEST_PARAMS]
24
26
 
27
+ ALL_COOKIES = Set[COOKIES, REQUEST_COOKIES]
28
+
25
29
  #Convert a string from "something_like_this" to "SomethingLikeThis"
26
30
  #
27
31
  #Taken from ActiveSupport.
@@ -229,7 +233,7 @@ module Brakeman::Util
229
233
 
230
234
  def cookies? exp
231
235
  if exp.is_a? Sexp
232
- return true if exp.node_type == :cookies or exp == COOKIES
236
+ return true if exp.node_type == :cookies or ALL_COOKIES.include? exp
233
237
 
234
238
  if call? exp
235
239
  if cookies? exp[1]
@@ -1,3 +1,3 @@
1
1
  module Brakeman
2
- Version = "3.7.2"
2
+ Version = "4.0.0"
3
3
  end
@@ -10,27 +10,39 @@ class Brakeman::Warning
10
10
 
11
11
  attr_accessor :code, :context, :file, :message, :relative_path
12
12
 
13
- TEXT_CONFIDENCE = [ "High", "Medium", "Weak" ]
14
-
15
- OPTIONS = {:called_from => :@called_from,
16
- :check => :@check,
17
- :class => :@class,
18
- :code => :@code,
19
- :confidence => :@confidence,
20
- :controller => :@controller,
21
- :file => :@file,
22
- :gem_info => :@gem_info,
23
- :line => :@line,
24
- :link_path => :@link_path,
25
- :message => :@message,
26
- :method => :@method,
27
- :model => :@model,
28
- :relative_path => :@relative_path,
29
- :template => :@template,
30
- :user_input => :@user_input,
31
- :warning_set => :@warning_set,
32
- :warning_type => :@warning_type
33
- }
13
+ TEXT_CONFIDENCE = {
14
+ 0 => "High",
15
+ 1 => "Medium",
16
+ 2 => "Weak",
17
+ }
18
+
19
+ CONFIDENCE = {
20
+ :high => 0,
21
+ :med => 1,
22
+ :medium => 1,
23
+ :low => 2,
24
+ :weak => 2,
25
+ }
26
+
27
+ OPTIONS = {
28
+ :called_from => :@called_from,
29
+ :check => :@check,
30
+ :class => :@class,
31
+ :code => :@code,
32
+ :controller => :@controller,
33
+ :file => :@file,
34
+ :gem_info => :@gem_info,
35
+ :line => :@line,
36
+ :link_path => :@link_path,
37
+ :message => :@message,
38
+ :method => :@method,
39
+ :model => :@model,
40
+ :relative_path => :@relative_path,
41
+ :template => :@template,
42
+ :user_input => :@user_input,
43
+ :warning_set => :@warning_set,
44
+ :warning_type => :@warning_type,
45
+ }
34
46
 
35
47
  #+options[:result]+ can be a result from Tracker#find_call. Otherwise, it can be +nil+.
36
48
  def initialize options = {}
@@ -40,6 +52,8 @@ class Brakeman::Warning
40
52
  self.instance_variable_set(var, options[key])
41
53
  end
42
54
 
55
+ self.confidence = options[:confidence]
56
+
43
57
  result = options[:result]
44
58
  if result
45
59
  @code ||= result[:call]
@@ -113,6 +127,20 @@ class Brakeman::Warning
113
127
  self.hash == other_warning.hash
114
128
  end
115
129
 
130
+ def confidence= conf
131
+ @confidence = case conf
132
+ when Integer
133
+ conf
134
+ when Symbol
135
+ CONFIDENCE[conf]
136
+ else
137
+ raise "Could not set confidence to `#{conf}`"
138
+ end
139
+
140
+ raise "Could not set confidence to `#{conf}`" unless @confidence
141
+ raise "Invalid confidence: `#{@confidence}`" unless TEXT_CONFIDENCE[@confidence]
142
+ end
143
+
116
144
  #Returns name of a view, including where it was rendered from
117
145
  def view_name(include_renderer = true)
118
146
  if called_from and include_renderer
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: brakeman-min
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.7.2
4
+ version: 4.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Collins
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain:
11
11
  - brakeman-public_cert.pem
12
- date: 2017-08-16 00:00:00.000000000 Z
12
+ date: 2017-09-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: minitest