brakeman 3.3.1 → 3.3.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (26) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGES +4 -0
  3. data/bundle/load.rb +1 -1
  4. data/bundle/ruby/2.3.0/gems/{terminal-table-1.5.2 → terminal-table-1.6.0}/Gemfile +0 -0
  5. data/bundle/ruby/2.3.0/gems/{terminal-table-1.5.2 → terminal-table-1.6.0}/History.rdoc +53 -48
  6. data/bundle/ruby/2.3.0/gems/{terminal-table-1.5.2 → terminal-table-1.6.0}/Manifest +0 -0
  7. data/bundle/ruby/2.3.0/gems/{terminal-table-1.5.2 → terminal-table-1.6.0}/README.rdoc +238 -240
  8. data/bundle/ruby/2.3.0/gems/{terminal-table-1.5.2 → terminal-table-1.6.0}/Rakefile +0 -0
  9. data/bundle/ruby/2.3.0/gems/{terminal-table-1.5.2 → terminal-table-1.6.0}/Todo.rdoc +13 -13
  10. data/bundle/ruby/2.3.0/gems/{terminal-table-1.5.2 → terminal-table-1.6.0}/examples/examples.rb +83 -83
  11. data/bundle/ruby/2.3.0/gems/{terminal-table-1.5.2 → terminal-table-1.6.0}/lib/terminal-table.rb +0 -0
  12. data/bundle/ruby/2.3.0/gems/{terminal-table-1.5.2 → terminal-table-1.6.0}/lib/terminal-table/cell.rb +16 -17
  13. data/bundle/ruby/2.3.0/gems/{terminal-table-1.5.2 → terminal-table-1.6.0}/lib/terminal-table/import.rb +0 -0
  14. data/bundle/ruby/2.3.0/gems/{terminal-table-1.5.2 → terminal-table-1.6.0}/lib/terminal-table/row.rb +0 -0
  15. data/bundle/ruby/2.3.0/gems/{terminal-table-1.5.2 → terminal-table-1.6.0}/lib/terminal-table/separator.rb +14 -14
  16. data/bundle/ruby/2.3.0/gems/{terminal-table-1.5.2 → terminal-table-1.6.0}/lib/terminal-table/style.rb +67 -62
  17. data/bundle/ruby/2.3.0/gems/{terminal-table-1.5.2 → terminal-table-1.6.0}/lib/terminal-table/table.rb +43 -40
  18. data/bundle/ruby/2.3.0/gems/{terminal-table-1.5.2 → terminal-table-1.6.0}/lib/terminal-table/table_helper.rb +9 -9
  19. data/bundle/ruby/2.3.0/gems/{terminal-table-1.5.2 → terminal-table-1.6.0}/lib/terminal-table/version.rb +1 -1
  20. data/bundle/ruby/2.3.0/gems/{terminal-table-1.5.2 → terminal-table-1.6.0}/terminal-table.gemspec +0 -0
  21. data/lib/brakeman/checks/check_secrets.rb +1 -1
  22. data/lib/brakeman/options.rb +1 -0
  23. data/lib/brakeman/tracker.rb +2 -2
  24. data/lib/brakeman/tracker/constants.rb +94 -33
  25. data/lib/brakeman/version.rb +1 -1
  26. metadata +19 -19
@@ -1,13 +1,12 @@
1
-
2
1
  module Terminal
3
2
  class Table
4
-
3
+
5
4
  attr_reader :title
6
5
  attr_reader :headings
7
-
6
+
8
7
  ##
9
8
  # Generates a ASCII table with the given _options_.
10
-
9
+
11
10
  def initialize options = {}, &block
12
11
  @column_widths = []
13
12
  self.style = options.fetch :style, {}
@@ -16,10 +15,10 @@ module Terminal
16
15
  self.title = options.fetch :title, nil
17
16
  yield_or_eval(&block) if block
18
17
  end
19
-
18
+
20
19
  ##
21
20
  # Align column _n_ to the given _alignment_ of :center, :left, or :right.
22
-
21
+
23
22
  def align_column n, alignment
24
23
  r = rows
25
24
  column(n).each_with_index do |col, i|
@@ -27,10 +26,10 @@ module Terminal
27
26
  cell.alignment = alignment unless cell.alignment?
28
27
  end
29
28
  end
30
-
29
+
31
30
  ##
32
- # Add a row.
33
-
31
+ # Add a row.
32
+
34
33
  def add_row array
35
34
  row = array == :separator ? Separator.new(self) : Row.new(self, array)
36
35
  @rows << row
@@ -44,58 +43,58 @@ module Terminal
44
43
  def add_separator
45
44
  self << :separator
46
45
  end
47
-
46
+
48
47
  def cell_spacing
49
48
  cell_padding + style.border_y.length
50
49
  end
51
-
50
+
52
51
  def cell_padding
53
52
  style.padding_left + style.padding_right
54
53
  end
55
-
54
+
56
55
  ##
57
56
  # Return column _n_.
58
-
57
+
59
58
  def column n, method = :value, array = rows
60
- array.map { |row|
59
+ array.map { |row|
61
60
  cell = row[n]
62
61
  cell && method ? cell.__send__(method) : cell
63
- }.compact
62
+ }.compact
64
63
  end
65
-
64
+
66
65
  ##
67
66
  # Return _n_ column including headings.
68
-
67
+
69
68
  def column_with_headings n, method = :value
70
69
  column n, method, headings_with_rows
71
70
  end
72
-
71
+
73
72
  ##
74
73
  # Return columns.
75
-
74
+
76
75
  def columns
77
- (0...number_of_columns).map { |n| column n }
76
+ (0...number_of_columns).map { |n| column n }
78
77
  end
79
-
78
+
80
79
  ##
81
80
  # Return length of column _n_.
82
-
81
+
83
82
  def column_width n
84
83
  width = @column_widths[n] || 0
85
84
  width + additional_column_widths[n].to_i
86
85
  end
87
86
  alias length_of_column column_width # for legacy support
88
-
87
+
89
88
  ##
90
89
  # Return total number of columns available.
91
-
90
+
92
91
  def number_of_columns
93
92
  headings_with_rows.map { |r| r.cells.size }.max
94
93
  end
95
94
 
96
95
  ##
97
96
  # Set the headings
98
-
97
+
99
98
  def headings= arrays
100
99
  arrays = [arrays] unless arrays.first.is_a?(Array)
101
100
  @headings = arrays.map do |array|
@@ -107,7 +106,7 @@ module Terminal
107
106
 
108
107
  ##
109
108
  # Render the table.
110
-
109
+
111
110
  def render
112
111
  separator = Separator.new(self)
113
112
  buffer = [separator]
@@ -121,19 +120,23 @@ module Terminal
121
120
  buffer << separator
122
121
  end
123
122
  end
124
- buffer += @rows
125
- buffer << separator
126
- buffer.map { |r| r.render }.join("\n")
123
+ if style.all_separators
124
+ buffer += @rows.product([separator]).flatten
125
+ else
126
+ buffer += @rows
127
+ buffer << separator
128
+ end
129
+ buffer.map { |r| style.margin_left + r.render }.join("\n")
127
130
  end
128
131
  alias :to_s :render
129
-
132
+
130
133
  ##
131
134
  # Return rows without separator rows.
132
135
 
133
136
  def rows
134
137
  @rows.reject { |row| row.is_a? Separator }
135
138
  end
136
-
139
+
137
140
  def rows= array
138
141
  @rows = []
139
142
  array.each { |arr| self << arr }
@@ -142,16 +145,16 @@ module Terminal
142
145
  def style=(options)
143
146
  style.apply options
144
147
  end
145
-
148
+
146
149
  def style
147
150
  @style ||= Style.new
148
151
  end
149
-
152
+
150
153
  def title=(title)
151
154
  @title = title
152
155
  recalc_column_widths Row.new(self, [title_cell_options])
153
156
  end
154
-
157
+
155
158
  ##
156
159
  # Check if _other_ is equal to self. _other_ is considered equal
157
160
  # if it contains the same headings and rows.
@@ -163,11 +166,11 @@ module Terminal
163
166
  end
164
167
 
165
168
  private
166
-
169
+
167
170
  def columns_width
168
171
  @column_widths.inject(0) { |s, i| s + i + cell_spacing } + style.border_y.length
169
172
  end
170
-
173
+
171
174
  def additional_column_widths
172
175
  return [] if style.width.nil?
173
176
  spacing = style.width - columns_width
@@ -181,7 +184,7 @@ module Terminal
181
184
  arr
182
185
  end
183
186
  end
184
-
187
+
185
188
  def recalc_column_widths row
186
189
  return if row.is_a? Separator
187
190
  i = 0
@@ -202,14 +205,14 @@ module Terminal
202
205
  end
203
206
  end
204
207
  end
205
-
208
+
206
209
  ##
207
210
  # Return headings combined with rows.
208
-
211
+
209
212
  def headings_with_rows
210
213
  @headings + rows
211
214
  end
212
-
215
+
213
216
  def yield_or_eval &block
214
217
  return unless block
215
218
  if block.arity > 0
@@ -1,9 +1,9 @@
1
- module Terminal
2
- class Table
3
- module TableHelper
4
- def table headings = [], *rows, &block
5
- Terminal::Table.new :headings => headings.to_a, :rows => rows, &block
6
- end
7
- end
8
- end
9
- end
1
+ module Terminal
2
+ class Table
3
+ module TableHelper
4
+ def table headings = [], *rows, &block
5
+ Terminal::Table.new :headings => headings.to_a, :rows => rows, &block
6
+ end
7
+ end
8
+ end
9
+ end
@@ -1,5 +1,5 @@
1
1
  module Terminal
2
2
  class Table
3
- VERSION = '1.5.2'
3
+ VERSION = '1.6.0'
4
4
  end
5
5
  end
@@ -13,7 +13,7 @@ class Brakeman::CheckSecrets < Brakeman::BaseCheck
13
13
  @warned = Set.new
14
14
 
15
15
  @tracker.constants.each do |constant|
16
- name = constant.name.last
16
+ name = constant.name_array.last
17
17
  value = constant.value
18
18
 
19
19
  if string? value and not value.value.empty? and looks_like_secret? name
@@ -76,6 +76,7 @@ module Brakeman::Options
76
76
  opts.on "--faster", "Faster, but less accurate scan" do
77
77
  options[:ignore_ifs] = true
78
78
  options[:skip_libs] = true
79
+ options[:disable_constant_tracking] = true
79
80
  end
80
81
 
81
82
  opts.on "--ignore-model-output", "Consider model attributes XSS-safe" do
@@ -186,11 +186,11 @@ class Brakeman::Tracker
186
186
  end
187
187
 
188
188
  def add_constant name, value, context = nil
189
- @constants.add name, value, context
189
+ @constants.add name, value, context unless @options[:disable_constant_tracking]
190
190
  end
191
191
 
192
192
  def constant_lookup name
193
- @constants.get_literal name
193
+ @constants.get_literal name unless @options[:disable_constant_tracking]
194
194
  end
195
195
 
196
196
  def index_call_sites
@@ -2,11 +2,11 @@ require 'brakeman/processors/output_processor'
2
2
 
3
3
  module Brakeman
4
4
  class Constant
5
- attr_reader :name, :file
5
+ attr_reader :name, :name_array, :file, :value
6
6
 
7
7
  def initialize name, value = nil, context = nil
8
8
  set_name name, context
9
- @values = [ value ]
9
+ @value = value
10
10
  @context = context
11
11
 
12
12
  if @context
@@ -15,28 +15,28 @@ module Brakeman
15
15
  end
16
16
 
17
17
  def line
18
- if @values.first.is_a? Sexp
19
- @values.first.line
18
+ if @value.is_a? Sexp
19
+ @value.line
20
20
  end
21
21
  end
22
22
 
23
23
  def set_name name, context
24
- @name = Constants.constant_as_array(name)
24
+ @name = name
25
+ @name_array = Constants.constant_as_array(name)
25
26
  end
26
27
 
27
28
  def match? name
28
- @name.reverse.zip(name.reverse).reduce(true) { |m, a| a[1] ? a[0] == a[1] && m : m }
29
- end
30
-
31
- def value
32
- @values.reverse.reduce do |m, v|
33
- Sexp.new(:or, v, m)
34
- end
35
- end
36
-
37
- def add_value exp
38
- unless @values.include? exp
39
- @values << exp
29
+ if name == @name
30
+ return true
31
+ elsif name.is_a? Sexp and name.node_type == :const and name.value == @name
32
+ return true
33
+ elsif name.is_a? Symbol and name.value == @name
34
+ return true
35
+ elsif name.class == Array
36
+ name == @name_array or
37
+ @name_array.reverse.zip(name.reverse).reduce(true) { |m, a| a[1] ? a[0] == a[1] && m : m }
38
+ else
39
+ false
40
40
  end
41
41
  end
42
42
  end
@@ -45,7 +45,11 @@ module Brakeman
45
45
  include Brakeman::Util
46
46
 
47
47
  def initialize
48
- @constants = []
48
+ @constants = Hash.new { |h, k| h[k] = [] }
49
+ end
50
+
51
+ def size
52
+ @constants.length
49
53
  end
50
54
 
51
55
  def [] exp
@@ -60,41 +64,98 @@ module Brakeman
60
64
  end
61
65
 
62
66
  def find_constant exp
63
- name = Constants.constant_as_array(exp)
64
- @constants.find do |c|
65
- c.match? name
67
+ base_name = Constants.get_constant_base_name(exp)
68
+
69
+ if @constants.key? base_name
70
+ @constants[base_name].find do |c|
71
+ if c.match? exp
72
+ return c
73
+ end
74
+ end
75
+
76
+ name_array = Constants.constant_as_array(exp)
77
+
78
+ # Avoid losing info about dynamic constant values
79
+ return unless name_array.all? { |n| constant? n or n.is_a? Symbol }
80
+
81
+ @constants[base_name].find do |c|
82
+ if c.match? name_array
83
+ return c
84
+ end
85
+ end
66
86
  end
87
+
88
+ nil
67
89
  end
68
90
 
69
91
  def add name, value, context = nil
70
- if existing = self.find_constant(name)
71
- existing.add_value value
72
- else
73
- @constants << Constant.new(name, value, context)
92
+ if call? value and value.method == :freeze
93
+ value = value.target
74
94
  end
95
+
96
+ base_name = Constants.get_constant_base_name(name)
97
+ @constants[base_name] << Constant.new(name, value, context)
98
+ end
99
+
100
+ LITERALS = [:lit, :false, :str, :true, :array, :hash]
101
+ def literal? exp
102
+ exp.is_a? Sexp and LITERALS.include? exp.node_type
75
103
  end
76
104
 
77
105
  def get_literal name
78
- if x = self[name] and [:lit, :false, :str, :true, :array, :hash].include? x.node_type
106
+ if x = self[name] and literal? x
79
107
  x
80
108
  else
81
109
  nil
82
110
  end
83
111
  end
84
112
 
85
- def each &block
86
- @constants.each &block
113
+ def each
114
+ @constants.each do |name, values|
115
+ values.each do |constant|
116
+ yield constant
117
+ end
118
+ end
87
119
  end
88
120
 
89
121
  def self.constant_as_array exp
90
- get_constant_name(exp).split('::')
122
+ res = []
123
+ while exp
124
+ if exp.is_a? Sexp
125
+ case exp.node_type
126
+ when :const
127
+ res << exp.value
128
+ exp = nil
129
+ when :colon3
130
+ res << exp.value << :""
131
+ exp = nil
132
+ when :colon2
133
+ res << exp.last
134
+ exp = exp[1]
135
+ else
136
+ res << exp
137
+ exp = nil
138
+ end
139
+ else
140
+ res << exp
141
+ exp = nil
142
+ end
143
+ end
144
+
145
+ res.reverse!
146
+ res
91
147
  end
92
148
 
93
- def self.get_constant_name exp
94
- if exp.is_a? Sexp
95
- Brakeman::OutputProcessor.new.format(exp)
149
+ def self.get_constant_base_name exp
150
+ return exp unless exp.is_a? Sexp
151
+
152
+ case exp.node_type
153
+ when :const, :colon3
154
+ exp.value
155
+ when :colon2
156
+ exp.last
96
157
  else
97
- exp.to_s
158
+ exp
98
159
  end
99
160
  end
100
161
  end