Brakeman - Rails Security Scanner

Static analysis security scanner for Ruby on Rails

Brakeman 3.5.0 Released

Changes since 3.4.1:

  • Warn about SQL injection even if target is not known ActiveRecord model
  • Avoid warning about models as SQL injection (#655, #680, #833)
  • Avoid warning about SQLi in all, first, or last after Rails 4.0
  • Treat templates without .html as HTML anyway (#790)
  • Report check name in JSON and plain reports (#971)
  • Add --ensure-latest option (tamgrosser / Michael Grosser)
  • Add --no-summary to hide summaries in HTML/text reports (#963)
  • Fail on invalid checks specified by -x or -t (#970)
  • Handle included block in concerns (#958)
  • Updated RubyParser/Ruby2Ruby dependencies

SQL Injection Improvements

This release includes several changes to the SQL Injection check.

First, Brakeman will no longer restrict SQL injection warnings to calls on known ActiveRecord models. While this may lead to a few false positives, there were too many reports of obvious SQL injection being missed. This reverses a decision made previously. Warnings that may involve non-models are given a lower confidence.

Next, SQL that includes calls on model targets will no longer generate warnings. There were too many false positives and no known vulnerabilities flagged by this.

Finally, Brakeman will no longer check calls to all, first, and last as they changed in Rails 4.1.

(changes)

Extensionless Templates

Templates which do not specify any extension (e.g. just .erb instead of .html.erb) will still be treated as HTML instead of being ignored.

(changes)

Check Name in Reports

The plain and JSON reports now include the name of the check that generated the warning.

(changes)

Option to Enforce Latest Brakeman

The --ensure-latest option has been added. If there is a newer version of Brakeman available, this option will cause Brakeman to exit with a non-zero exit code.

(changes)

Option to Hide Summary

When using --no-summary and either the plain or “table” output, Brakeman will only report warnings, no metadata. Probably most useful in combination with --quiet.

(changes)

Fail on Invalid Checks

When use -t or -x to control which checks are run, Brakeman will now fail if the options supplied do not match existing check names. -t None may be used to avoid running any checks.

(changes)

Handle Included Concerns

Brakeman will now handle the included block in Concerns. Additionally, to support this, Concerns are processed prior to other classes.

(changes)

Checksums

The SHA256 sums for this release are:

49fd8b3e6c1f348304bdbfc3b5d4cfbd465a5b5d4feec8337bbe3df7836787be  brakeman-3.5.0.gem
2ef50a61ca4aa1cff1f28dfe6308ea53157d996975519f5ae5c9266bf5772fb0  brakeman-min-3.5.0.gem
766c9da778e3be36ca709e637276f090514dbc0ddde5e261a1baff6da351480e  brakeman-lib-3.5.0.gem

Reporting Issues

Thank you to everyone who reported bugs and contributed to this release.

Please report any issues with this release! Take a look at this guide to reporting Brakeman problems.

Also consider following @brakeman on Twitter and hanging out on Gitter for questions and discussion.

Brakeman 3.4.1 Released

  • Configurable engines path (Jason Yeo)
  • Check CSRF setting in direct subclasses of ActionController::Base (Jason Yeo)
  • Pull Ruby version from .ruby-version or Gemfile
  • Use Ruby version to turn off SymbolDoS check (#928)
  • Fix ignoring link interpolation not at beginning of string (#939)
  • Show action help at start of interactive ignore (#949)
  • Avoid warning about where_values_hash in SQLi (#942)

Engine Paths Option

Thanks to the work of Jason Yeo, Brakeman now supports custom paths to Rails engines uses the --add-engines-path option.

Multiple comma-separated paths may be configured. To include all subdirectories, use * (e.g. my_engines/*). Absolute paths may be used for engines outside the application.

(changes)

Expanded CSRF Check

Also thanks to Jason Yeo, any controller with ActionController::Base as a direct parent will be checked for a protect_from_forgery call.

(changes)

Ruby Version Info

Brakeman will now pull information about the Ruby version used for an application either from the Gemfile or .ruby-version. Right now this is only used for disabling (the already optional) Symbol DoS check for versions of Ruby that have symbol garbage collection.

(changes)

Link Interpolation False Positive

Brakeman’s warning about interpolating user input into URLs has always checked to see if the interpolation was at the beginning of the string. However, that check didn’t work if the first thing in the string was another interpolation. This has been fixed.

(changes)

More Help in Interactive Ignore

For clarity, “interactive ignore” mode will now display the action options before going through each warning.

image

(changes)

Reporting Issues

Thank you to everyone who reported bugs and contributed to this release.

Please report any issues with this release! Take a look at this guide to reporting Brakeman problems.

Also consider following @brakeman on Twitter and hanging out on Gitter for questions and discussion.

Brakeman 3.4.0 Released

Changes since 3.3.5:

  • Show obsolete ignore entries in reports (Jonathan Cheatham)
  • Add option to prune ignore file with -I
  • Add new plain report format (#914)
  • Support creating reports in non-existent paths (#924)
  • Add --no-exit-warn (#925)
  • Improved Slim template support

Obsolete Ignore Entries

The “ignore” configuration file can sometimes grow large due to stale entries that no longer correspond to existing warnings. Thanks to Jonathan Cheatham, these obsolete entires will now be noted in the default and JSON reports.

(changes)

When using the -I option it is now possible to prune the ignore file.

image

image

(changes)

New Report Format

This release adds a new “plain text” report format. It will eventually replace the default “table” report in Brakeman 4.0.

image

To output in the new format, use -f plain or -o report.plain.

The color codes should be disabled automatically if outputing to a file, but --no-color can be used to turn colors off.

Feedback on the new report format is encouraged prior to the 4.0 release.

(changes)

Report Paths

If the specified output file is in a non-existent path, Brakeman will now attempt to create the path before writing out the report.

(changes)

No Exit Code on Warnings

--no-exit-warn has been added to complement --exit-warn.

(changes)

Improved Slim Support

Most users will not notice any changes, but internally Slim templates are handled a bit better.

(changes and more)

SHAs

The SHA256 sums for this release are

0cfd4b9cb8515ed9cbd254710761bfc409c604f3351e200b22955a1c3f93f8d8  brakeman-3.4.0.gem
7d07d87aa0732465bb6f0c17279f78edcfd0b1d841ddb63a95529ba762841395  brakeman-min-3.4.0.gem
e3d61c1de5549984a0d9eb3a3a53a4ef17b1b41db1be7d504237dd05a0cfa203  brakeman-lib-3.4.0.gem

Reporting Issues

Thank you to everyone who reported bugs.

Please report any issues with this release! Take a look at this guide to reporting Brakeman problems.

Also consider following @brakeman on Twitter and hanging out on Gitter for questions and discussion.

Brakeman 3.3.4/3.3.5 Released

This is a quick release to add warnings for CVE-2016-6316 and CVE-2016-6317. There was a bug in 3.3.4 that affected debug output which has been fixed in 3.3.5.

Changes since 3.3.3:

  • Add generic warning for CVE-2016-6316
  • Warn about dangerous use of content_tag with CVE-2016-6316
  • Add warning for CVE-2016-6317
  • Use Minitest

Changes since 3.3.4:

  • Fix bug in reports when using --debug

CVE-2016-6316

Typically Rails will escape attribute values passed to tag helpers like content_tag. If the attribute has already been marked as “safe” with .html_safe or (more likely) a different escaping helper like sanitize, the tag helper will not escape the value again (that is the purpose of .html_safe). However, not all sanitizers/escape methods escape double quotes, which are dangerous inside of tag attributes. In particular, double quotes allow an attacker to close the current attribute and insert new attributes (like onmouseover) that can execute JavaScript.

Brakeman will issue a generic warning about CVE-2016-6316 for affected versions and may generate warnings for potentially dangerous calls to content_tag.

(changes)

CVE-2016-6317

The JSON bug is back. Specially-crafted queries can cause parameters to be interpreted as empty hashes, which may cause unexpected behavior in SQL queries.

Brakeman will generate a generic warning for affected versions (4.2 series).

(changes)

Minitest

Unrelated, Brakeman now uses Minitest instead of test-unit.

(changes)

SHAs

The SHA256 sums for this release are

7231e00bdb4353ee7e91e5f1e60e34cf29b5563e6f7e1e5478223e72568c493a  brakeman-3.3.5.gem
c07e282c2e1733f8d7db4a4ffefe22e7e38a62ddfd750f0866c0b49070cb61c9  brakeman-lib-3.3.5.gem
a7f8e6fa8eb4254b7ad17080180289794a02641b1f2ec362de57cfdb2f1535be  brakeman-min-3.3.5.gem

Reporting Issues

Thank you to everyone who reported bugs.

Please report any issues with this release! Take a look at this guide to reporting Brakeman problems.

Also consider following @brakeman on Twitter and hanging out on Gitter for questions and discussion.

Brakeman 3.3.3 Released

This release is mostly bug fixes and internal improvements, although it may find more warnings due to indexing of view helpers.

  • Index calls in view helpers
  • Process inline template renders (#672)
  • Show path when no Rails app found (Neil Matatall)
  • Avoid warning about hashes in link_to hrefs (#897)
  • Improve return value guesses
  • Ignore boolean methods in render paths
  • Reduce open redirect duplicates
  • Fix SymbolDoS error with unknown Rails version

View Helpers

Calls in view helpers are now indexed, which means Brakeman will search them for potential vulnerabilities.

(changes)

Inline Templates

Brakeman will now process inline templates in controllers, if they are using ERB (the default):

render :inline => "<%= params[:x].html_safe %>"

(changes)

Rails App Path

Thanks to Neil Matatall, Brakeman will now display the path it tried to search for a Rails application if it cannot find it:

Please supply the path to a Rails application (looking in /some/path/).

(changes)

Hashes as URLs

Brakeman will no longer warn about obvious hash arguments in the HREF for link_to calls, as well as handling url_for better.

(changes)

Return Values

In some cases, Brakeman attempts to determine the possible return value(s) of a method call. This release includes a number of improvements to those guesses which may make some warnings easier to understand and fix some false positives.

(changes)

Render Path Booleans

The check for dynamic render paths will no longer warn about methods ending in ?.

(changes)

Redirect Duplicates

This release refactored much of the warning duplicate tracking, and as such there should be fewer duplicate warnings about open redirects.

(changes)

SHAs

The SHA256 sums for this release are

490bf7b47d4edbb29fd3f87c5dafa50aec2888d495b64275a635df324a8476e9  brakeman-3.3.3.gem
793f1c69cca2681bdd0c98f11307ace4f1a43ed594dd45cbe5b67f0383e76e2f  brakeman-lib-3.3.3.gem
dcc3a75b12f84cac582d383a375d3b85d033e25ba42af051bedcdc8b5377c2c5  brakeman-min-3.3.3.gem

Reporting Issues

Thank you to everyone who reported bugs and contributed improvements in this release.

Please report any issues with this release! Take a look at this guide to reporting Brakeman problems.

Also consider following @brakeman on Twitter and hanging out on Gitter for questions and discussion.

Brakeman 3.3.2 Released

This is a bug fix release.

Changes since 3.3.2:

  • Fix performance regression in global constant tracking

Brakeman 3.3.0 introduced a new feature to track constant values across the application. This helped reduce false positives, for example when checking a value against a constant array of values. However, the lookup of constant values was very slow for moderate to large numbers of constants. In some test cases it added up to a minute of scan time. This has been resolved along with some changes to how dynamic constant names are handled.

Additionally, the --faster option will turn off global constant tracking entirely.

(changes)

SHAs

The SHA256 sums for this release are

58bb2179de2bd479d32dc2d2018e40caf478916e283ea88089fe0bcb30a55e6c  brakeman-3.3.2.gem
4f72ff02a163d78244554c4a26ea35e88d76dd6b60c3d21573db8518abcba6fc  brakeman-min-3.3.2.gem
c0beeabe95aa693a5273bd48922028f48a190940b18c795813bd0f96068452b4  brakeman-lib-3.3.2.gem

Reporting Issues

Thank you to the reporters of the performance issue in the 3.3.0 release.

Please report any issues with this release! Take a look at this guide to reporting Brakeman problems.

Also consider following @brakeman on Twitter and hanging out on Gitter for questions and discussion.

For commercial support, please consider Brakeman Pro.

Brakeman 3.3.1 Released

Changes since 3.3.1:

  • Improved line number accuracy in ERB templates (Patrick Toomey)
  • Allow multiple line regex in validates_format_of (Dmitrij Fedorenko)
  • Avoid overwriting instance/class methods with same name (Tim Wade)
  • Add --force-scan option (Neil Matatall)
  • Only consider if branches in templates
  • Support more safe &. operations
  • Avoid warning about SQL injection with quoted_primary_key (#884)
  • Delay loading vendored gems and modifying load path
  • Added brakeman-lib gem

ERB Template Line Numbers

Patrick Toomey contributed a series of patches to bring Brakeman’s handling of ERB/Erubis templates in line with the Rails implementation. This has the effect of correcting some line numbers and fixed processing of case statements in templates.

(changes)

Multiline Regex Validation

Dmitrij Fedorenko added a change to support multiline extended regular expressions for model validations.

(changes)

Class Methods

Tim Wade fixed an issue where class methods and instance methods with the same name on the same class would overwrite each other. This may cause a few warning fingerprints to change, since all method names are now stored as symbols (some were strings before).

(changes)

Force Scan

Neil Matatall added the --force-scan option to force Brakeman to scan an application even if it doesn’t look like a Rails app.

(changes)

Branches in Templates

When looking at template output, Brakeman will no longer treat the conditional as output, just the branches. This helps find more potential instances of cross-site scripting.

For example:

<%= params[:x].html_safe unless this_is_a_bad_idea? %>

Now Brakeman will just consider the params[:x].html_safe value which is clearly dangerous.

(changes)

More Safe Calls

Brakeman can now handle more instances of the “safe call” or “lonely” operator such as a&.b ||= 1 and x&.y += z 1.

(changes)

Quoted Primary Key

Brakeman will no longer warn about use of quoted_primary_key in SQL strings.

(changes)

Delayed Load Path Modification

Brakeman 3.3.0 started vendoring all its dependencies to avoid conflicts with application dependencies. However, if Brakeman is included in a Gemfile without require: false, it will still modify the load path and potentially cause conflicts.

This version delays loading any dependencies until Brakeman actually runs. This is almost like having require: false automatically.

Please keep in mind it is really not recommended to include Brakeman in Gemfiles unless it is actually being used as a library. Otherwise it’s like mixing your browser’s dependencies with your applications. It doesn’t make sense.

(changes)

brakeman-lib

For those who don’t want Brakeman to bundle and vendor its own dependencies, the brakeman-lib gem is identical to the brakeman gem but without the bundling. Consider using it if the bundling and modified load paths are causing issues.

(changes)

RailsConf Security Talks

Justin Collins gave a lightning talk about Brakeman and a regular talk about real-world examples of vulnerabilities Rails won’t save you from.

Mike Milner spoke about the security breaches of 2015.

Jessica Rudder talked through examples of SQL injection in ActiveRecord.

SHAs

The SHA256 sums for this release are

5c22721c8b486fa9d283cabf65c7e77b2f7428056d4d907b7f74a91dd112616a  brakeman-3.3.1.gem
7aa57ed8b42c0cadef09214f5544424659ab3972912137fad37da1a052d8a792  brakeman-lib-3.3.1.gem
95e68202493d8c504ad72276c8bfa46abb1c78c309bc2b80b433a6220f3722eb  brakeman-min-3.3.1.gem

Reporting Issues

Thank you to everyone who reported bugs and contributed improvements in this release.

Please report any issues with this release! Take a look at this guide to reporting Brakeman problems.

Also consider following @brakeman on Twitter and hanging out on Gitter for questions and discussion. Please note the mailing list is no longer in use and has apparently not been delivering mail for some time.

Brakeman 3.3.0 Released

Brakeman 3.3.0 introduces a new packaging method for Brakeman which vendors all dependencies and does not include any gem dependencies in the gemspec. Please test and provide feedback if it does not work as expected.

Changes since 3.2.1:

  • Bundle all dependencies in gem
  • Return exit code 4 if no Rails application is detected (#869)
  • Add optional check for secrets in source code (#201)
  • Track constants globally
  • Skip if branches with Rails.env.test? (#862)
  • Skip processing obviously false if branches (more broadly)
  • Handle HAML find_and_preserve with a block (#837)
  • Process Array#first
  • Allow non-Hash arguments in protect_from_forgery (Jason Yeo)
  • Avoid warning about u helper (Chad Dollins)
  • Avoid warning about mass assignment and SQL injection with params.slice (#866)
  • Avoid warning about slice in redirect_to and link_to (#832)
  • Avoid warning on popen with array (#851)
  • [Code Climate engine] When possible, output to /dev/stdout (Gordon Diggs)
  • [Code Climate engine] Remove nil entries from include_paths (Gordon Diggs)
  • [Code Climate engine] Report end lines for issues (Gordon Diggs)

Dependency Bundling

In its gem form, Brakeman no longer declares any external dependencies. Its dependencies are bundled with the gem itself. This should prevent the conflicts which sometimes occur when Brakeman is declared as a dependency of a Rails application. The disadvantage is you will no longer be able to update Brakeman dependencies (like RubyParser) without updating Brakeman itself.

As this is a new way of distributing Brakeman, please report any issues that may arise.

(changes)

New Exit Code

A new exit code has been added for the case when Brakeman does not detect a Rails application.

For reference, these are Brakeman’s current exit codes:

  • 0 - Normal exit
  • 3 - Warnings found (with -z)
  • 4 - No Rails application detected
  • 255 - Error

(changes)

Secrets Check

A new optional check has been added to look for hard-coded secrets in the source code. It will warn when constants like PASSWORD are assigned string literals. To run the new check, use -t Secrets or -A to run all checks including optional ones.

(changes)

Constant Values

This release includes initial support for tracking and matching constants across the application. For example, if a model contains a constant Model::KEYS which is used elsewhere, Brakeman should be able to track this value. This helps prevents false positives when safe values have been declared as constants.

(changes)

Skipping Test Code

Brakeman will now ignore if branches that check Rails.env.test?. Additionally, branch skipping behavior (e.g. if false...) has been expanded to most of Brakeman’s processing instead of just in data flow analysis.

(changes)

HAML find_and_preserve

Brakeman will now handle uses of find_and_preserve in HAML with a block.

(changes)

Array#first

Calls to Array#first will be replaced with the first value in the array when known.

(changes)

Forgery Option

Jason Yeo provided a fix for when Brakeman encounters a non-Hash argument to protect_from_forgery.

(changes)

u Helper

Chad Dollins fixed XSS false positives when the u alias for url_encode is used.

(changes)

Fewer slice False Positives

Brakeman should no longer warn when using params.slice in mass assignment, SQL injection, links, and open redirects.

(changes and other changes)

Safe popen

Brakeman will no longer warn about uses of popen when the argument is an array, in which case the arguments are escaped.

(changes)

Code Climate Engine

Gordon Diggs provided several improvements to the Code Climate Engine in this release:

  • Remove nil entries from the include_paths option
  • Force output to stdout when possible
  • Report end lines to conform with spec

SHAs

The SHA256 sums for this release are

c01ec64d35218887fc5ea2ae8babc88e9e0e7cc3c161b020725d2b17c4189858  brakeman-3.3.0.gem
f1adce1a696799342dc9f50b51975024060360dc9018358c5d8e34c1c4681bd1  brakeman-min-3.3.0.gem

Reporting Issues

Thank you to everyone who reported bugs and contributed improvements in this release.

Please report any issues with this release! Take a look at this guide to reporting Brakeman problems.

Also consider following @brakeman on Twitter and hanging out on Gitter for questions and discussion. Please note the mailing list is no longer in use and has apparently not been delivering mail for some time.

Brakeman 3.2.1 Released

Changes since 3.2.0:

  • Remove multi_json dependency from bin/brakeman

As pointed out by Benjamin Fleischer, there was a lingering use of multi_json in bin/brakeman. This only caused a problem when using the --compare option.

(changes)

SHAs

The SHA256 sums for this release are

4a7e7a6e9ad9fed22f727fb8d471de145f55d97465b4dfb4935e3e8379667425  brakeman-min-3.2.1.gem
901202b04b1cae0a781b5a6bae2db3eecd35e9f0a044fbfaa31cac63ab636449  brakeman-3.2.1.gem

Reporting Issues

Please report any issues with this release! Take a look at this guide to reporting Brakeman problems.

Also consider following @brakeman on Twitter and hanging out on Gitter for questions and discussion. Please note the mailing list is no longer in use and has apparently not been delivering mail for some time.

Brakeman 3.2.0 Released

This release sheds a couple dependencies and adds support for new Ruby 2.3 syntax.

Changes since 3.1.5:

  • Support calls using &. operator (#796)
  • Handle CoffeeScript in HAML (#813)
  • Avoid render warnings about params[:action]/params[:controller] (#812)
  • Only update ignore config file on changes (#824)
  • Sort ignore config file
  • Index calls in class bodies but outside methods (#814)
  • Skip Symbol DoS check on Rails 5
  • Fix finding calls with targets: nil
  • Remove fastercsv dependency
  • Remove multi-json dependecy

Ruby 2.3 Lonely Operator

With the update of RubyParser to 3.8.1 (and Ruby2Ruby to 2.3), Brakeman now supports the new &. operator and should treat it like a regular method call.

(changes)

CoffeeScript in HAML

This release handles CoffeeScript embedded in HAML better and should reduce some false positives.

(changes)

Render Warnings on Safe Parameters

Brakeman will no longer warn on render params[:action] or render params[:controller], as those values are not able to be controlled by an attacker.

(changes)

‘Ignore’ Configuration Changes

The “ignore config” files generated by Brakeman are now sorted and will only update on changes, instead of always writing a new file.

(changes)

Index Calls Outside Methods

Calls that are outside methods (but inside class bodies) can now be found in Brakeman checks.

(changes)

Skip Symbol DoS with Rails 5

Rails 5 requires Ruby >= 2.2.2, which now garbage collects symbols. If the SymbolDoS check is run on a Rails 5 application (it’s already optional), it will no longer warn.

(changes)

Dependency Removal

Since Ruby 1.8 is no longer supported, this release removes the legacy fastercsv and multi-json dependencies.

(fastercsv, multi-json)

SHAs

The SHA256 sums for this release are

d1d1468fcca0ec5dd99c53af2018b781a8efe06483190aef9d13b1abcbb7e2a0  brakeman-min-3.2.0.gem
07023148564668cc39911eec0354ca03774be1f8a03d66162f53a5dde44bb502  brakeman-3.2.0.gem

Reporting Issues

Thank you to everyone who reported bugs and contributed improvements in this release.

Please report any issues with this release! Take a look at this guide to reporting Brakeman problems.

Also consider following @brakeman on Twitter and hanging out on Gitter for questions and discussion. Please note the mailing list is no longer in use and has apparently not been delivering mail for some time.