Class: Brakeman::CheckDetailedExceptions

Inherits:
BaseCheck show all
Defined in:
lib/brakeman/checks/check_detailed_exceptions.rb

Overview

Check for detailed exceptions enabled for production

Constant Summary collapse

LOCAL_REQUEST =
s(:call, s(:call, nil, :request), :local?)

Constants inherited from BaseCheck

BaseCheck::CONFIDENCE

Constants included from Util

Util::ALL_PARAMETERS, Util::COOKIES, Util::COOKIES_SEXP, Util::PARAMETERS, Util::PARAMS_SEXP, Util::PATH_PARAMETERS, Util::QUERY_PARAMETERS, Util::REQUEST_ENV, Util::REQUEST_PARAMETERS, Util::REQUEST_PARAMS, Util::SESSION, Util::SESSION_SEXP

Constants inherited from SexpProcessor

SexpProcessor::VERSION

Instance Attribute Summary

Attributes inherited from BaseCheck

#tracker, #warnings

Attributes inherited from SexpProcessor

#context, #env, #expected

Instance Method Summary collapse

Methods inherited from BaseCheck

#add_result, inherited, #initialize, #process_call, #process_cookies, #process_default, #process_dstr, #process_if, #process_params

Methods included from Util

#array?, #block?, #call?, #camelize, #class_name, #constant?, #contains_class?, #context_for, #cookies?, #false?, #file_by_name, #file_for, #github_url, #hash?, #hash_access, #hash_insert, #hash_iterate, #integer?, #make_call, #node_type?, #number?, #params?, #pluralize, #rails_version, #regexp?, #relative_path, #request_env?, #request_value?, #result?, #set_env_defaults, #sexp?, #string?, #string_interp?, #symbol?, #table_to_csv, #template_path_to_name, #true?, #truncate_table, #underscore

Methods included from ProcessorHelper

#current_file_name, #process_all, #process_all!, #process_call_args, #process_call_defn?, #process_class, #process_module

Methods inherited from SexpProcessor

#in_context, #initialize, #process, processors, #scope

Constructor Details

This class inherits a constructor from Brakeman::BaseCheck

Instance Method Details

#check_detailed_exceptionsObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/brakeman/checks/check_detailed_exceptions.rb', line 26

def check_detailed_exceptions
  tracker.controllers.each do |name, controller|
    controller.methods_public.each do |method_name, definition|
      src = definition[:src]
      body = src.body.last
      next unless body

      if method_name == :show_detailed_exceptions? and not safe? body
        if true? body
          confidence = CONFIDENCE[:high]
        else
          confidence = CONFIDENCE[:med]
        end

        warn :warning_type => "Information Disclosure",
             :warning_code => :detailed_exceptions,
             :message => "Detailed exceptions may be enabled in 'show_detailed_exceptions?'",
             :confidence => confidence,
             :code => src,
             :file => definition[:file]
      end
    end
  end
end

#check_local_request_configObject



16
17
18
19
20
21
22
23
24
# File 'lib/brakeman/checks/check_detailed_exceptions.rb', line 16

def check_local_request_config
  if true? tracker.config.rails[:consider_all_requests_local]
    warn :warning_type => "Information Disclosure",
         :warning_code => :local_request_config,
         :message => "Detailed exceptions are enabled in production",
         :confidence => CONFIDENCE[:high],
         :file => "config/environments/production.rb"
  end
end

#run_checkObject



11
12
13
14
# File 'lib/brakeman/checks/check_detailed_exceptions.rb', line 11

def run_check
  check_local_request_config
  check_detailed_exceptions
end

#safe?(body) ⇒ Boolean

Returns:

  • (Boolean)


51
52
53
54
# File 'lib/brakeman/checks/check_detailed_exceptions.rb', line 51

def safe? body
  false? body or
  body == LOCAL_REQUEST
end