README.md 5.7 KB
Newer Older
J
Justin 已提交
1 2 3 4
# Brakeman

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

J
Justin Collins 已提交
5 6 7
It targets Rails versions 2.x and 3.x.
 
There is also a [plugin available](http://brakemanscanner.org/docs/jenkins/) for Jenkins/Hudson.
8

J
Justin Collins 已提交
9
For even more continuous testing, try the [Guard plugin](https://github.com/oreoshake/guard-brakeman).
J
Justin Collins 已提交
10

J
Justin Collins 已提交
11 12 13
# Homepage/News

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

J
Justin Collins 已提交
15
Twitter: http://twitter.com/brakeman
J
Justin Collins 已提交
16

J
Justin Collins 已提交
17
Mailing list: brakeman@librelist.com
J
Justin Collins 已提交
18

J
Justin 已提交
19 20
# Installation

J
Justin 已提交
21 22 23 24 25 26
Using RubyGems:

    gem install brakeman

From source:

J
Justin 已提交
27 28 29 30 31
    gem build brakeman.gemspec
    gem install brakeman*.gem

# Usage

32 33
    brakeman [app_path]

34
It is simplest to run Brakeman from the root directory of the Rails application. A path may also be supplied.
J
Justin 已提交
35 36 37 38 39

# Options

To specify an output file for the results:

40
    brakeman -o output_file
J
Justin 已提交
41

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

To suppress informational warnings and just output the report:

46
    brakeman -q
J
Justin 已提交
47 48 49

To see all kinds of debugging information:

50
    brakeman -d
J
Justin 已提交
51 52 53

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

54
    brakeman -x DefaultRoutes
J
Justin 已提交
55 56 57

Multiple checks should be separated by a comma:

58
    brakeman -x DefaultRoutes,Redirect
J
Justin 已提交
59 60 61

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

62
    brakeman -t SQL,ValidationRegex
J
Justin 已提交
63 64 65

To indicate certain methods are "safe":

66
    brakeman -s benign_method,totally_safe
J
Justin 已提交
67

J
Justin Collins 已提交
68
By default, brakeman will assume that unknown methods involving untrusted data are dangerous. For example, this would cause a warning (Rails 2):
J
Justin 已提交
69 70 71 72 73

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

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

74
    brakeman -r
J
Justin 已提交
75

76 77 78 79 80 81 82 83 84 85
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 已提交
86 87 88 89 90 91
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 已提交
92
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 已提交
93 94 95

    brakeman -z

J
Justin Collins 已提交
96 97 98 99 100 101 102 103
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 已提交
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
# Warning information

See WARNING_TYPES for more information on the warnings reported by this tool.

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

124
    brakeman -w3
J
Justin 已提交
125

J
Justin Collins 已提交
126
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 已提交
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141

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

The default config locations are `./config.yaml`, `~/.brakeman/`, and `/etc/brakeman/config.yaml`

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

# License

The MIT License

J
Justin Collins 已提交
142
Copyright (c) 2010-2012, YELLOWPAGES.COM, LLC
J
Justin 已提交
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.