A static analysis security vulnerability scanner for Ruby on Rails applications
A static analysis security vulnerability scanner for Ruby on Rails applications
Brakeman is a static analysis tool which checks Ruby on Rails applications for security vulnerabilities.
Using RubyGems:
gem install brakemanUsing Bundler:
group :development do
gem 'brakeman', require: false
endUsing Docker:
docker pull presidentbeef/brakemanUsing Docker to build from source:
git clone https://github.com/presidentbeef/brakeman.git
cd brakeman
docker build . -t brakemanFrom a Rails application's root directory:
brakemanOutside of Rails root:
brakeman /path/to/rails/applicationFrom a Rails application's root directory:
docker run -v "$(pwd)":/code presidentbeef/brakemanWith a little nicer color:
docker run -v "$(pwd)":/code presidentbeef/brakeman --colorFor an HTML report:
docker run -v "$(pwd)":/code presidentbeef/brakeman -o brakeman_results.htmlOutside of Rails root (note that the output file is relative to path/to/rails/application):
docker run -v 'path/to/rails/application':/code presidentbeef/brakeman -o brakeman_results.htmlBrakeman should work with any version of Rails from 2.3.x to 8.x.
Brakeman can analyze code written with Ruby 2.0 syntax and newer, but requires at least Ruby 3.2.0 to run.
For a full list of options, use brakeman --help or see the OPTIONS.md file.
To specify an output file for the results:
brakeman -o output_fileThe output format is determined by the file extension or by using the -f option. Current options are: text, html, tabs, json, junit, markdown, csv, codeclimate, github, sarif, and sonar.
Multiple output files can be specified:
brakeman -o output.html -o output.jsonTo output to both a file and to the console, with color:
brakeman --color -o /dev/stdout -o output.jsonTo suppress informational warnings and just output the report:
brakeman -qNote all Brakeman output except reports are sent to stderr, making it simple to redirect stdout to a file and just get the report.
To see all kinds of debugging information:
brakeman -dSpecific checks can be skipped, if desired. The name needs to be the correct case. For example, to skip looking for default routes (DefaultRoutes):
brakeman -x DefaultRoutesMultiple checks should be separated by a comma:
brakeman -x DefaultRoutes,RedirectTo do the opposite and only run a certain set of tests:
brakeman -t SQL,ValidationRegexIf Brakeman is running a bit slow, try
brakeman --fasterThis will disable some features, but will probably be much faster (currently it is the same as --skip-libs --no-branching). WARNING: This may cause Brakeman to miss some vulnerabilities.
By default, Brakeman will return a non-zero exit code if any security warnings are found or scanning errors are encountered. To disable this:
brakeman --no-exit-on-warn --no-exit-on-errorTo skip certain files or directories that Brakeman may have trouble parsing, use:
brakeman --skip-files file1,/path1/,path2/To compare results of a scan with a previous scan, use the JSON output option and then:
brakeman --compare old_report.jsonThis will output JSON with two lists: one of fixed warnings and one of new warnings.
Brakeman will ignore warnings if configured to do so. By default, it looks for a configuration file in config/brakeman.ignore.
To create and manage this file, use:
brakeman -IIf you want to temporarily see the warnings you ignored without affecting the exit code, use:
brakeman --show-ignoredSee warning_types for more information on the warnings reported by this tool.
The HTML output format provides an excerpt from the original application source where a warning was triggered. Due to the processing done while looking for vulnerabilities, the source may not resemble the reported warning and reported line numbers may be slightly off. However, the context still provides a quick look into the code which raised the warning.
Brakeman assigns a confidence level to each warning. This provides a rough estimate of how certain the tool is that a given warning is actually a problem. Naturally, these ratings should not be taken as absolute truth.
There are three levels of confidence:
To only get warnings above a given confidence level:
brakeman -w3The -w switch takes a number from 1 to 3, with 1 being low (all warnings) and 3 being high (only highest confidence warnings).
Brakeman options can be stored and read from YAML files.
To simplify the process of writing a configuration file, the -C option will output the currently set options:
$ brakeman -C --skip-files plugins/
---
:skip_files:
- plugins/Options passed in on the commandline have priority over configuration files.
The default config locations are ./config/brakeman.yml, ~/.brakeman/config.yml, and /etc/brakeman/config.yml
The -c option can be used to specify a configuration file to use.
There is a plugin available for Jenkins/Hudson.
For even more continuous testing, try the Guard plugin.
There are a couple GitHub Actions available.
git clone git://github.com/presidentbeef/brakeman.git
cd brakeman
gem build brakeman.gemspec
gem install brakeman*.gemWebsite: http://brakemanscanner.org/
Twitter: https://twitter.com/brakeman
Chat: https://gitter.im/presidentbeef/brakeman
Brakeman is free for non-commercial use.
See COPYING for details.
request: strong params checks for id (key) columns
Add warnings for dangerous content security policy settings autogenerated by Rails
Unscoped Find should exclude only if all belongs_to associations are optional
False Positive: Regexp containing an escaped $ is marked unsafe
False positive: `HAML::AttributeBuilder.build_class` incorrectly flagged as XSS
Parallelise index_call_sites and process_libs: ~75% of scan time is single-threaded on large apps
Poor performance processing repeated conditional reassignments
Support reading config from ignore file
Hash lookup on frozen constant should untaint the result
UnsafeReflection requires array to be defined with values strictly in the context of the execution