Class: Brakeman::CheckSessionSettings

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

Overview

Checks for session key length and http_only settings

Constant Summary

Constants inherited from BaseCheck

BaseCheck::CONFIDENCE

Constants included from Util

Util::ALL_COOKIES, Util::ALL_PARAMETERS, Util::COOKIES, Util::COOKIES_SEXP, Util::DIR_CONST, Util::LITERALS, 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, Util::SIMPLE_LITERALS

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, #process_array, #process_cookies, #process_default, #process_dstr, #process_if, #process_params

Methods included from Messages

#msg, #msg_code, #msg_cve, #msg_file, #msg_input, #msg_lit, #msg_plain, #msg_version

Methods included from Util

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

Methods included from ProcessorHelper

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

Methods inherited from SexpProcessor

#in_context, #process, processors, #scope

Constructor Details

#initialize(*args) ⇒ CheckSessionSettings

Returns a new instance of CheckSessionSettings.



9
10
11
12
13
14
15
16
17
# File 'lib/brakeman/checks/check_session_settings.rb', line 9

def initialize *args
  super

  unless tracker.options[:rails3]
    @session_settings = Sexp.new(:colon2, Sexp.new(:const, :ActionController), :Base)
  else
    @session_settings = nil
  end
end

Instance Method Details

#process_attrasgn(exp) ⇒ Object

Looks for ActionController::Base.session = { … } in Rails 2.x apps

and App::Application.config.secret_token = in Rails 3.x apps

and App::Application.config.secret_key_base = in Rails 4.x apps



46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/brakeman/checks/check_session_settings.rb', line 46

def process_attrasgn exp
  if not tracker.options[:rails3] and exp.target == @session_settings and exp.method == :session=
    check_for_issues exp.first_arg, @app_tree.file_path("config/initializers/session_store.rb")
  end

  if tracker.options[:rails3] and settings_target?(exp.target) and
    (exp.method == :secret_token= or exp.method == :secret_key_base=) and string? exp.first_arg

    warn_about_secret_token exp.line, @app_tree.file_path("config/initializers/secret_token.rb")
  end

  exp
end

#process_call(exp) ⇒ Object

Looks for Rails3::Application.config.session_store :cookie_store, { … } in Rails 3.x apps



62
63
64
65
66
67
68
# File 'lib/brakeman/checks/check_session_settings.rb', line 62

def process_call exp
  if tracker.options[:rails3] and settings_target?(exp.target) and exp.method == :session_store
    check_for_rails3_issues exp.second_arg, @app_tree.file_path("config/initializers/session_store.rb")
  end

  exp
end

#run_checkObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/brakeman/checks/check_session_settings.rb', line 19

def run_check
  settings = tracker.config.session_settings 

  check_for_issues settings, @app_tree.file_path("config/environment.rb")

  session_store = @app_tree.file_path("config/initializers/session_store.rb")
  secret_token = @app_tree.file_path("config/initializers/secret_token.rb")

  [session_store, secret_token].each do |file|
    if tracker.initializers[file] and not ignored? file.basename
      process tracker.initializers[file]
    end
  end

  if tracker.options[:rails4]
    check_secrets_yaml
  end
end