brakeman 4.5.0 → 4.5.1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of brakeman might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/CHANGES.md +15 -0
- data/README.md +6 -6
- data/bundle/load.rb +3 -3
- data/bundle/ruby/2.5.0/gems/{highline-1.7.10 → highline-2.0.2}/AUTHORS +0 -0
- data/bundle/ruby/2.5.0/gems/{highline-1.7.10 → highline-2.0.2}/COPYING +0 -0
- data/bundle/ruby/2.5.0/gems/{highline-1.7.10 → highline-2.0.2}/Changelog.md +211 -15
- data/bundle/ruby/2.5.0/gems/highline-2.0.2/Gemfile +22 -0
- data/bundle/ruby/2.5.0/gems/{highline-1.7.10 → highline-2.0.2}/LICENSE +0 -0
- data/bundle/ruby/2.5.0/gems/highline-2.0.2/README.md +202 -0
- data/bundle/ruby/2.5.0/gems/{highline-1.7.10 → highline-2.0.2}/TODO +0 -0
- data/bundle/ruby/2.5.0/gems/highline-2.0.2/appveyor.yml +37 -0
- data/bundle/ruby/2.5.0/gems/highline-2.0.2/highline.gemspec +35 -0
- data/bundle/ruby/2.5.0/gems/highline-2.0.2/lib/highline.rb +650 -0
- data/bundle/ruby/2.5.0/gems/highline-2.0.2/lib/highline/builtin_styles.rb +129 -0
- data/bundle/ruby/2.5.0/gems/{highline-1.7.10 → highline-2.0.2}/lib/highline/color_scheme.rb +49 -32
- data/bundle/ruby/2.5.0/gems/highline-2.0.2/lib/highline/compatibility.rb +23 -0
- data/bundle/ruby/2.5.0/gems/highline-2.0.2/lib/highline/custom_errors.rb +57 -0
- data/bundle/ruby/2.5.0/gems/highline-2.0.2/lib/highline/import.rb +48 -0
- data/bundle/ruby/2.5.0/gems/highline-2.0.2/lib/highline/io_console_compatible.rb +37 -0
- data/bundle/ruby/2.5.0/gems/highline-2.0.2/lib/highline/list.rb +177 -0
- data/bundle/ruby/2.5.0/gems/highline-2.0.2/lib/highline/list_renderer.rb +261 -0
- data/bundle/ruby/2.5.0/gems/highline-2.0.2/lib/highline/menu.rb +576 -0
- data/bundle/ruby/2.5.0/gems/highline-2.0.2/lib/highline/menu/item.rb +32 -0
- data/bundle/ruby/2.5.0/gems/highline-2.0.2/lib/highline/paginator.rb +52 -0
- data/bundle/ruby/2.5.0/gems/{highline-1.7.10 → highline-2.0.2}/lib/highline/question.rb +281 -131
- data/bundle/ruby/2.5.0/gems/highline-2.0.2/lib/highline/question/answer_converter.rb +103 -0
- data/bundle/ruby/2.5.0/gems/highline-2.0.2/lib/highline/question_asker.rb +150 -0
- data/bundle/ruby/2.5.0/gems/highline-2.0.2/lib/highline/simulate.rb +59 -0
- data/bundle/ruby/2.5.0/gems/highline-2.0.2/lib/highline/statement.rb +88 -0
- data/bundle/ruby/2.5.0/gems/highline-2.0.2/lib/highline/string.rb +36 -0
- data/bundle/ruby/2.5.0/gems/highline-2.0.2/lib/highline/string_extensions.rb +130 -0
- data/bundle/ruby/2.5.0/gems/highline-2.0.2/lib/highline/style.rb +325 -0
- data/bundle/ruby/2.5.0/gems/highline-2.0.2/lib/highline/template_renderer.rb +62 -0
- data/bundle/ruby/2.5.0/gems/highline-2.0.2/lib/highline/terminal.rb +190 -0
- data/bundle/ruby/2.5.0/gems/highline-2.0.2/lib/highline/terminal/io_console.rb +36 -0
- data/bundle/ruby/2.5.0/gems/highline-2.0.2/lib/highline/terminal/ncurses.rb +38 -0
- data/bundle/ruby/2.5.0/gems/highline-2.0.2/lib/highline/terminal/unix_stty.rb +51 -0
- data/bundle/ruby/2.5.0/gems/{highline-1.7.10 → highline-2.0.2}/lib/highline/version.rb +3 -1
- data/bundle/ruby/2.5.0/gems/highline-2.0.2/lib/highline/wrapper.rb +53 -0
- data/bundle/ruby/2.5.0/gems/{ruby_parser-3.13.0 → ruby_parser-3.13.1}/History.rdoc +32 -0
- data/bundle/ruby/2.5.0/gems/{ruby_parser-3.13.0 → ruby_parser-3.13.1}/Manifest.txt +0 -0
- data/bundle/ruby/2.5.0/gems/{ruby_parser-3.13.0 → ruby_parser-3.13.1}/README.rdoc +0 -0
- data/bundle/ruby/2.5.0/gems/{ruby_parser-3.13.0 → ruby_parser-3.13.1}/compare/normalize.rb +0 -0
- data/bundle/ruby/2.5.0/gems/{ruby_parser-3.13.0 → ruby_parser-3.13.1}/debugging.md +0 -0
- data/bundle/ruby/2.5.0/gems/{ruby_parser-3.13.0 → ruby_parser-3.13.1}/lib/rp_extensions.rb +1 -1
- data/bundle/ruby/2.5.0/gems/{ruby_parser-3.13.0 → ruby_parser-3.13.1}/lib/rp_stringscanner.rb +0 -0
- data/bundle/ruby/2.5.0/gems/{ruby_parser-3.13.0 → ruby_parser-3.13.1}/lib/ruby20_parser.rb +2427 -2432
- data/bundle/ruby/2.5.0/gems/{ruby_parser-3.13.0 → ruby_parser-3.13.1}/lib/ruby20_parser.y +32 -29
- data/bundle/ruby/2.5.0/gems/{ruby_parser-3.13.0 → ruby_parser-3.13.1}/lib/ruby21_parser.rb +2101 -2109
- data/bundle/ruby/2.5.0/gems/{ruby_parser-3.13.0 → ruby_parser-3.13.1}/lib/ruby21_parser.y +32 -29
- data/bundle/ruby/2.5.0/gems/{ruby_parser-3.13.0 → ruby_parser-3.13.1}/lib/ruby22_parser.rb +2080 -2095
- data/bundle/ruby/2.5.0/gems/{ruby_parser-3.13.0 → ruby_parser-3.13.1}/lib/ruby22_parser.y +32 -29
- data/bundle/ruby/2.5.0/gems/{ruby_parser-3.13.0/lib/ruby25_parser.rb → ruby_parser-3.13.1/lib/ruby23_parser.rb} +2339 -2333
- data/bundle/ruby/2.5.0/gems/{ruby_parser-3.13.0 → ruby_parser-3.13.1}/lib/ruby23_parser.y +32 -29
- data/bundle/ruby/2.5.0/gems/{ruby_parser-3.13.0 → ruby_parser-3.13.1}/lib/ruby24_parser.rb +2347 -2335
- data/bundle/ruby/2.5.0/gems/{ruby_parser-3.13.0 → ruby_parser-3.13.1}/lib/ruby24_parser.y +32 -23
- data/bundle/ruby/2.5.0/gems/{ruby_parser-3.13.0/lib/ruby23_parser.rb → ruby_parser-3.13.1/lib/ruby25_parser.rb} +2349 -2337
- data/bundle/ruby/2.5.0/gems/{ruby_parser-3.13.0 → ruby_parser-3.13.1}/lib/ruby25_parser.y +32 -23
- data/bundle/ruby/2.5.0/gems/{ruby_parser-3.13.0 → ruby_parser-3.13.1}/lib/ruby26_parser.rb +2351 -2338
- data/bundle/ruby/2.5.0/gems/{ruby_parser-3.13.0 → ruby_parser-3.13.1}/lib/ruby26_parser.y +32 -23
- data/bundle/ruby/2.5.0/gems/{ruby_parser-3.13.0 → ruby_parser-3.13.1}/lib/ruby_lexer.rb +253 -161
- data/bundle/ruby/2.5.0/gems/{ruby_parser-3.13.0 → ruby_parser-3.13.1}/lib/ruby_lexer.rex +25 -25
- data/bundle/ruby/2.5.0/gems/{ruby_parser-3.13.0 → ruby_parser-3.13.1}/lib/ruby_lexer.rex.rb +68 -26
- data/bundle/ruby/2.5.0/gems/{ruby_parser-3.13.0 → ruby_parser-3.13.1}/lib/ruby_parser.rb +3 -1
- data/bundle/ruby/2.5.0/gems/{ruby_parser-3.13.0 → ruby_parser-3.13.1}/lib/ruby_parser.yy +34 -23
- data/bundle/ruby/2.5.0/gems/{ruby_parser-3.13.0 → ruby_parser-3.13.1}/lib/ruby_parser_extras.rb +64 -43
- data/bundle/ruby/2.5.0/gems/{ruby_parser-3.13.0 → ruby_parser-3.13.1}/tools/munge.rb +2 -1
- data/bundle/ruby/2.5.0/gems/{ruby_parser-3.13.0 → ruby_parser-3.13.1}/tools/ripper.rb +6 -1
- data/bundle/ruby/2.5.0/gems/{unicode-display_width-1.5.0 → unicode-display_width-1.6.0}/CHANGELOG.md +4 -0
- data/bundle/ruby/2.5.0/gems/{unicode-display_width-1.5.0 → unicode-display_width-1.6.0}/MIT-LICENSE.txt +0 -0
- data/bundle/ruby/2.5.0/gems/{unicode-display_width-1.5.0 → unicode-display_width-1.6.0}/README.md +1 -1
- data/bundle/ruby/2.5.0/gems/{unicode-display_width-1.5.0 → unicode-display_width-1.6.0}/data/display_width.marshal.gz +0 -0
- data/bundle/ruby/2.5.0/gems/{unicode-display_width-1.5.0 → unicode-display_width-1.6.0}/lib/unicode/display_width.rb +0 -0
- data/bundle/ruby/2.5.0/gems/{unicode-display_width-1.5.0 → unicode-display_width-1.6.0}/lib/unicode/display_width/constants.rb +2 -2
- data/bundle/ruby/2.5.0/gems/{unicode-display_width-1.5.0 → unicode-display_width-1.6.0}/lib/unicode/display_width/index.rb +0 -0
- data/bundle/ruby/2.5.0/gems/{unicode-display_width-1.5.0 → unicode-display_width-1.6.0}/lib/unicode/display_width/no_string_ext.rb +0 -0
- data/bundle/ruby/2.5.0/gems/{unicode-display_width-1.5.0 → unicode-display_width-1.6.0}/lib/unicode/display_width/string_ext.rb +0 -0
- data/lib/brakeman.rb +7 -0
- data/lib/brakeman/app_tree.rb +34 -22
- data/lib/brakeman/checks.rb +7 -7
- data/lib/brakeman/checks/base_check.rb +9 -9
- data/lib/brakeman/checks/check_cross_site_scripting.rb +5 -0
- data/lib/brakeman/checks/check_default_routes.rb +5 -0
- data/lib/brakeman/checks/check_deserialize.rb +52 -0
- data/lib/brakeman/checks/check_dynamic_finders.rb +1 -1
- data/lib/brakeman/checks/check_force_ssl.rb +27 -0
- data/lib/brakeman/checks/check_json_parsing.rb +5 -0
- data/lib/brakeman/checks/check_link_to_href.rb +6 -1
- data/lib/brakeman/checks/check_mail_to.rb +1 -1
- data/lib/brakeman/checks/check_model_attr_accessible.rb +1 -1
- data/lib/brakeman/checks/check_model_attributes.rb +12 -50
- data/lib/brakeman/checks/check_model_serialize.rb +1 -1
- data/lib/brakeman/checks/check_nested_attributes_bypass.rb +3 -3
- data/lib/brakeman/checks/check_secrets.rb +1 -1
- data/lib/brakeman/checks/check_session_settings.rb +10 -10
- data/lib/brakeman/checks/check_simple_format.rb +5 -0
- data/lib/brakeman/checks/check_skip_before_filter.rb +1 -1
- data/lib/brakeman/checks/check_sql.rb +15 -17
- data/lib/brakeman/checks/check_validation_regex.rb +1 -1
- data/lib/brakeman/file_parser.rb +6 -8
- data/lib/brakeman/file_path.rb +71 -0
- data/lib/brakeman/options.rb +7 -0
- data/lib/brakeman/parsers/template_parser.rb +3 -3
- data/lib/brakeman/processor.rb +3 -4
- data/lib/brakeman/processors/alias_processor.rb +12 -6
- data/lib/brakeman/processors/base_processor.rb +8 -7
- data/lib/brakeman/processors/controller_alias_processor.rb +10 -7
- data/lib/brakeman/processors/controller_processor.rb +5 -9
- data/lib/brakeman/processors/haml_template_processor.rb +5 -0
- data/lib/brakeman/processors/lib/module_helper.rb +8 -8
- data/lib/brakeman/processors/lib/processor_helper.rb +3 -3
- data/lib/brakeman/processors/lib/rails2_config_processor.rb +3 -3
- data/lib/brakeman/processors/lib/rails2_route_processor.rb +2 -2
- data/lib/brakeman/processors/lib/rails3_config_processor.rb +3 -3
- data/lib/brakeman/processors/lib/rails3_route_processor.rb +2 -2
- data/lib/brakeman/processors/lib/render_helper.rb +2 -2
- data/lib/brakeman/processors/lib/render_path.rb +18 -1
- data/lib/brakeman/processors/library_processor.rb +5 -5
- data/lib/brakeman/processors/model_processor.rb +4 -5
- data/lib/brakeman/processors/output_processor.rb +5 -0
- data/lib/brakeman/processors/template_alias_processor.rb +4 -5
- data/lib/brakeman/processors/template_processor.rb +4 -4
- data/lib/brakeman/report.rb +3 -3
- data/lib/brakeman/report/ignore/config.rb +2 -3
- data/lib/brakeman/report/ignore/interactive.rb +2 -2
- data/lib/brakeman/report/pager.rb +1 -0
- data/lib/brakeman/report/report_base.rb +51 -6
- data/lib/brakeman/report/report_codeclimate.rb +3 -3
- data/lib/brakeman/report/report_hash.rb +1 -1
- data/lib/brakeman/report/report_html.rb +2 -2
- data/lib/brakeman/report/report_json.rb +1 -24
- data/lib/brakeman/report/report_table.rb +20 -4
- data/lib/brakeman/report/report_tabs.rb +1 -1
- data/lib/brakeman/report/report_text.rb +2 -2
- data/lib/brakeman/rescanner.rb +9 -12
- data/lib/brakeman/scanner.rb +19 -14
- data/lib/brakeman/tracker.rb +4 -4
- data/lib/brakeman/tracker/collection.rb +4 -3
- data/lib/brakeman/tracker/config.rb +6 -0
- data/lib/brakeman/util.rb +1 -147
- data/lib/brakeman/version.rb +1 -1
- data/lib/brakeman/warning.rb +23 -13
- data/lib/brakeman/warning_codes.rb +1 -0
- data/lib/ruby_parser/bm_sexp_processor.rb +1 -0
- metadata +78 -61
- data/bundle/ruby/2.5.0/gems/highline-1.7.10/Gemfile +0 -11
- data/bundle/ruby/2.5.0/gems/highline-1.7.10/INSTALL +0 -59
- data/bundle/ruby/2.5.0/gems/highline-1.7.10/README.rdoc +0 -74
- data/bundle/ruby/2.5.0/gems/highline-1.7.10/highline.gemspec +0 -37
- data/bundle/ruby/2.5.0/gems/highline-1.7.10/lib/highline.rb +0 -1048
- data/bundle/ruby/2.5.0/gems/highline-1.7.10/lib/highline/compatibility.rb +0 -16
- data/bundle/ruby/2.5.0/gems/highline-1.7.10/lib/highline/import.rb +0 -41
- data/bundle/ruby/2.5.0/gems/highline-1.7.10/lib/highline/menu.rb +0 -381
- data/bundle/ruby/2.5.0/gems/highline-1.7.10/lib/highline/simulate.rb +0 -48
- data/bundle/ruby/2.5.0/gems/highline-1.7.10/lib/highline/string_extensions.rb +0 -111
- data/bundle/ruby/2.5.0/gems/highline-1.7.10/lib/highline/style.rb +0 -192
- data/bundle/ruby/2.5.0/gems/highline-1.7.10/lib/highline/system_extensions.rb +0 -254
- data/bundle/ruby/2.5.0/gems/highline-1.7.10/setup.rb +0 -1360
@@ -199,10 +199,6 @@ class Brakeman::Report::Table < Brakeman::Report::Base
|
|
199
199
|
end
|
200
200
|
end
|
201
201
|
|
202
|
-
def convert_warning warning, original
|
203
|
-
warning
|
204
|
-
end
|
205
|
-
|
206
202
|
def convert_ignored_warning warning, original
|
207
203
|
convert_warning warning, original
|
208
204
|
end
|
@@ -271,4 +267,24 @@ Duration: #{tracker.duration} seconds
|
|
271
267
|
Checks run: #{checks.checks_run.sort.join(", ")}
|
272
268
|
HEADER
|
273
269
|
end
|
270
|
+
|
271
|
+
def truncate_table str
|
272
|
+
@terminal_width ||= if @tracker.options[:table_width]
|
273
|
+
@tracker.options[:table_width]
|
274
|
+
elsif $stdin && $stdin.tty?
|
275
|
+
Brakeman.load_brakeman_dependency 'highline'
|
276
|
+
::HighLine.default_instance.terminal.terminal_size[0]
|
277
|
+
else
|
278
|
+
80
|
279
|
+
end
|
280
|
+
lines = str.lines
|
281
|
+
|
282
|
+
lines.map do |line|
|
283
|
+
if line.chomp.length > @terminal_width
|
284
|
+
line[0..(@terminal_width - 3)] + ">>\n"
|
285
|
+
else
|
286
|
+
line
|
287
|
+
end
|
288
|
+
end.join
|
289
|
+
end
|
274
290
|
end
|
@@ -10,7 +10,7 @@ class Brakeman::Report::Tabs < Brakeman::Report::Table
|
|
10
10
|
self.send(meth).map do |w|
|
11
11
|
line = w.line || 0
|
12
12
|
w.warning_type.gsub!(/[^\w\s]/, ' ')
|
13
|
-
"#{
|
13
|
+
"#{(w.file.absolute)}\t#{line}\t#{w.warning_type}\t#{category}\t#{w.format_message}\t#{TEXT_CONFIDENCE[w.confidence]}"
|
14
14
|
end.join "\n"
|
15
15
|
|
16
16
|
end.join "\n"
|
@@ -201,8 +201,8 @@ class Brakeman::Report::Text < Brakeman::Report::Base
|
|
201
201
|
|
202
202
|
# ONLY used for generate_controllers to avoid duplication
|
203
203
|
def render_array name, cols, values, locals
|
204
|
-
controllers = values.map do |
|
205
|
-
c = [ label("Controller",
|
204
|
+
controllers = values.map do |controller_name, parent, includes, routes|
|
205
|
+
c = [ label("Controller", controller_name) ]
|
206
206
|
c << label("Parent", parent) unless parent.empty?
|
207
207
|
c << label("Includes", includes) unless includes.empty?
|
208
208
|
c << label("Routes", routes)
|
data/lib/brakeman/rescanner.rb
CHANGED
@@ -13,7 +13,7 @@ class Brakeman::Rescanner < Brakeman::Scanner
|
|
13
13
|
def initialize options, processor, changed_files
|
14
14
|
super(options, processor)
|
15
15
|
|
16
|
-
@paths = changed_files.map {|f|
|
16
|
+
@paths = changed_files.map {|f| tracker.app_tree.file_path(f) }
|
17
17
|
@old_results = tracker.filtered_warnings #Old warnings from previous scan
|
18
18
|
@changes = nil #True if files had to be rescanned
|
19
19
|
@reindex = Set.new
|
@@ -67,7 +67,7 @@ class Brakeman::Rescanner < Brakeman::Scanner
|
|
67
67
|
def rescan_file path, type = nil
|
68
68
|
type ||= file_type path
|
69
69
|
|
70
|
-
unless
|
70
|
+
unless path.exists?
|
71
71
|
return rescan_deleted_file path, type
|
72
72
|
end
|
73
73
|
|
@@ -127,14 +127,14 @@ class Brakeman::Rescanner < Brakeman::Scanner
|
|
127
127
|
end
|
128
128
|
|
129
129
|
def rescan_template path
|
130
|
-
return unless path.match KNOWN_TEMPLATE_EXTENSIONS and
|
130
|
+
return unless path.relative.match KNOWN_TEMPLATE_EXTENSIONS and path.exists?
|
131
131
|
|
132
132
|
template_name = template_path_to_name(path)
|
133
133
|
|
134
134
|
tracker.reset_template template_name
|
135
|
-
fp = Brakeman::FileParser.new(tracker
|
135
|
+
fp = Brakeman::FileParser.new(tracker)
|
136
136
|
template_parser = Brakeman::TemplateParser.new(tracker, fp)
|
137
|
-
template_parser.parse_template path,
|
137
|
+
template_parser.parse_template path, path.read
|
138
138
|
process_template fp.file_list[:templates].first
|
139
139
|
|
140
140
|
@processor.process_template_alias tracker.templates[template_name]
|
@@ -256,16 +256,13 @@ class Brakeman::Rescanner < Brakeman::Scanner
|
|
256
256
|
end
|
257
257
|
|
258
258
|
def rescan_deleted_template path
|
259
|
-
return unless path.match KNOWN_TEMPLATE_EXTENSIONS
|
259
|
+
return unless path.relative.match KNOWN_TEMPLATE_EXTENSIONS
|
260
260
|
|
261
261
|
template_name = template_path_to_name(path)
|
262
262
|
|
263
263
|
#Remove template
|
264
264
|
tracker.reset_template template_name
|
265
265
|
|
266
|
-
rendered_from_controller = /^#{template_name}\.(.+Controller)#(.+)/
|
267
|
-
rendered_from_view = /^#{template_name}\.Template:(.+)/
|
268
|
-
|
269
266
|
#Remove any rendered versions, or partials rendered from it
|
270
267
|
tracker.templates.delete_if do |_name, template|
|
271
268
|
template.file == path or template.name.to_sym == template_name.to_sym
|
@@ -371,7 +368,7 @@ class Brakeman::Rescanner < Brakeman::Scanner
|
|
371
368
|
next unless template.render_path
|
372
369
|
|
373
370
|
if template.render_path.include_any_method? method_names
|
374
|
-
name.to_s.match
|
371
|
+
name.to_s.match(/^([^.]+)/)
|
375
372
|
|
376
373
|
original = tracker.templates[$1.to_sym]
|
377
374
|
|
@@ -388,8 +385,8 @@ class Brakeman::Rescanner < Brakeman::Scanner
|
|
388
385
|
end
|
389
386
|
|
390
387
|
def parse_ruby_files list
|
391
|
-
paths = list.select
|
392
|
-
file_parser = Brakeman::FileParser.new(tracker
|
388
|
+
paths = list.select(&:exists?)
|
389
|
+
file_parser = Brakeman::FileParser.new(tracker)
|
393
390
|
file_parser.parse_files paths, :rescan
|
394
391
|
file_parser.file_list[:rescan]
|
395
392
|
end
|
data/lib/brakeman/scanner.rb
CHANGED
@@ -16,7 +16,6 @@ end
|
|
16
16
|
#Scans the Rails application.
|
17
17
|
class Brakeman::Scanner
|
18
18
|
attr_reader :options
|
19
|
-
RUBY_1_9 = RUBY_VERSION >= "1.9.0"
|
20
19
|
|
21
20
|
#Pass in path to the root of the Rails application
|
22
21
|
def initialize options, processor = nil
|
@@ -66,7 +65,7 @@ class Brakeman::Scanner
|
|
66
65
|
end
|
67
66
|
|
68
67
|
def parse_files
|
69
|
-
fp = Brakeman::FileParser.new tracker
|
68
|
+
fp = Brakeman::FileParser.new tracker
|
70
69
|
|
71
70
|
files = {
|
72
71
|
:initializers => @app_tree.initializer_paths,
|
@@ -95,7 +94,7 @@ class Brakeman::Scanner
|
|
95
94
|
#
|
96
95
|
#Stores parsed information in tracker.config
|
97
96
|
def process_config
|
98
|
-
if options[:rails3] or options[:rails4] or options[:rails5]
|
97
|
+
if options[:rails3] or options[:rails4] or options[:rails5] or options[:rails6]
|
99
98
|
process_config_file "application.rb"
|
100
99
|
process_config_file "environments/production.rb"
|
101
100
|
else
|
@@ -111,14 +110,14 @@ class Brakeman::Scanner
|
|
111
110
|
end
|
112
111
|
|
113
112
|
if @app_tree.exists? ".ruby-version"
|
114
|
-
tracker.config.set_ruby_version @app_tree.
|
113
|
+
tracker.config.set_ruby_version @app_tree.file_path(".ruby-version").read
|
115
114
|
end
|
116
115
|
end
|
117
116
|
|
118
117
|
def process_config_file file
|
119
|
-
path = "config/#{file}"
|
118
|
+
path = @app_tree.file_path("config/#{file}")
|
120
119
|
|
121
|
-
if
|
120
|
+
if path.exists?
|
122
121
|
@processor.process_config(parse_ruby_file(path), path)
|
123
122
|
end
|
124
123
|
|
@@ -132,16 +131,21 @@ class Brakeman::Scanner
|
|
132
131
|
#Process Gemfile
|
133
132
|
def process_gems
|
134
133
|
gem_files = {}
|
134
|
+
|
135
135
|
if @app_tree.exists? "Gemfile"
|
136
|
-
|
136
|
+
file = @app_tree.file_path("Gemfile")
|
137
|
+
gem_files[:gemfile] = { :src => parse_ruby_file(file), :file => file }
|
137
138
|
elsif @app_tree.exists? "gems.rb"
|
138
|
-
|
139
|
+
file = @app_tree.file_path("gems.rb")
|
140
|
+
gem_files[:gemfile] = { :src => parse_ruby_file(file), :file => file }
|
139
141
|
end
|
140
142
|
|
141
143
|
if @app_tree.exists? "Gemfile.lock"
|
142
|
-
|
144
|
+
file = @app_tree.file_path("Gemfile.lock")
|
145
|
+
gem_files[:gemlock] = { :src => file.read, :file => file }
|
143
146
|
elsif @app_tree.exists? "gems.locked"
|
144
|
-
|
147
|
+
file = @app_tree.file_path("gems.locked")
|
148
|
+
gem_files[:gemlock] = { :src => file.read, :file => file }
|
145
149
|
end
|
146
150
|
|
147
151
|
if @app_tree.gemspec
|
@@ -215,7 +219,8 @@ class Brakeman::Scanner
|
|
215
219
|
#Adds parsed information to tracker.routes
|
216
220
|
def process_routes
|
217
221
|
if @app_tree.exists?("config/routes.rb")
|
218
|
-
|
222
|
+
file = @app_tree.file_path("config/routes.rb")
|
223
|
+
if routes_sexp = parse_ruby_file(file)
|
219
224
|
@processor.process_routes routes_sexp
|
220
225
|
else
|
221
226
|
Brakeman.notify "[Notice] Error while processing routes - assuming all public controller methods are actions."
|
@@ -316,9 +321,9 @@ class Brakeman::Scanner
|
|
316
321
|
tracker.index_call_sites
|
317
322
|
end
|
318
323
|
|
319
|
-
def parse_ruby_file
|
320
|
-
fp = Brakeman::FileParser.new(self.tracker
|
321
|
-
fp.parse_ruby(
|
324
|
+
def parse_ruby_file file
|
325
|
+
fp = Brakeman::FileParser.new(self.tracker)
|
326
|
+
fp.parse_ruby(file.read, file)
|
322
327
|
end
|
323
328
|
end
|
324
329
|
|
data/lib/brakeman/tracker.rb
CHANGED
@@ -12,7 +12,7 @@ class Brakeman::Tracker
|
|
12
12
|
attr_accessor :controllers, :constants, :templates, :models, :errors,
|
13
13
|
:checks, :initializers, :config, :routes, :processor, :libs,
|
14
14
|
:template_cache, :options, :filter_cache, :start_time, :end_time,
|
15
|
-
:duration, :ignored_filter
|
15
|
+
:duration, :ignored_filter, :app_tree
|
16
16
|
|
17
17
|
#Place holder when there should be a model, but it is not
|
18
18
|
#clear what model it will be.
|
@@ -34,7 +34,7 @@ class Brakeman::Tracker
|
|
34
34
|
#we can match models later without knowing precisely what
|
35
35
|
#class they are.
|
36
36
|
@models = {}
|
37
|
-
@models[UNKNOWN_MODEL] = Brakeman::Model.new(UNKNOWN_MODEL, nil,
|
37
|
+
@models[UNKNOWN_MODEL] = Brakeman::Model.new(UNKNOWN_MODEL, nil, @app_tree.file_path("NOT_REAL.rb"), nil, self)
|
38
38
|
@routes = {}
|
39
39
|
@initializers = {}
|
40
40
|
@errors = []
|
@@ -71,7 +71,7 @@ class Brakeman::Tracker
|
|
71
71
|
#Run a set of checks on the current information. Results will be stored
|
72
72
|
#in Tracker#checks.
|
73
73
|
def run_checks
|
74
|
-
@checks = Brakeman::Checks.run_checks(
|
74
|
+
@checks = Brakeman::Checks.run_checks(self)
|
75
75
|
|
76
76
|
@end_time = Time.now
|
77
77
|
@duration = @end_time - @start_time
|
@@ -172,7 +172,7 @@ class Brakeman::Tracker
|
|
172
172
|
|
173
173
|
#Returns a Report with this Tracker's information
|
174
174
|
def report
|
175
|
-
Brakeman::Report.new(
|
175
|
+
Brakeman::Report.new(self)
|
176
176
|
end
|
177
177
|
|
178
178
|
def warnings
|
@@ -9,13 +9,14 @@ module Brakeman
|
|
9
9
|
def initialize name, parent, file_name, src, tracker
|
10
10
|
@name = name
|
11
11
|
@parent = parent
|
12
|
-
@
|
13
|
-
@
|
14
|
-
@src = { file_name => src }
|
12
|
+
@files = []
|
13
|
+
@src = {}
|
15
14
|
@includes = []
|
16
15
|
@methods = { :public => {}, :private => {}, :protected => {} }
|
17
16
|
@options = {}
|
18
17
|
@tracker = tracker
|
18
|
+
|
19
|
+
add_file file_name, src
|
19
20
|
end
|
20
21
|
|
21
22
|
def ancestor? parent, seen={}
|
@@ -97,6 +97,12 @@ module Brakeman
|
|
97
97
|
tracker.options[:rails4] = true
|
98
98
|
tracker.options[:rails5] = true
|
99
99
|
Brakeman.notify "[Notice] Detected Rails 5 application"
|
100
|
+
elsif @rails_version.start_with? "6"
|
101
|
+
tracker.options[:rails3] = true
|
102
|
+
tracker.options[:rails4] = true
|
103
|
+
tracker.options[:rails5] = true
|
104
|
+
tracker.options[:rails6] = true
|
105
|
+
Brakeman.notify "[Notice] Detected Rails 6 application"
|
100
106
|
end
|
101
107
|
end
|
102
108
|
end
|
data/lib/brakeman/util.rb
CHANGED
@@ -346,158 +346,12 @@ module Brakeman::Util
|
|
346
346
|
@tracker.config.rails_version
|
347
347
|
end
|
348
348
|
|
349
|
-
#Return file name related to given warning. Uses +warning.file+ if it exists
|
350
|
-
def file_for warning, tracker = nil
|
351
|
-
if tracker.nil?
|
352
|
-
tracker = @tracker || self.tracker
|
353
|
-
end
|
354
|
-
|
355
|
-
if warning.file
|
356
|
-
File.expand_path warning.file, tracker.app_path
|
357
|
-
elsif warning.template and warning.template.file
|
358
|
-
warning.template.file
|
359
|
-
else
|
360
|
-
case warning.warning_set
|
361
|
-
when :controller
|
362
|
-
file_by_name warning.controller, :controller, tracker
|
363
|
-
when :template
|
364
|
-
file_by_name warning.template.name, :template, tracker
|
365
|
-
when :model
|
366
|
-
file_by_name warning.model, :model, tracker
|
367
|
-
when :warning
|
368
|
-
file_by_name warning.class, nil, tracker
|
369
|
-
else
|
370
|
-
nil
|
371
|
-
end
|
372
|
-
end
|
373
|
-
end
|
374
|
-
|
375
|
-
#Attempt to determine path to context file based on the reported name
|
376
|
-
#in the warning.
|
377
|
-
#
|
378
|
-
#For example,
|
379
|
-
#
|
380
|
-
# file_by_name FileController #=> "/rails/root/app/controllers/file_controller.rb
|
381
|
-
def file_by_name name, type, tracker = nil
|
382
|
-
return nil unless name
|
383
|
-
string_name = name.to_s
|
384
|
-
name = name.to_sym
|
385
|
-
|
386
|
-
unless type
|
387
|
-
if string_name =~ /Controller$/
|
388
|
-
type = :controller
|
389
|
-
elsif camelize(string_name) == string_name # This is not always true
|
390
|
-
type = :model
|
391
|
-
else
|
392
|
-
type = :template
|
393
|
-
end
|
394
|
-
end
|
395
|
-
|
396
|
-
path = tracker.app_path
|
397
|
-
|
398
|
-
case type
|
399
|
-
when :controller
|
400
|
-
if tracker.controllers[name]
|
401
|
-
path = tracker.controllers[name].file
|
402
|
-
else
|
403
|
-
path += "/app/controllers/#{underscore(string_name)}.rb"
|
404
|
-
end
|
405
|
-
when :model
|
406
|
-
if tracker.models[name]
|
407
|
-
path = tracker.models[name].file
|
408
|
-
else
|
409
|
-
path += "/app/models/#{underscore(string_name)}.rb"
|
410
|
-
end
|
411
|
-
when :template
|
412
|
-
if tracker.templates[name] and tracker.templates[name].file
|
413
|
-
path = tracker.templates[name].file
|
414
|
-
elsif string_name.include? " "
|
415
|
-
name = string_name.split[0].to_sym
|
416
|
-
path = file_for tracker, name, :template
|
417
|
-
else
|
418
|
-
path = nil
|
419
|
-
end
|
420
|
-
end
|
421
|
-
|
422
|
-
path
|
423
|
-
end
|
424
|
-
|
425
|
-
#Return array of lines surrounding the warning location from the original
|
426
|
-
#file.
|
427
|
-
def context_for app_tree, warning, tracker = nil
|
428
|
-
file = file_for warning, tracker
|
429
|
-
context = []
|
430
|
-
return context unless warning.line and file and @app_tree.path_exists? file
|
431
|
-
|
432
|
-
current_line = 0
|
433
|
-
start_line = warning.line - 5
|
434
|
-
end_line = warning.line + 5
|
435
|
-
|
436
|
-
start_line = 1 if start_line < 0
|
437
|
-
|
438
|
-
File.open file do |f|
|
439
|
-
f.each_line do |line|
|
440
|
-
current_line += 1
|
441
|
-
|
442
|
-
next if line.strip == ""
|
443
|
-
|
444
|
-
if current_line > end_line
|
445
|
-
break
|
446
|
-
end
|
447
|
-
|
448
|
-
if current_line >= start_line
|
449
|
-
context << [current_line, line]
|
450
|
-
end
|
451
|
-
end
|
452
|
-
end
|
453
|
-
|
454
|
-
context
|
455
|
-
end
|
456
|
-
|
457
|
-
def relative_path file
|
458
|
-
pname = Pathname.new file
|
459
|
-
if file and not file.empty? and pname.absolute?
|
460
|
-
pname.relative_path_from(Pathname.new(@tracker.app_path)).to_s
|
461
|
-
else
|
462
|
-
file
|
463
|
-
end
|
464
|
-
end
|
465
|
-
|
466
349
|
#Convert path/filename to view name
|
467
350
|
#
|
468
351
|
# views/test/something.html.erb -> test/something
|
469
352
|
def template_path_to_name path
|
470
|
-
names = path.split("/")
|
353
|
+
names = path.relative.split("/")
|
471
354
|
names.last.gsub!(/(\.(html|js)\..*|\.(rhtml|haml|erb|slim))$/, '')
|
472
355
|
names[(names.index("views") + 1)..-1].join("/").to_sym
|
473
356
|
end
|
474
|
-
|
475
|
-
def github_url file, line=nil
|
476
|
-
if repo_url = @tracker.options[:github_url] and file and not file.empty? and file.start_with? '/'
|
477
|
-
url = "#{repo_url}/#{relative_path(file)}"
|
478
|
-
url << "#L#{line}" if line
|
479
|
-
else
|
480
|
-
nil
|
481
|
-
end
|
482
|
-
end
|
483
|
-
|
484
|
-
def truncate_table str
|
485
|
-
@terminal_width ||= if @tracker.options[:table_width]
|
486
|
-
@tracker.options[:table_width]
|
487
|
-
elsif $stdin && $stdin.tty?
|
488
|
-
Brakeman.load_brakeman_dependency 'highline'
|
489
|
-
::HighLine.new.terminal_size[0]
|
490
|
-
else
|
491
|
-
80
|
492
|
-
end
|
493
|
-
lines = str.lines
|
494
|
-
|
495
|
-
lines.map do |line|
|
496
|
-
if line.chomp.length > @terminal_width
|
497
|
-
line[0..(@terminal_width - 3)] + ">>\n"
|
498
|
-
else
|
499
|
-
line
|
500
|
-
end
|
501
|
-
end.join
|
502
|
-
end
|
503
357
|
end
|