Skip to content

Commit

Permalink
Add --show-ignored flag
Browse files Browse the repository at this point in the history
  • Loading branch information
gazayas committed Jul 25, 2024
1 parent ed7242d commit e1d32ce
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 0 deletions.
4 changes: 4 additions & 0 deletions OPTIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,10 @@ Brakeman will raise warnings on models that use `attr_protected`. To suppress th

brakeman --ignore-protected

To show all ignored warnings without affecting the exit code (i.e. - Will return `0` if the application shows no warnings when simply running `brakeman`):

brakeman --show-ignored

Brakeman will assume that unknown methods involving untrusted data are dangerous. For example, this would cause a warning (Rails 2):

<%= some_method(:option => params[:input]) %>
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@ To create and manage this file, use:

brakeman -I

If you want to temporarily see the warnings you ignored without affecting the exit code, use:

brakeman --show-ignored

# Warning information

See [warning\_types](docs/warning_types) for more information on the warnings reported by this tool.
Expand Down
2 changes: 2 additions & 0 deletions lib/brakeman.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ module Brakeman
# * :report_routes - show found routes on controllers (default: false)
# * :run_checks - array of checks to run (run all if not specified)
# * :safe_methods - array of methods to consider safe
# * :show_ignored - Display warnings that are usually ignored
# * :sql_safe_methods - array of sql sanitization methods to consider safe
# * :skip_libs - do not process lib/ directory (default: false)
# * :skip_vendor - do not process vendor/ directory (default: true)
Expand Down Expand Up @@ -198,6 +199,7 @@ def self.default_options
:relative_path => false,
:report_progress => true,
:safe_methods => Set.new,
:show_ignored => false,
:sql_safe_methods => Set.new,
:skip_checks => Set.new,
:skip_vendor => true,
Expand Down
4 changes: 4 additions & 0 deletions lib/brakeman/options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,10 @@ def create_option_parser options
options[:interactive_ignore] = true
end

opts.on "--show-ignored", "Show files that are usually ignored by the ignore configuration file" do
options[:show_ignored] = true
end

opts.on "-l", "--[no-]combine-locations", "Combine warning locations (Default)" do |combine|
options[:combine_locations] = combine
end
Expand Down
5 changes: 5 additions & 0 deletions lib/brakeman/report/report_text.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ def generate_report
unless summary_option == :no_summary
add_chunk generate_header
add_chunk generate_overview
add_chunk generate_show_ignored_overview if tracker.options[:show_ignored] && ignored_warnings.any?
add_chunk generate_warning_overview
end

Expand Down Expand Up @@ -101,6 +102,10 @@ def generate_warnings
end
end

def generate_show_ignored_overview
double_space("Ignored File Overview", ignored_warnings.map {|w| output_warning w})
end

def generate_errors
return if tracker.errors.empty?
full_trace = tracker.options[:debug]
Expand Down
7 changes: 7 additions & 0 deletions test/tests/commandline.rb
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,13 @@ def test_exit_on_warn_no_warnings
end
end

# Assert default when using `--show-ignored` flag.
def test_show_ignored_warnings
assert_exit Brakeman::Warnings_Found_Exit_Code do
scan_app "--show-ignored"
end
end

def test_compare_deactivates_ensure_ignore_notes
opts, = Brakeman::Commandline.parse_options [
'--ensure-ignore-notes',
Expand Down

0 comments on commit e1d32ce

Please sign in to comment.