Module: Brakeman::Options
- Defined in:
- lib/brakeman/options.rb
Overview
Parses command line arguments for Brakeman
Class Method Summary collapse
-
.get_options(args, destructive = false) ⇒ Object
Return hash of options and the parser.
-
.parse(args) ⇒ Object
Parse argument array.
-
.parse!(args) ⇒ Object
Parse arguments and remove them from the array as they are matched.
Class Method Details
.get_options(args, destructive = false) ⇒ Object
Return hash of options and the parser
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 |
# File 'lib/brakeman/options.rb', line 20 def args, destructive = false = {} parser = OptionParser.new do |opts| opts. = "Usage: brakeman [options] rails/root/path" opts.on "-n", "--no-threads", "Run checks sequentially" do [:parallel_checks] = false end opts.on "--[no-]progress", "Show progress reports" do |progress| [:report_progress] = progress end opts.on "-p", "--path PATH", "Specify path to Rails application" do |path| [:app_path] = path end opts.on "-q", "--[no-]quiet", "Suppress informational messages" do |quiet| [:quiet] = quiet end opts.on( "-z", "--exit-on-warn", "Exit code is non-zero if warnings found") do [:exit_on_warn] = true end opts.on "-3", "--rails3", "Force Rails 3 mode" do [:rails3] = true end opts.on "-4", "--rails4", "Force Rails 4 mode" do [:rails3] = true [:rails4] = true end opts.separator "" opts.separator "Scanning options:" opts.on "-A", "--run-all-checks", "Run all default and optional checks" do [:run_all_checks] = true end opts.on "-a", "--[no-]assume-routes", "Assume all controller methods are actions (default)" do |assume| [:assume_all_routes] = assume end opts.on "-e", "--escape-html", "Escape HTML by default" do [:escape_html] = true end opts.on "--faster", "Faster, but less accurate scan" do [:ignore_ifs] = true [:skip_libs] = true end opts.on "--ignore-model-output", "Consider model attributes XSS-safe" do [:ignore_model_output] = true end opts.on "--ignore-protected", "Consider models with attr_protected safe" do [:ignore_attr_protected] = true end opts.on "--[no-]index-libs", "Add libraries to call index (default)" do |index| [:index_libs] = index end opts.on "--interprocedural", "Process method calls to known methods" do [:interprocedural] = true end opts.on "--no-branching", "Disable flow sensitivity on conditionals" do [:ignore_ifs] = true end opts.on "--branch-limit LIMIT", Integer, "Limit depth of values in branches (-1 for no limit)" do |limit| [:branch_limit] = limit end opts.on "-r", "--report-direct", "Only report direct use of untrusted data" do |option| [:check_arguments] = !option end opts.on "-s", "--safe-methods meth1,meth2,etc", Array, "Set methods as safe for unescaped output in views" do |methods| [:safe_methods] ||= Set.new [:safe_methods].merge methods.map {|e| e.to_sym } end opts.on "--url-safe-methods method1,method2,etc", Array, "Do not warn of XSS if the link_to href parameter is wrapped in a safe method" do |methods| [:url_safe_methods] ||= Set.new [:url_safe_methods].merge methods.map {|e| e.to_sym } end opts.on "--skip-files file1,file2,etc", Array, "Skip processing of these files" do |files| [:skip_files] ||= Set.new [:skip_files].merge files end opts.on "--only-files file1,file2,etc", Array, "Process only these files" do |files| [:only_files] ||= Set.new [:only_files].merge files end opts.on "--skip-libs", "Skip processing lib directory" do [:skip_libs] = true end opts.on "--add-libs-path path1,path2,etc", Array, "An application relative lib directory (ex. app/mailers) to process" do |paths| [:additional_libs_path] ||= Set.new [:additional_libs_path].merge paths end opts.on "-t", "--test Check1,Check2,etc", Array, "Only run the specified checks" do |checks| checks.each_with_index do |s, index| if s[0,5] != "Check" checks[index] = "Check" << s end end [:run_checks] ||= Set.new [:run_checks].merge checks end opts.on "-x", "--except Check1,Check2,etc", Array, "Skip the specified checks" do |skip| skip.each do |s| if s[0,5] != "Check" s = "Check" << s end [:skip_checks] ||= Set.new [:skip_checks] << s end end opts.on "--add-checks-path path1,path2,etc", Array, "A directory containing additional out-of-tree checks to run" do |paths| [:additional_checks_path] ||= Set.new [:additional_checks_path].merge paths.map {|p| File. p} end opts.separator "" opts.separator "Output options:" opts.on "-d", "--debug", "Lots of output" do [:debug] = true end opts.on "-f", "--format TYPE", [:pdf, :text, :html, :csv, :tabs, :json, :markdown, :codeclimate, :cc], "Specify output formats. Default is text" do |type| type = "s" if type == :text [:output_format] = ("to_" << type.to_s).to_sym end opts.on "--css-file CSSFile", "Specify CSS to use for HTML output" do |file| [:html_style] = File. file end opts.on "-i IGNOREFILE", "--ignore-config IGNOREFILE", "Use configuration to ignore warnings" do |file| [:ignore_file] = file end opts.on "-I", "--interactive-ignore", "Interactively ignore warnings" do [:interactive_ignore] = true end opts.on "-l", "--[no-]combine-locations", "Combine warning locations (Default)" do |combine| [:combine_locations] = combine end opts.on "--[no-]highlights", "Highlight user input in report" do |highlight| [:highlight_user_input] = highlight end opts.on "-m", "--routes", "Report controller information" do [:report_routes] = true end opts.on "--message-limit LENGTH", "Limit message length in HTML report" do |limit| [:message_limit] = limit.to_i end opts.on "--table-width WIDTH", "Limit table width in text report" do |width| [:table_width] = width.to_i end opts.on "-o", "--output FILE", "Specify files for output. Defaults to stdout. Multiple '-o's allowed" do |file| [:output_files] ||= [] [:output_files].push(file) end opts.on "--[no-]separate-models", "Warn on each model without attr_accessible (Default)" do |separate| [:collapse_mass_assignment] = !separate end opts.on "--summary", "Only output summary of warnings" do [:summary_only] = true end opts.on "--absolute-paths", "Output absolute file paths in reports" do [:absolute_paths] = true end opts.on "--github-repo USER/REPO[/PATH][@REF]", "Output links to GitHub in markdown and HTML reports using specified repo" do |repo| [:github_repo] = repo end opts.on "-w", "--confidence-level LEVEL", ["1", "2", "3"], "Set minimal confidence level (1 - 3)" do |level| [:min_confidence] = 3 - level.to_i end opts.on "--compare FILE", "Compare the results of a previous brakeman scan (only JSON is supported)" do |file| [:previous_results_json] = File.(file) end opts.separator "" opts.separator "Configuration files:" opts.on "-c", "--config-file FILE", "Use specified configuration file" do |file| [:config_file] = File.(file) end opts.on "-C", "--create-config [FILE]", "Output configuration file based on options" do |file| if file [:create_config] = file else [:create_config] = true end end opts.separator "" opts.on "-k", "--checks", "List all available vulnerability checks" do [:list_checks] = true end opts.on "--optional-checks", "List optional checks" do [:list_optional_checks] = true end opts.on "--rake", "Create rake task to run Brakeman" do [:install_rake_task] = true end opts.on "-v", "--version", "Show Brakeman version" do [:show_version] = true end opts.on_tail "-h", "--help", "Display this message" do [:show_help] = true end end if destructive parser.parse! args else parser.parse args end if [:previous_results_json] and [:output_files] [:comparison_output_file] = [:output_files].shift end return , parser end |
.parse(args) ⇒ Object
Parse argument array
10 11 12 |
# File 'lib/brakeman/options.rb', line 10 def parse args args end |
.parse!(args) ⇒ Object
Parse arguments and remove them from the array as they are matched
15 16 17 |
# File 'lib/brakeman/options.rb', line 15 def parse! args args, true end |