Class: Brakeman::Report::JSON

Inherits:
Base
  • Object
show all
Defined in:
lib/brakeman/report/report_json.rb

Constant Summary

Constants inherited from Base

Base::TEXT_CONFIDENCE

Constants included from Util

Util::ALL_COOKIES, Util::ALL_PARAMETERS, Util::COOKIES, Util::COOKIES_SEXP, Util::PARAMETERS, Util::PARAMS_SEXP, Util::PATH_PARAMETERS, Util::QUERY_PARAMETERS, Util::REQUEST_COOKIES, Util::REQUEST_ENV, Util::REQUEST_PARAMETERS, Util::REQUEST_PARAMS, Util::REQUEST_REQUEST_PARAMETERS, Util::SAFE_LITERAL, Util::SESSION, Util::SESSION_SEXP

Instance Attribute Summary

Attributes inherited from Base

#checks, #tracker

Instance Method Summary collapse

Methods inherited from Base

#absolute_paths?, #all_warnings, #context_for, #controller_information, #controller_warnings, #filter_warnings, #generic_warnings, #github_url, #ignored_warnings, #initialize, #model_warnings, #number_of_templates, #rails_version, #template_warnings, #warning_file, #warnings_summary

Methods included from Util

#array?, #block?, #call?, #camelize, #class_name, #constant?, #contains_class?, #cookies?, #false?, #hash?, #hash_access, #hash_insert, #hash_iterate, #integer?, #kwsplat?, #make_call, #node_type?, #number?, #params?, #pluralize, #rails_version, #regexp?, #remove_kwsplat, #request_env?, #request_value?, #result?, #safe_literal, #safe_literal?, #safe_literal_target?, #set_env_defaults, #sexp?, #string?, #string_interp?, #symbol?, #template_path_to_name, #true?, #underscore

Constructor Details

This class inherits a constructor from Brakeman::Report::Base

Instance Method Details

#convert_to_hashes(warnings) ⇒ Object



38
39
40
41
42
# File 'lib/brakeman/report/report_json.rb', line 38

def convert_to_hashes warnings
  warnings.map do |w|
    w.to_hash(absolute_paths: false)
  end.sort_by { |w| "#{w[:fingerprint]}#{w[:line]}" }
end

#generate_reportObject



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/brakeman/report/report_json.rb', line 2

def generate_report
  errors = tracker.errors.map{|e| { :error => e[:error], :location => e[:backtrace][0] }}

  obsolete = tracker.unused_fingerprints

  warnings = convert_to_hashes all_warnings

  ignored = convert_to_hashes ignored_warnings

  scan_info = {
    :app_path => tracker.app_path,
    :rails_version => rails_version,
    :security_warnings => all_warnings.length,
    :start_time => tracker.start_time.to_s,
    :end_time => tracker.end_time.to_s,
    :duration => tracker.duration,
    :checks_performed => checks.checks_run.sort,
    :number_of_controllers => tracker.controllers.length,
    # ignore the "fake" model
    :number_of_models => tracker.models.length - 1,
    :number_of_templates => number_of_templates(@tracker),
    :ruby_version => RUBY_VERSION,
    :brakeman_version => Brakeman::Version
  }

  report_info = {
    :scan_info => scan_info,
    :warnings => warnings,
    :ignored_warnings => ignored,
    :errors => errors,
    :obsolete => obsolete
  }

  JSON.pretty_generate report_info
end