Sha256: 88c82ef25b18a26837b592167b53000842dcad3799e720f45fd1eb7b1dfab3d4

Contents?: true

Size: 1.03 KB

Versions: 6

Compression:

Stored size: 1.03 KB

Contents

require 'brakeman/checks/base_check'

class Brakeman::CheckSecrets < Brakeman::BaseCheck
  Brakeman::Checks.add_optional self

  @description = "Checks for secrets stored in source code"

  def run_check
    check_constants
  end

  def check_constants
    @warned = Set.new

    @tracker.constants.each do |constant|
      name = constant.name_array.last
      value = constant.value

      if string? value and not value.value.empty? and looks_like_secret? name
        match = [name, value, value.line]

        unless @warned.include? match
          @warned << match

          warn :warning_code => :secret_in_source,
            :warning_type => "Authentication",
            :message => msg("Hardcoded value for ", msg_code(name), " in source code"),
            :confidence => :medium,
            :file => constant.file,
            :line => constant.line
        end
      end
    end
  end

  def looks_like_secret? name
    # REST_AUTH_SITE_KEY is the pepper in Devise
    name.match /password|secret|(rest_auth_site|api)_key$/i
  end
end

Version data entries

6 entries across 6 versions & 3 rubygems

Version Path
brakeman-4.5.0 lib/brakeman/checks/check_secrets.rb
brakeman-min-4.5.0 lib/brakeman/checks/check_secrets.rb
brakeman-lib-4.5.0 lib/brakeman/checks/check_secrets.rb
brakeman-4.4.0 lib/brakeman/checks/check_secrets.rb
brakeman-lib-4.4.0 lib/brakeman/checks/check_secrets.rb
brakeman-min-4.4.0 lib/brakeman/checks/check_secrets.rb