Sha256: 0ca02f25052c694c25ef1950d0a76b44f094e8805bf7cd9424430b575cb941ff

Contents?: true

Size: 1.34 KB

Versions: 40

Compression:

Stored size: 1.34 KB

Contents

require 'brakeman/checks/base_check'

# Checks if verify_mode= is called with OpenSSL::SSL::VERIFY_NONE

class Brakeman::CheckSSLVerify < Brakeman::BaseCheck
  Brakeman::Checks.add self

  SSL_VERIFY_NONE = s(:colon2, s(:colon2, s(:const, :OpenSSL), :SSL), :VERIFY_NONE)

  @description = "Checks for OpenSSL::SSL::VERIFY_NONE"

  def run_check
    check_open_ssl_verify_none
    check_http_start
  end

  def check_open_ssl_verify_none
    tracker.find_call(:method => :verify_mode=).each {|call| process_verify_mode_result(call) }
  end

  def process_verify_mode_result result
    if result[:call].last_arg == SSL_VERIFY_NONE
      warn_about_ssl_verification_bypass result
    end
  end

  def check_http_start
    tracker.find_call(:target => :'Net::HTTP', :method => :start).each { |call| process_http_start_result call }
  end

  def process_http_start_result result
    arg = result[:call].last_arg

    if hash? arg and hash_access(arg, :verify_mode) == SSL_VERIFY_NONE
      warn_about_ssl_verification_bypass result
    end
  end

  def warn_about_ssl_verification_bypass result
    return unless original? result

    warn :result => result,
      :warning_type => "SSL Verification Bypass",
      :warning_code => :ssl_verification_bypass,
      :message => "SSL certificate verification was bypassed",
      :confidence => :high,
      :cwe_id => [295]
  end
end

Version data entries

40 entries across 40 versions & 3 rubygems

Version Path
brakeman-7.0.0 lib/brakeman/checks/check_ssl_verify.rb
brakeman-lib-7.0.0 lib/brakeman/checks/check_ssl_verify.rb
brakeman-min-7.0.0 lib/brakeman/checks/check_ssl_verify.rb
brakeman-6.2.2 lib/brakeman/checks/check_ssl_verify.rb
brakeman-lib-6.2.2 lib/brakeman/checks/check_ssl_verify.rb
brakeman-min-6.2.2 lib/brakeman/checks/check_ssl_verify.rb
brakeman-6.2.2.rc1 lib/brakeman/checks/check_ssl_verify.rb
brakeman-min-6.2.1 lib/brakeman/checks/check_ssl_verify.rb
brakeman-lib-6.2.1 lib/brakeman/checks/check_ssl_verify.rb
brakeman-6.2.1 lib/brakeman/checks/check_ssl_verify.rb
brakeman-6.2.0 lib/brakeman/checks/check_ssl_verify.rb
brakeman-lib-6.2.0 lib/brakeman/checks/check_ssl_verify.rb
brakeman-min-6.2.0 lib/brakeman/checks/check_ssl_verify.rb
brakeman-6.1.2 lib/brakeman/checks/check_ssl_verify.rb
brakeman-lib-6.1.2 lib/brakeman/checks/check_ssl_verify.rb
brakeman-min-6.1.2 lib/brakeman/checks/check_ssl_verify.rb
brakeman-min-6.1.1 lib/brakeman/checks/check_ssl_verify.rb
brakeman-lib-6.1.1 lib/brakeman/checks/check_ssl_verify.rb
brakeman-6.1.1 lib/brakeman/checks/check_ssl_verify.rb
brakeman-6.1.0 lib/brakeman/checks/check_ssl_verify.rb