diff --git a/bin/brakeman b/bin/brakeman index 7e1727963786beae274eef51a30d45af99819687..c5971c4f6b203a9e1b1f0292f6f9ebdae36b8f83 100755 --- a/bin/brakeman +++ b/bin/brakeman @@ -24,6 +24,10 @@ OptionParser.new do |opts| options[:parallel_checks] = false end + opts.on "--no-progress", "Do not show progress reports" do + options[:report_progress] = false + end + opts.on "-p", "--path PATH", "Specify path to Rails application" do |path| options[:app_path] = File.expand_path path end diff --git a/lib/brakeman.rb b/lib/brakeman.rb index 9a228b7153416423168ab536974ff96e5171a42f..655442584a74e8b7e95a90f3be0a2bd7c18d301f 100644 --- a/lib/brakeman.rb +++ b/lib/brakeman.rb @@ -48,6 +48,7 @@ module Brakeman options = set_options options if options[:quiet] + options[:report_progress] = false $VERBOSE = nil end @@ -120,6 +121,7 @@ module Brakeman :message_limit => 100, :parallel_checks => true, :quiet => true, + :report_progress => true, :html_style => "#{File.expand_path(File.dirname(__FILE__))}/brakeman/format/style.css" } end diff --git a/lib/brakeman/scanner.rb b/lib/brakeman/scanner.rb index 94974a4ca660b2711a90f6a3123e5c70f626efec..c83eb0cba4e211e2e79745cff0b6ad226dbe8a89 100644 --- a/lib/brakeman/scanner.rb +++ b/lib/brakeman/scanner.rb @@ -32,6 +32,7 @@ class Brakeman::Scanner #Pass in path to the root of the Rails application def initialize options @options = options + @report_progress = options[:report_progress] @path = options[:app_path] @app_path = File.join(@path, "app") @processor = Brakeman::Processor.new options @@ -58,15 +59,15 @@ class Brakeman::Scanner process_initializers warn "Processing libs..." process_libs - warn "Processing routes..." + warn "Processing routes... " process_routes - warn "Processing templates..." + warn "Processing templates... " process_templates - warn "Processing models..." + warn "Processing models... " process_models - warn "Processing controllers..." + warn "Processing controllers... " process_controllers - warn "Indexing call sites..." + warn "Indexing call sites... " index_call_sites tracker end @@ -142,7 +143,16 @@ class Brakeman::Scanner return end - Dir.glob(@path + "/lib/**/*.rb").sort.each do |f| + lib_files = Dir.glob(@path + "/lib/**/*.rb").sort + total = lib_files.length + current = 0 + + lib_files.each do |f| + if @report_progress + print " #{current}/#{total} files processed\r" + current += 1 + end + begin @processor.process_lib parse_ruby(File.read(f)), f rescue Racc::ParseError => e @@ -174,7 +184,17 @@ class Brakeman::Scanner # #Adds processed controllers to tracker.controllers def process_controllers - Dir.glob(@app_path + "/controllers/**/*.rb").sort.each do |f| + controller_files = Dir.glob(@app_path + "/controllers/**/*.rb").sort + total = controller_files.length * 2 + current = 0 + + controller_files.each do |f| + warn "Processing #{f}" if options[:debug] + if @report_progress + print " #{current}/#{total} files processed\r" + current += 1 + end + begin @processor.process_controller(parse_ruby(File.read(f)), f) rescue Racc::ParseError => e @@ -184,7 +204,17 @@ class Brakeman::Scanner end end + current = 0 + total = tracker.controllers.length + + warn "Processing data flow in controllers..." + tracker.controllers.each do |name, controller| + if @report_progress + print " #{current}/#{total} controllers processed\r" + current += 1 + end + @processor.process_controller_alias controller[:src] end end @@ -198,8 +228,15 @@ class Brakeman::Scanner $stdout.sync = true count = 0 - Dir.glob(views_path).sort.each do |f| - count += 1 + template_files = Dir.glob(views_path).sort + total = template_files.length + + template_files.each do |f| + if @report_progress + count += 1 + print " #{count}/#{total} files processed\r" + end + type = f.match(/.*\.(erb|haml|rhtml)$/)[1].to_sym type = :erb if type == :rhtml name = template_path_to_name f @@ -242,7 +279,17 @@ class Brakeman::Scanner end end + total = tracker.templates.length + count = 0 + + warn "Processing data flow in templates..." + tracker.templates.keys.dup.each do |name| + if @report_progress + count += 1 + print " #{count}/#{total} templates processed\r" + end + @processor.process_template_alias tracker.templates[name] end @@ -261,7 +308,17 @@ class Brakeman::Scanner # #Adds the processed models to tracker.models def process_models - Dir.glob(@app_path + "/models/*.rb").sort.each do |f| + model_files = Dir.glob(@app_path + "/models/*.rb").sort + + total = model_files.length + current = 0 + + model_files.each do |f| + if @report_progress + print " #{current}/#{total} files processed\r" + current += 1 + end + begin @processor.process_model(parse_ruby(File.read(f)), f) rescue Racc::ParseError => e