README.md 5.7 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 12 13
# Brakeman

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

# Installation

J
Justin 已提交
14 15 16 17
Using RubyGems:

    gem install brakeman

18
Using Bundler:
19 20 21 22 23

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

24
# Usage
J
Justin 已提交
25

26
From a Rails application's root directory:
27

28
    brakeman
29

30
Outside of Rails root:
31

32
    brakeman /path/to/rails/application
J
Justin 已提交
33

34
# Compatibility
35

36
Brakeman works with Rails 2.x, 3.x, and 4.x.
J
Justin 已提交
37

38 39 40
# Basic Options

For a full list of options, use `brakeman --help` or see the OPTIONS.md file.
J
Justin 已提交
41 42 43

To specify an output file for the results:

44
    brakeman -o output_file
J
Justin 已提交
45

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

J
Justin Collins 已提交
48 49 50 51
Multiple output files can be specified:

    brakeman -o output.html -o output.json

J
Justin 已提交
52 53
To suppress informational warnings and just output the report:

54
    brakeman -q
J
Justin 已提交
55

56 57
Note all Brakeman output except reports are sent to stderr, making it simple to redirect stdout to a file and just get the report.

J
Justin 已提交
58 59
To see all kinds of debugging information:

60
    brakeman -d
J
Justin 已提交
61 62 63

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

64
    brakeman -x DefaultRoutes
J
Justin 已提交
65 66 67

Multiple checks should be separated by a comma:

68
    brakeman -x DefaultRoutes,Redirect
J
Justin 已提交
69 70 71

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

72
    brakeman -t SQL,ValidationRegex
J
Justin 已提交
73

J
Justin 已提交
74 75 76 77 78 79
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 已提交
80
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 已提交
81 82 83

    brakeman -z

J
Justin Collins 已提交
84 85 86 87
To skip certain files that Brakeman may have trouble parsing, use:

    brakeman --skip-files file1,file2,etc

J
Justin Collins 已提交
88 89 90 91 92 93
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 已提交
94 95 96 97 98
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 已提交
99 100
# Warning information

J
Justin Collins 已提交
101
See WARNING\_TYPES for more information on the warnings reported by this tool.
J
Justin 已提交
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118

# 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:

119
    brakeman -w3
J
Justin 已提交
120

J
Justin Collins 已提交
121
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 已提交
122 123 124 125 126 127 128

# 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 已提交
129
The default config locations are `./config/brakeman.yml`, `~/.brakeman/config.yml`, and `/etc/brakeman/config.yml`
J
Justin 已提交
130 131 132

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

133 134 135 136 137 138 139 140 141 142 143
# For Slim Users

[Slim v3.0.0](https://github.com/slim-template/slim/blob/master/CHANGES#L12) dropped support for Ruby 1.8.7. Install a version of [`slim`](http://slim-lang.com/) compatible with your Ruby.

| Ruby Version |       `Gemfile`       |              Command Line              |
|--------------|-----------------------|----------------------------------------|
| Ruby 1.8.7   | `gem 'slim', '< 3.0'` | `$ gem install slim --version '< 3.0'` |
| Ruby 1.9+    | `gem 'slim'`          | `$ gem install slim`                   |

# Continuous Integration

144
There is a [plugin available](http://brakemanscanner.org/docs/jenkins/) for Jenkins/Hudson.
145 146 147 148 149

For even more continuous testing, try the [Guard plugin](https://github.com/guard/guard-brakeman).

# Building

D
David Lanner 已提交
150 151
    git clone git://github.com/presidentbeef/brakeman.git
    cd brakeman
152 153 154 155 156 157 158 159 160 161 162
    gem build brakeman.gemspec
    gem install brakeman*.gem

# Homepage/News

Website: http://brakemanscanner.org/

Twitter: http://twitter.com/brakeman

Mailing list: brakeman@librelist.com

J
Justin Collins 已提交
163 164 165 166 167 168 169 170
# 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/)

171
[..and more!](http://brakemanscanner.org/brakeman_users)
J
Justin Collins 已提交
172

J
Justin Collins 已提交
173 174
# License

D
David Lanner 已提交
175
see [MIT-LICENSE](MIT-LICENSE)