Class: Brakeman::CheckBasicAuth

Inherits:
BaseCheck
  • Object
show all
Defined in:
lib/brakeman/checks/check_basic_auth.rb

Overview

Checks if password is stored in controller when using http_basic_authenticate_with

Only for Rails >= 3.1

Constant Summary

Constant Summary

Constants inherited from BaseCheck

BaseCheck::CONFIDENCE

Constants included from Util

Util::ALL_PARAMETERS, Util::COOKIES, Util::PARAMETERS, Util::PATH_PARAMETERS, Util::QUERY_PARAMETERS, Util::REQUEST_PARAMETERS, Util::SESSION

Instance Attribute Summary

Attributes inherited from BaseCheck

#tracker, #warnings

Instance Method Summary (collapse)

Methods inherited from BaseCheck

#add_result, #initialize, #process_call, #process_cookies, #process_default, #process_params

Methods included from Util

#array?, #call?, #camelize, #cookies?, #false?, #hash?, #hash_insert, #hash_iterate, #integer?, #number?, #params?, #pluralize, #regexp?, #result?, #set_env_defaults, #sexp?, #string?, #symbol?, #true?, #underscore

Methods included from ProcessorHelper

#class_name, #process_module

Constructor Details

This class inherits a constructor from Brakeman::BaseCheck

Instance Method Details

- (Object) get_password(call)



34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/brakeman/checks/check_basic_auth.rb', line 34

def get_password call
  args = call[3][1]

  return false if args.nil? or not hash? args

  hash_iterate(args) do |k, v|
    if symbol? k and k[1] == :password
      return v
    end
  end

  nil
end

- (Object) run_check



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/brakeman/checks/check_basic_auth.rb', line 10

def run_check
  return if version_between? "0.0.0", "3.0.99"

  controllers = tracker.controllers.select do |name, c|
    c[:options][:http_basic_authenticate_with]
  end

  Hash[controllers].each do |name, controller|
    controller[:options][:http_basic_authenticate_with].each do |call|

      if pass = get_password(call) and string? pass
        warn :controller => name,
            :warning_type => "Basic Auth", 
            :message => "Basic authentication password stored in source code",
            :line => call.line,
            :code => call, 
            :confidence => 0

        break
      end
    end
  end
end