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_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, #process_cookies, #process_default, #process_if, #process_params, #process_string_interp

Methods included from Util

#array?, #block?, #call?, #camelize, #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, #regexp?, #relative_path, #request_env?, #request_value?, #result?, #set_env_defaults, #sexp?, #string?, #symbol?, #table_to_csv, #template_path_to_name, #true?, #truncate_table, #underscore

Methods included from ProcessorHelper

#class_name, #process_all, #process_all!, #process_call_args, #process_class, #process_module

Methods inherited from SexpProcessor

#error_handler, #in_context, #process, #process_dummy, #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


40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/brakeman/checks/check_session_settings.rb', line 40

def process_attrasgn exp
  if not tracker.options[:rails3] and exp.target == @session_settings and exp.method == :session=
    check_for_issues exp.first_arg, "#{tracker.app_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, "#{tracker.app_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


56
57
58
59
60
61
62
# File 'lib/brakeman/checks/check_session_settings.rb', line 56

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, "#{tracker.app_path}/config/initializers/session_store.rb"
  end

  exp
end

#run_checkObject


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

def run_check
  settings = tracker.config[:rails][:action_controller] &&
             tracker.config[:rails][:action_controller][:session]

  check_for_issues settings, "#{tracker.app_path}/config/environment.rb"

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