brakeman 7.1.2 → 8.0.0

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.
Files changed (130) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGES.md +11 -0
  3. data/README.md +1 -1
  4. data/bundle/load.rb +2 -2
  5. data/bundle/ruby/3.2.0/gems/erubi-1.13.1/CHANGELOG +111 -0
  6. data/bundle/ruby/3.2.0/gems/{erubis-2.7.0 → erubi-1.13.1}/MIT-LICENSE +1 -0
  7. data/bundle/ruby/3.2.0/gems/erubi-1.13.1/README.rdoc +151 -0
  8. data/bundle/ruby/3.2.0/gems/erubi-1.13.1/lib/erubi/capture_block.rb +91 -0
  9. data/bundle/ruby/3.2.0/gems/erubi-1.13.1/lib/erubi/capture_end.rb +58 -0
  10. data/bundle/ruby/3.2.0/gems/erubi-1.13.1/lib/erubi.rb +299 -0
  11. data/bundle/ruby/3.2.0/gems/{tilt-2.6.1 → tilt-2.7.0}/lib/tilt/asciidoc.rb +12 -5
  12. data/bundle/ruby/3.2.0/gems/{tilt-2.6.1 → tilt-2.7.0}/lib/tilt/babel.rb +5 -0
  13. data/bundle/ruby/3.2.0/gems/{tilt-2.6.1 → tilt-2.7.0}/lib/tilt/builder.rb +4 -0
  14. data/bundle/ruby/3.2.0/gems/{tilt-2.6.1 → tilt-2.7.0}/lib/tilt/coffee.rb +14 -4
  15. data/bundle/ruby/3.2.0/gems/{tilt-2.6.1 → tilt-2.7.0}/lib/tilt/commonmarker.rb +41 -0
  16. data/bundle/ruby/3.2.0/gems/tilt-2.7.0/lib/tilt/csv.rb +63 -0
  17. data/bundle/ruby/3.2.0/gems/tilt-2.7.0/lib/tilt/erb.rb +130 -0
  18. data/bundle/ruby/3.2.0/gems/{tilt-2.6.1 → tilt-2.7.0}/lib/tilt/erubi.rb +41 -8
  19. data/bundle/ruby/3.2.0/gems/{tilt-2.6.1 → tilt-2.7.0}/lib/tilt/etanni.rb +7 -0
  20. data/bundle/ruby/3.2.0/gems/{tilt-2.6.1 → tilt-2.7.0}/lib/tilt/haml.rb +67 -1
  21. data/bundle/ruby/3.2.0/gems/tilt-2.7.0/lib/tilt/kramdown.rb +59 -0
  22. data/bundle/ruby/3.2.0/gems/tilt-2.7.0/lib/tilt/liquid.rb +93 -0
  23. data/bundle/ruby/3.2.0/gems/{tilt-2.6.1 → tilt-2.7.0}/lib/tilt/livescript.rb +11 -4
  24. data/bundle/ruby/3.2.0/gems/{tilt-2.6.1 → tilt-2.7.0}/lib/tilt/mapping.rb +8 -8
  25. data/bundle/ruby/3.2.0/gems/{tilt-2.6.1 → tilt-2.7.0}/lib/tilt/markaby.rb +11 -2
  26. data/bundle/ruby/3.2.0/gems/{tilt-2.6.1 → tilt-2.7.0}/lib/tilt/nokogiri.rb +13 -2
  27. data/bundle/ruby/3.2.0/gems/tilt-2.7.0/lib/tilt/pandoc.rb +81 -0
  28. data/bundle/ruby/3.2.0/gems/{tilt-2.6.1 → tilt-2.7.0}/lib/tilt/pipeline.rb +6 -1
  29. data/bundle/ruby/3.2.0/gems/{tilt-2.6.1 → tilt-2.7.0}/lib/tilt/plain.rb +5 -1
  30. data/bundle/ruby/3.2.0/gems/{tilt-2.6.1 → tilt-2.7.0}/lib/tilt/prawn.rb +17 -6
  31. data/bundle/ruby/3.2.0/gems/tilt-2.7.0/lib/tilt/radius.rb +96 -0
  32. data/bundle/ruby/3.2.0/gems/tilt-2.7.0/lib/tilt/rdiscount.rb +82 -0
  33. data/bundle/ruby/3.2.0/gems/tilt-2.7.0/lib/tilt/rdoc.rb +33 -0
  34. data/bundle/ruby/3.2.0/gems/tilt-2.7.0/lib/tilt/redcarpet.rb +73 -0
  35. data/bundle/ruby/3.2.0/gems/tilt-2.7.0/lib/tilt/redcloth.rb +40 -0
  36. data/bundle/ruby/3.2.0/gems/tilt-2.7.0/lib/tilt/rst-pandoc.rb +33 -0
  37. data/bundle/ruby/3.2.0/gems/{tilt-2.6.1 → tilt-2.7.0}/lib/tilt/sass.rb +16 -3
  38. data/bundle/ruby/3.2.0/gems/tilt-2.7.0/lib/tilt/slim.rb +18 -0
  39. data/bundle/ruby/3.2.0/gems/{tilt-2.6.1 → tilt-2.7.0}/lib/tilt/string.rb +10 -2
  40. data/bundle/ruby/3.2.0/gems/{tilt-2.6.1 → tilt-2.7.0}/lib/tilt/template.rb +5 -5
  41. data/bundle/ruby/3.2.0/gems/{tilt-2.6.1 → tilt-2.7.0}/lib/tilt/typescript.rb +5 -0
  42. data/bundle/ruby/3.2.0/gems/tilt-2.7.0/lib/tilt/yajl.rb +91 -0
  43. data/bundle/ruby/3.2.0/gems/{tilt-2.6.1 → tilt-2.7.0}/lib/tilt.rb +1 -2
  44. data/lib/brakeman/app_tree.rb +7 -2
  45. data/lib/brakeman/checks/check_model_attributes.rb +1 -1
  46. data/lib/brakeman/checks/check_render.rb +1 -27
  47. data/lib/brakeman/checks/check_render_rce.rb +43 -0
  48. data/lib/brakeman/checks/check_session_settings.rb +1 -1
  49. data/lib/brakeman/checks.rb +31 -25
  50. data/lib/brakeman/commandline.rb +6 -1
  51. data/lib/brakeman/file_parser.rb +3 -2
  52. data/lib/brakeman/logger.rb +264 -0
  53. data/lib/brakeman/options.rb +0 -9
  54. data/lib/brakeman/parsers/rails_erubi.rb +82 -0
  55. data/lib/brakeman/parsers/template_parser.rb +7 -15
  56. data/lib/brakeman/processor.rb +2 -2
  57. data/lib/brakeman/processors/controller_alias_processor.rb +1 -1
  58. data/lib/brakeman/processors/controller_processor.rb +3 -3
  59. data/lib/brakeman/processors/{erubis_template_processor.rb → erubi_template_procesor.rb} +3 -3
  60. data/lib/brakeman/processors/lib/rails2_config_processor.rb +4 -3
  61. data/lib/brakeman/processors/lib/rails2_route_processor.rb +1 -1
  62. data/lib/brakeman/processors/lib/render_helper.rb +1 -1
  63. data/lib/brakeman/processors/lib/render_path.rb +1 -1
  64. data/lib/brakeman/processors/model_processor.rb +1 -1
  65. data/lib/brakeman/report/ignore/config.rb +1 -1
  66. data/lib/brakeman/scanner.rb +25 -49
  67. data/lib/brakeman/tracker/collection.rb +12 -2
  68. data/lib/brakeman/tracker/config.rb +17 -13
  69. data/lib/brakeman/tracker/constants.rb +17 -2
  70. data/lib/brakeman/tracker/controller.rb +1 -1
  71. data/lib/brakeman/tracker.rb +7 -15
  72. data/lib/brakeman/version.rb +1 -1
  73. data/lib/brakeman.rb +89 -49
  74. metadata +51 -80
  75. data/bundle/ruby/3.2.0/gems/erubis-2.7.0/CHANGES.txt +0 -828
  76. data/bundle/ruby/3.2.0/gems/erubis-2.7.0/README.txt +0 -102
  77. data/bundle/ruby/3.2.0/gems/erubis-2.7.0/contrib/erubis +0 -3468
  78. data/bundle/ruby/3.2.0/gems/erubis-2.7.0/contrib/erubis-run.rb +0 -132
  79. data/bundle/ruby/3.2.0/gems/erubis-2.7.0/contrib/inline-require +0 -179
  80. data/bundle/ruby/3.2.0/gems/erubis-2.7.0/lib/erubis/context.rb +0 -83
  81. data/bundle/ruby/3.2.0/gems/erubis-2.7.0/lib/erubis/converter.rb +0 -357
  82. data/bundle/ruby/3.2.0/gems/erubis-2.7.0/lib/erubis/engine/ec.rb +0 -117
  83. data/bundle/ruby/3.2.0/gems/erubis-2.7.0/lib/erubis/engine/ecpp.rb +0 -113
  84. data/bundle/ruby/3.2.0/gems/erubis-2.7.0/lib/erubis/engine/ejava.rb +0 -110
  85. data/bundle/ruby/3.2.0/gems/erubis-2.7.0/lib/erubis/engine/ejavascript.rb +0 -119
  86. data/bundle/ruby/3.2.0/gems/erubis-2.7.0/lib/erubis/engine/enhanced.rb +0 -126
  87. data/bundle/ruby/3.2.0/gems/erubis-2.7.0/lib/erubis/engine/eperl.rb +0 -95
  88. data/bundle/ruby/3.2.0/gems/erubis-2.7.0/lib/erubis/engine/ephp.rb +0 -99
  89. data/bundle/ruby/3.2.0/gems/erubis-2.7.0/lib/erubis/engine/eruby.rb +0 -125
  90. data/bundle/ruby/3.2.0/gems/erubis-2.7.0/lib/erubis/engine/escheme.rb +0 -114
  91. data/bundle/ruby/3.2.0/gems/erubis-2.7.0/lib/erubis/engine/optimized.rb +0 -127
  92. data/bundle/ruby/3.2.0/gems/erubis-2.7.0/lib/erubis/engine.rb +0 -120
  93. data/bundle/ruby/3.2.0/gems/erubis-2.7.0/lib/erubis/enhancer.rb +0 -723
  94. data/bundle/ruby/3.2.0/gems/erubis-2.7.0/lib/erubis/error.rb +0 -23
  95. data/bundle/ruby/3.2.0/gems/erubis-2.7.0/lib/erubis/evaluator.rb +0 -88
  96. data/bundle/ruby/3.2.0/gems/erubis-2.7.0/lib/erubis/generator.rb +0 -85
  97. data/bundle/ruby/3.2.0/gems/erubis-2.7.0/lib/erubis/helper.rb +0 -47
  98. data/bundle/ruby/3.2.0/gems/erubis-2.7.0/lib/erubis/helpers/rails_form_helper.rb +0 -197
  99. data/bundle/ruby/3.2.0/gems/erubis-2.7.0/lib/erubis/helpers/rails_helper.rb +0 -353
  100. data/bundle/ruby/3.2.0/gems/erubis-2.7.0/lib/erubis/local-setting.rb +0 -9
  101. data/bundle/ruby/3.2.0/gems/erubis-2.7.0/lib/erubis/main.rb +0 -516
  102. data/bundle/ruby/3.2.0/gems/erubis-2.7.0/lib/erubis/preprocessing.rb +0 -58
  103. data/bundle/ruby/3.2.0/gems/erubis-2.7.0/lib/erubis/tiny.rb +0 -144
  104. data/bundle/ruby/3.2.0/gems/erubis-2.7.0/lib/erubis/util.rb +0 -22
  105. data/bundle/ruby/3.2.0/gems/erubis-2.7.0/lib/erubis.rb +0 -73
  106. data/bundle/ruby/3.2.0/gems/erubis-2.7.0/setup.rb +0 -1331
  107. data/bundle/ruby/3.2.0/gems/tilt-2.6.1/lib/tilt/creole.rb +0 -16
  108. data/bundle/ruby/3.2.0/gems/tilt-2.6.1/lib/tilt/csv.rb +0 -53
  109. data/bundle/ruby/3.2.0/gems/tilt-2.6.1/lib/tilt/erb.rb +0 -65
  110. data/bundle/ruby/3.2.0/gems/tilt-2.6.1/lib/tilt/kramdown.rb +0 -13
  111. data/bundle/ruby/3.2.0/gems/tilt-2.6.1/lib/tilt/liquid.rb +0 -37
  112. data/bundle/ruby/3.2.0/gems/tilt-2.6.1/lib/tilt/pandoc.rb +0 -39
  113. data/bundle/ruby/3.2.0/gems/tilt-2.6.1/lib/tilt/radius.rb +0 -41
  114. data/bundle/ruby/3.2.0/gems/tilt-2.6.1/lib/tilt/rdiscount.rb +0 -23
  115. data/bundle/ruby/3.2.0/gems/tilt-2.6.1/lib/tilt/rdoc.rb +0 -11
  116. data/bundle/ruby/3.2.0/gems/tilt-2.6.1/lib/tilt/redcarpet.rb +0 -31
  117. data/bundle/ruby/3.2.0/gems/tilt-2.6.1/lib/tilt/redcloth.rb +0 -13
  118. data/bundle/ruby/3.2.0/gems/tilt-2.6.1/lib/tilt/rst-pandoc.rb +0 -10
  119. data/bundle/ruby/3.2.0/gems/tilt-2.6.1/lib/tilt/slim.rb +0 -5
  120. data/bundle/ruby/3.2.0/gems/tilt-2.6.1/lib/tilt/yajl.rb +0 -81
  121. data/lib/brakeman/parsers/erubis_patch.rb +0 -11
  122. data/lib/brakeman/parsers/rails2_erubis.rb +0 -9
  123. data/lib/brakeman/parsers/rails2_xss_plugin_erubis.rb +0 -52
  124. data/lib/brakeman/parsers/rails3_erubis.rb +0 -85
  125. /data/bundle/ruby/3.2.0/gems/{tilt-2.6.1 → tilt-2.7.0}/COPYING +0 -0
  126. /data/bundle/ruby/3.2.0/gems/{tilt-2.6.1 → tilt-2.7.0}/lib/tilt/_emacs_org.rb +0 -0
  127. /data/bundle/ruby/3.2.0/gems/{tilt-2.6.1 → tilt-2.7.0}/lib/tilt/_handlebars.rb +0 -0
  128. /data/bundle/ruby/3.2.0/gems/{tilt-2.6.1 → tilt-2.7.0}/lib/tilt/_jbuilder.rb +0 -0
  129. /data/bundle/ruby/3.2.0/gems/{tilt-2.6.1 → tilt-2.7.0}/lib/tilt/_org.rb +0 -0
  130. /data/bundle/ruby/3.2.0/gems/{tilt-2.6.1 → tilt-2.7.0}/lib/tilt/cli.rb +0 -0
@@ -0,0 +1,264 @@
1
+ module Brakeman
2
+ module Logger
3
+ def self.get_logger options, dest = $stderr
4
+ case
5
+ when options[:debug]
6
+ Debug.new(options, dest)
7
+ when options[:quiet]
8
+ Quiet.new(options, dest)
9
+ when options[:report_progress] == false
10
+ Plain.new(options, dest)
11
+ when dest.tty?
12
+ Console.new(options, dest)
13
+ else
14
+ Plain.new(options, dest)
15
+ end
16
+ end
17
+
18
+ class Base
19
+ def initialize(options, log_destination = $stderr)
20
+ @dest = log_destination
21
+ @show_timing = options[:debug] || options[:show_timing]
22
+ end
23
+
24
+ # Output a message to the log.
25
+ # If newline is `false`, does not output a newline after message.
26
+ def log(message, newline: true)
27
+ if newline
28
+ @dest.puts message
29
+ else
30
+ @dest.write message
31
+ end
32
+ end
33
+
34
+ # Notify about important information - use sparingly
35
+ def announce(message); end
36
+
37
+ # Notify regarding errors - use sparingly
38
+ def alert(message); end
39
+
40
+ # Output debug information
41
+ def debug(message); end
42
+
43
+ # Wraps a step in the scanning process
44
+ def context(description, &)
45
+ yield self
46
+ end
47
+
48
+ # Wraps a substep (e.g. processing one file)
49
+ def single_context(description, &)
50
+ yield
51
+ end
52
+
53
+ # Update progress towards a known total
54
+ def update_progress(current, total, type = 'files'); end
55
+
56
+ # Show a spinner
57
+ def spin; end
58
+
59
+ # Called on exit
60
+ def cleanup(newline); end
61
+
62
+ def show_timing? = @show_timing
63
+
64
+ # Use ANSI codes to color a string
65
+ def color(message, *)
66
+ if @highline
67
+ @highline.color(message, *)
68
+ else
69
+ message
70
+ end
71
+ end
72
+
73
+ def color?
74
+ @highline and @highline.use_color?
75
+ end
76
+
77
+ private
78
+
79
+ def load_highline(output_color)
80
+ if @dest.tty? or output_color == :force
81
+ Brakeman.load_brakeman_dependency 'highline'
82
+ @highline = HighLine.new
83
+ @highline.use_color = !!output_color
84
+ else
85
+ @highline = nil
86
+ end
87
+ end
88
+ end
89
+
90
+ class Plain < Base
91
+ def initialize(options, *)
92
+ super
93
+
94
+ load_highline(options[:output_color])
95
+ end
96
+
97
+ def announce(message)
98
+ log color(message, :bold, :green)
99
+ end
100
+
101
+ def alert(message)
102
+ log color(message, :red)
103
+ end
104
+
105
+ def context(description, &)
106
+ log "#{color(description, :green)}..."
107
+
108
+ if show_timing?
109
+ time_step(description, &)
110
+ else
111
+ yield
112
+ end
113
+ end
114
+
115
+ def time_step(description, &)
116
+ start_t = Time.now
117
+ yield
118
+ duration = Time.now - start_t
119
+
120
+ log color(("Completed #{description.to_s.downcase} in %0.2fs" % duration), :gray)
121
+ end
122
+ end
123
+
124
+ class Quiet < Base
125
+ def initialize(*)
126
+ super
127
+ end
128
+ end
129
+
130
+ class Debug < Plain
131
+ def debug(message)
132
+ log color(message, :gray)
133
+ end
134
+
135
+ def context(description, &)
136
+ log "#{description}..."
137
+
138
+ time_step(description, &)
139
+ end
140
+
141
+ def single_context(description, &)
142
+ debug "Processing #{description}"
143
+
144
+ if show_timing?
145
+ # Even in debug, only show timing for each file if asked
146
+ time_step(description, &)
147
+ else
148
+ yield
149
+ end
150
+ end
151
+ end
152
+
153
+ class Console < Base
154
+ attr_reader :prefix
155
+
156
+ def initialize(options, *)
157
+ super
158
+
159
+ load_highline(options[:output_color])
160
+ require 'reline'
161
+ require 'reline/io/ansi'
162
+
163
+ @prefix = ''
164
+ @post_fix_pos = 0
165
+ @reline = Reline::ANSI.new
166
+ @report_progress = options[:report_progress]
167
+ @spinner = ["⣀", "⣄", "⣤", "⣦", "⣶", "⣷", "⣿"]
168
+ @percenter = ["⣀", "⣤", "⣶", "⣿"]
169
+ @spindex = 0
170
+ @last_spin = Time.now
171
+ @reline.hide_cursor
172
+ end
173
+
174
+ def announce message
175
+ clear_line
176
+ log color(message, :bold, :green)
177
+ rewrite_prefix
178
+ end
179
+
180
+ def alert message
181
+ clear_line
182
+ log color(message, :red)
183
+ rewrite_prefix
184
+ end
185
+
186
+ def context(description, &)
187
+ write_prefix description
188
+
189
+ time_step(description, &)
190
+ ensure
191
+ clear_prefix
192
+ end
193
+
194
+ def time_step(description, &)
195
+ if show_timing?
196
+ start_t = Time.now
197
+ yield
198
+ duration = Time.now - start_t
199
+
200
+ write_after color(('%0.2fs' % duration), :gray)
201
+ log ''
202
+ else
203
+ yield
204
+ end
205
+ end
206
+
207
+ def update_progress current, total, type = 'files'
208
+ percent = ((current / total.to_f) * 100).to_i
209
+ tenths = [(percent / 10), 0].max
210
+
211
+ lead = color(@percenter[percent % 10 / 3], :bold, :red)
212
+ done_blocks = color("⣿" * tenths, :red)
213
+ remaining = color("⣀" * (9 - tenths), :gray)
214
+ write_after "#{done_blocks}#{lead}#{remaining}"
215
+ end
216
+
217
+ def write_prefix pref
218
+ set_prefix pref
219
+ rewrite_prefix
220
+ end
221
+
222
+ # If an alert was written, redo prefix on next line
223
+ def rewrite_prefix
224
+ log(@prefix, newline: false)
225
+ @reline.erase_after_cursor
226
+ end
227
+
228
+ def write_after message
229
+ @reline.move_cursor_column(@post_fix_pos)
230
+ log(message, newline: false)
231
+ @reline.erase_after_cursor
232
+ end
233
+
234
+ def set_prefix message
235
+ @prefix = "#{color('»', :bold, :cyan)} #{color(message, :green)}"
236
+ @post_fix_pos = HighLine::Wrapper.actual_length(@prefix) + 1
237
+ end
238
+
239
+ def clear_prefix
240
+ @prefix = ''
241
+ @post_fix_pos = 0
242
+ clear_line
243
+ end
244
+
245
+ def clear_line
246
+ @reline.move_cursor_column(0)
247
+ @reline.erase_after_cursor
248
+ end
249
+
250
+ def spin
251
+ return unless (Time.now - @last_spin) > 0.2
252
+
253
+ write_after color(@spinner[@spindex], :bold, :red)
254
+ @spindex = (@spindex + 1) % @spinner.length
255
+ @last_spin = Time.now
256
+ end
257
+
258
+ def cleanup(newline = true)
259
+ @reline.show_cursor
260
+ log('') if newline
261
+ end
262
+ end
263
+ end
264
+ end
@@ -131,7 +131,6 @@ module Brakeman::Options
131
131
 
132
132
  opts.on "--faster", "Faster, but less accurate scan" do
133
133
  options[:ignore_ifs] = true
134
- options[:skip_libs] = true
135
134
  options[:disable_constant_tracking] = true
136
135
  end
137
136
 
@@ -143,10 +142,6 @@ module Brakeman::Options
143
142
  options[:ignore_attr_protected] = true
144
143
  end
145
144
 
146
- opts.on "--[no-]index-libs", "Add libraries to call index (Default)" do |index|
147
- options[:index_libs] = index
148
- end
149
-
150
145
  opts.on "--interprocedural", "Process method calls to known methods" do
151
146
  options[:interprocedural] = true
152
147
  end
@@ -212,10 +207,6 @@ module Brakeman::Options
212
207
  options[:skip_vendor] = skip
213
208
  end
214
209
 
215
- opts.on "--skip-libs", "Skip processing lib directory" do
216
- options[:skip_libs] = true
217
- end
218
-
219
210
  opts.on "--add-libs-path path1,path2,etc", Array, "An application relative lib directory (ex. app/mailers) to process" do |paths|
220
211
  options[:additional_libs_path] ||= Set.new
221
212
  options[:additional_libs_path].merge paths
@@ -0,0 +1,82 @@
1
+ # frozen_string_literal: true
2
+ # Copied almost verbatim from Rails
3
+ # https://github.com/rails/rails/blob/5359cf8a5b093b04170e884ee8da5a1e076b8a0d/actionview/lib/action_view/template/handlers/erb/erubi.rb#L9
4
+
5
+ Brakeman.load_brakeman_dependency "erubi"
6
+
7
+ module Brakeman
8
+ class Erubi < ::Erubi::Engine
9
+ # :nodoc: all
10
+ def initialize(input, properties = {})
11
+ @newline_pending = 0
12
+
13
+ # Dup properties so that we don't modify argument
14
+ properties = Hash[properties]
15
+
16
+ properties[:bufvar] ||= "@output_buffer"
17
+ properties[:preamble] ||= ""
18
+ properties[:postamble] ||= "#{properties[:bufvar]}"
19
+
20
+ # Tell Erubi whether the template will be compiled with `frozen_string_literal: true`
21
+ # properties[:freeze_template_literals] = !Template.frozen_string_literal
22
+ properties[:freeze_template_literals] = false
23
+
24
+ properties[:escapefunc] = ""
25
+
26
+ super
27
+ end
28
+
29
+ private
30
+ def add_text(text)
31
+ return if text.empty?
32
+
33
+ if text == "\n"
34
+ @newline_pending += 1
35
+ else
36
+ with_buffer do
37
+ src << ".safe_append='"
38
+ src << "\n" * @newline_pending if @newline_pending > 0
39
+ src << text.gsub(/['\\]/, '\\\\\&') << @text_end
40
+ end
41
+ @newline_pending = 0
42
+ end
43
+ end
44
+
45
+ BLOCK_EXPR = /((\s|\))do|\{)(\s*\|[^|]*\|)?\s*\Z/
46
+
47
+ def add_expression(indicator, code)
48
+ flush_newline_if_pending(src)
49
+
50
+ with_buffer do
51
+ if (indicator == "==") || @escape
52
+ src << ".safe_expr_append="
53
+ else
54
+ src << ".append="
55
+ end
56
+
57
+ if BLOCK_EXPR.match?(code)
58
+ src << " " << code
59
+ else
60
+ src << "(" << code << ")"
61
+ end
62
+ end
63
+ end
64
+
65
+ def add_code(code)
66
+ flush_newline_if_pending(src)
67
+ super
68
+ end
69
+
70
+ def add_postamble(_)
71
+ flush_newline_if_pending(src)
72
+ super
73
+ end
74
+
75
+ def flush_newline_if_pending(src)
76
+ if @newline_pending > 0
77
+ with_buffer { src << ".safe_append='#{"\n" * @newline_pending}" << @text_end }
78
+ @newline_pending = 0
79
+ end
80
+ end
81
+ end
82
+ end
@@ -21,7 +21,7 @@ module Brakeman
21
21
  begin
22
22
  src = case type
23
23
  when :erb
24
- type = :erubis if erubis?
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 tracker.config.escape_html?
50
- if tracker.options[:rails3]
51
- require 'brakeman/parsers/rails3_erubis'
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 erubis?
64
+ def erubi?
73
65
  tracker.config.escape_html? or
74
- tracker.config.erubis?
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.erubis? ? :erubis : :erb
143
+ type = tp.erubi? ? :erubi : :erb
152
144
 
153
145
  return type, fp.parse_ruby(src, "_inline_")
154
146
  end
@@ -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 :erubis
69
- result = ErubisTemplateProcessor.new(@tracker, name, called_from, file_name).process src
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 "[Notice] Could not find filter #{name}"
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 "[Notice] Treating inner class as library: #{name}"
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 "[Notice] Adding noncontroller as library: #{name}"
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 "[Notice] Layout not found: #{name}"
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 Erubis instead of erb.
4
- class Brakeman::ErubisTemplateProcessor < Brakeman::TemplateProcessor
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 Erubis
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.notify "[Notice] Using Erubis for ERB templates"
43
- @tracker.config.erubis = true
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.notify "[Notice] Unhandled resource option, please report: #{option}"
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 "[Notice] No such template: #{name}"
101
+ Brakeman.debug "No such template: #{name}"
102
102
  return
103
103
  end
104
104
 
@@ -36,7 +36,7 @@ module Brakeman
36
36
  file: template.file,
37
37
  }
38
38
  else
39
- Brakeman.debug "[Notice] No render path to add template information"
39
+ Brakeman.debug "No render path to add template information"
40
40
  end
41
41
  end
42
42
 
@@ -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 "[Notice] Treating inner class as library: #{name}"
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.notify "[Notice] Could not find ignore configuration in #{file}"
110
+ Brakeman.alert "Could not find ignore configuration in #{file} (no file)"
111
111
  @already_ignored = []
112
112
  end
113
113