README.md 5.8 KB
Newer Older
J
Justin Collins 已提交
1 2
![Brakeman Logo](http://brakemanscanner.org/images/logo_medium.png)

3 4 5 6
[![Travis CI
Status](https://secure.travis-ci.org/presidentbeef/brakeman.png)](https://travis-ci.org/presidentbeef/brakeman)
[![Code
Climate](https://codeclimate.com/github/presidentbeef/brakeman.png)](https://codeclimate.com/github/presidentbeef/brakeman)
J
Justin Collins 已提交
7

J
Justin 已提交
8 9 10 11
# Brakeman

Brakeman is a static analysis tool which checks Ruby on Rails applications for security vulnerabilities.

J
Justin Collins 已提交
12
It works with Rails 2.x, 3.x, and 4.x.
13

J
Justin Collins 已提交
14
There is also a [plugin available](http://brakemanscanner.org/docs/jenkins/) for Jenkins/Hudson.
15

P
Philippe Dionne 已提交
16
For even more continuous testing, try the [Guard plugin](https://github.com/guard/guard-brakeman).
J
Justin Collins 已提交
17

J
Justin Collins 已提交
18 19 20
# Homepage/News

Website: http://brakemanscanner.org/
J
Justin Collins 已提交
21

J
Justin Collins 已提交
22
Twitter: http://twitter.com/brakeman
J
Justin Collins 已提交
23

J
Justin Collins 已提交
24
Mailing list: brakeman@librelist.com
J
Justin Collins 已提交
25

J
Justin 已提交
26 27
# Installation

J
Justin 已提交
28 29 30 31
Using RubyGems:

    gem install brakeman

J
Justin Collins 已提交
32
Using Bundler, add to development group in Gemfile and set to not be required automatically:
33 34 35 36 37

    group :development do
      gem 'brakeman', :require => false
    end

J
Justin 已提交
38 39
From source:

J
Justin 已提交
40 41 42 43 44
    gem build brakeman.gemspec
    gem install brakeman*.gem

# Usage

45 46
    brakeman [app_path]

47
It is simplest to run Brakeman from the root directory of the Rails application. A path may also be supplied.
J
Justin 已提交
48 49 50 51 52

# Options

To specify an output file for the results:

53
    brakeman -o output_file
J
Justin 已提交
54

J
Justin Collins 已提交
55
The output format is determined by the file extension or by using the `-f` option. Current options are: `text`, `html`, `tabs`, `json` and `csv`.
J
Justin 已提交
56

J
Justin Collins 已提交
57 58 59 60
Multiple output files can be specified:

    brakeman -o output.html -o output.json

J
Justin 已提交
61 62
To suppress informational warnings and just output the report:

63
    brakeman -q
J
Justin 已提交
64 65 66

To see all kinds of debugging information:

67
    brakeman -d
J
Justin 已提交
68 69 70

Specific checks can be skipped, if desired. The name needs to be the correct case. For example, to skip looking for default routes (`DefaultRoutes`):

71
    brakeman -x DefaultRoutes
J
Justin 已提交
72 73 74

Multiple checks should be separated by a comma:

75
    brakeman -x DefaultRoutes,Redirect
J
Justin 已提交
76 77 78

To do the opposite and only run a certain set of tests:

79
    brakeman -t SQL,ValidationRegex
J
Justin 已提交
80 81 82

To indicate certain methods are "safe":

83
    brakeman -s benign_method,totally_safe
J
Justin 已提交
84

J
Justin Collins 已提交
85
By default, brakeman will assume that unknown methods involving untrusted data are dangerous. For example, this would cause a warning (Rails 2):
J
Justin 已提交
86 87 88 89 90

    <%= some_method(:option => params[:input]) %>

To only raise warnings only when untrusted data is being directly used:

91
    brakeman -r
J
Justin 已提交
92

93 94 95 96 97 98 99 100 101 102
By default, each check will be run in a separate thread. To disable this behavior:

    brakeman -n

Normally Brakeman will parse `routes.rb` and attempt to infer which controller methods are used as actions. However, this is not perfect (especially for Rails 3). To ignore the automatically inferred routes and assume all methods are actions:

    brakeman -a

Note that this will be enabled automatically if Brakeman runs into an error while parsing the routes.

J
Justin 已提交
103 104 105 106 107 108
If Brakeman is running a bit slow, try

    brakeman --faster

This 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.

J
Justin Collins 已提交
109
By default, Brakeman will return 0 as an exit code unless something went very wrong. To return an error code when warnings were found:
J
Justin Collins 已提交
110 111 112

    brakeman -z

J
Justin Collins 已提交
113 114 115 116 117 118 119 120
To skip certain files that Brakeman may have trouble parsing, use:

    brakeman --skip-files file1,file2,etc

Brakeman will raise warnings on models that use `attr_protected`. To suppress these warnings:

    brakeman --ignore-protected

J
Justin Collins 已提交
121 122 123 124 125 126
To compare results of a scan with a previous scan, use the JSON output option and then:

    brakeman --compare old_report.json

This will output JSON with two lists: one of fixed warnings and one of new warnings.

J
Justin Collins 已提交
127 128 129 130 131
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 -I

J
Justin 已提交
132 133
# Warning information

J
Justin Collins 已提交
134
See WARNING\_TYPES for more information on the warnings reported by this tool.
J
Justin 已提交
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151

# Warning context

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.

# Confidence levels

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:

 + High - Either this is a simple warning (boolean value) or user input is very likely being used in unsafe ways.
 + Medium - This generally indicates an unsafe use of a variable, but the variable may or may not be user input.
 + Weak - Typically means user input was indirectly used in a potentially unsafe manner.

To only get warnings above a given confidence level:

152
    brakeman -w3
J
Justin 已提交
153

J
Justin Collins 已提交
154
The `-w` switch takes a number from 1 to 3, with 1 being low (all warnings) and 3 being high (only highest confidence warnings).
J
Justin 已提交
155 156 157 158 159 160 161

# Configuration files

Brakeman options can stored and read from YAML files. To simplify the process of writing a configuration file, the `-C` option will output the currently set options.

Options passed in on the commandline have priority over configuration files.

G
grosser 已提交
162
The default config locations are `./config/brakeman.yml`, `~/.brakeman/config.yml`, and `/etc/brakeman/config.yml`
J
Justin 已提交
163 164 165

The `-c` option can be used to specify a configuration file to use.

J
Justin Collins 已提交
166 167 168 169 170 171 172 173 174 175
# Who is Using Brakeman?

* [Code Climate](https://codeclimate.com/)
* [GitHub](https://github.com/)
* [Groupon](http://www.groupon.com/)
* [New Relic](http://newrelic.com)
* [Twitter](https://twitter.com/)

[..and more!](http://brakeman.org/brakeman_users)

J
Justin Collins 已提交
176 177 178
# License

see MIT-LICENSE