Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --show-ignored flag #1861

Merged
merged 4 commits into from
Aug 21, 2024

Conversation

gazayas
Copy link
Contributor

@gazayas gazayas commented Jul 25, 2024

Closes #1767.

After scaffolding a Foo model with a couple of vulnerabilities on a new application, running brakeman --show-ignored displays the following:

> brakeman --show-ignored
...

== Overview ==

Controllers: 2
Models: 2
Templates: 8
Errors: 0
Security Warnings: 0
Ignored Warnings: 2

== Ignored File Overview ==

Confidence: High
Category: SQL Injection
Check: SQL
Message: Possible SQL injection
Code: Foo.where(("bar = " + params[:bar]))
File: app/controllers/foos_controller.rb
Line: 24

Confidence: High
Category: SQL Injection
Check: SQL
Message: Possible SQL injection
Code: Foo.where(("bar = " + params[:bar]))
File: app/controllers/foos_controller.rb
Line: 40

== Warning Types ==


No warnings found

> echo $?
0

This ensures the exit code is unaffected by adding the flag (you can see in the test I added that the exit code returned is 3 which is the default in the command line test).

I wanted to check the output and not just the exit code in the command line test, but I had some trouble finding the right way to do it.

Either way, Looking back at this comment, if we do want to affect the exit code or take another approach, I'd be glad to look over the logic again.

Copy link

dryrunsecurity bot commented Jul 25, 2024

DryRun Security Summary

The pull request enhances the Brakeman application security scanner by adding a new command-line option to display ignored files and warnings, improving the reporting functionality, and enhancing the test suite to ensure the reliability and security-related functionality of the tool.

Expand for full summary

Summary:

The code changes in this pull request are focused on enhancing the functionality and usability of the Brakeman application security scanner. The key changes include:

  1. Addition of a new command-line option --show-ignored that allows users to display the files and warnings that are usually ignored by Brakeman's ignore configuration. This provides more transparency into the scanning process and can help identify potential security issues that may have been overlooked.

  2. Improvements to the reporting functionality, including the addition of a new section in the text-based report that summarizes the ignored warnings. This feature can be valuable for security teams to better understand the scope of the security analysis.

  3. Enhancements to the test suite, including new test cases to verify the behavior of the --show-ignored option and the interaction between different command-line options. These changes help to ensure the reliability and security-related functionality of the Brakeman tool.

Overall, these changes are focused on improving the usability, configurability, and transparency of the Brakeman security scanner, which can indirectly benefit the security of Ruby on Rails applications by making it easier for developers and security teams to identify and address potential vulnerabilities.

Files Changed:

  • lib/brakeman/options.rb: Adds a new command-line option --show-ignored to display the files that are usually ignored by the ignore configuration file.
  • README.md: Adds a new section explaining how to use the --show-ignored option to temporarily see the warnings that Brakeman has ignored.
  • lib/brakeman.rb: Adds a new option :show_ignored to the Brakeman configuration, which allows the user to display warnings that are usually ignored.
  • OPTIONS.md: Documents the new --show-ignored option and clarifies the usage of the --ignore-protected option.
  • lib/brakeman/report/report_text.rb: Adds a new method generate_show_ignored_overview to include a section in the text-based report that lists the ignored warnings.
  • test/tests/options.rb: Adds a new test case test_show_ignored_option to verify the behavior of the :show_ignored option.
  • test/tests/commandline.rb: Adds a new test case test_show_ignored_warnings to check the behavior of the --show-ignored flag, and modifies an existing test case to ensure the --ensure-ignore-notes option is deactivated when the --compare option is used.

Code Analysis

We ran 9 analyzers against 7 files and 1 analyzer had findings. 8 analyzers had no findings.

Analyzer Findings
Authn/Authz Analyzer 1 finding

Riskiness

🟢 Risk threshold not exceeded.

View PR in the DryRun Dashboard.

@presidentbeef
Copy link
Owner

Thanks!

Can you also add a simple test in test/tests/options.rb?

@gazayas
Copy link
Contributor Author

gazayas commented Aug 5, 2024

Done!

@@ -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})
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should go at the end of the report, after generate_warnings, not as part of the summary. It's not a summary, it's a list of warnings.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also title should be "Ignored Warnings" instead of "Ignored File Overview"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, I went ahead and changed the title here: 3203739

I moved generate_show_ignored_overview to the end below this line, but I'm getting some test errors so I'll try to push the changes once I figure that part out.

Copy link
Contributor Author

@gazayas gazayas Aug 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I moved generate_show_ignored_overview to the end of the report.

I explicitly return @output_string here because adding generate_show_ignored_overview at the end was returning nil in some cases (When --show-ignored isn't used, the if statement returns nil). All of these lines that use add_chunk don't set a second argument so all of the contents are saved to @output_string, so I think it should be safe to return the instance variable here explicitly.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense. Just coincidence that it's worked all this time since generate_warnings always returns something.

@presidentbeef presidentbeef merged commit 1f7bbad into presidentbeef:main Aug 21, 2024
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Is there a flag to show all warnings including the ignored ones?
2 participants