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_dstr, #process_if, #process_params

Methods included from Util

#array?, #block?, #call?, #camelize, #class_name, #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

#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



43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/brakeman/checks/check_session_settings.rb', line 43

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.expand_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.expand_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



59
60
61
62
63
64
65
# File 'lib/brakeman/checks/check_session_settings.rb', line 59

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.expand_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
# File 'lib/brakeman/checks/check_session_settings.rb', line 19

def run_check
  settings = tracker.config.session_settings 

  check_for_issues settings, @app_tree.expand_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

  if tracker.options[:rails4]
    check_secrets_yaml
  end
end