Skip to main content

Overview

This vulnerability occurs when an application communicates over TLS/SSL (HTTPS, LDAPS, secure database connections, etc.) but fails to properly validate the certificate presented by the server. Common failures include:
  • Not checking the certificate at all.
  • Not verifying the certificate chain up to a trusted root Certificate Authority (CA).
  • Accepting expired certificates.
  • Accepting certificates for the wrong hostname (hostname mismatch).
  • Accepting self-signed certificates in production without explicit pinning.
Failing to validate certificates allows attackers to perform Man-in-the-Middle (MitM) attacks by presenting a fake or invalid certificate, intercepting, reading, and potentially modifying the supposedly secure communication. 🔒❓➡️👨‍💻➡️🔓

Business Impact

Improper certificate validation completely undermines the security benefits of TLS/SSL:
  • Data Interception: Attackers can eavesdrop on sensitive data (credentials, session tokens, PII) transmitted over the connection.
  • Data Tampering: Attackers can modify data in transit without detection.
  • Authentication Bypass: If certificate validation is part of client or server authentication, bypassing it breaks the authentication mechanism.
  • Phishing: Users might be presented with fake websites served over HTTPS with invalid certificates if their browser or client doesn’t warn them properly (though browsers are generally good at this, application-to-server connections often fail here).

Reference Details

CWE ID: CWE-295 (Related: CWE-296, CWE-297) OWASP Top 10 (2021): A07:2021 - Identification and Authentication Failures Severity: High to Critical

Framework-Specific Analysis and Remediation

This vulnerability typically occurs when developers use HTTP client libraries, LDAP clients, database connectors, or other network libraries and either explicitly disable certificate validation (often done during development to work with self-signed certificates) or use libraries with insecure defaults. Key Remediation Principles:
  1. Always Validate Certificates: Ensure certificate validation is enabled in all production code making TLS/SSL connections.
  2. Verify Hostname: Ensure the hostname in the certificate matches the hostname the application is connecting to.
  3. Check Chain of Trust: Ensure the certificate chain validates back to a trusted root CA present in the system’s or application’s trust store.
  4. Check Expiry: Ensure the certificate is within its validity period.
  5. Avoid Disabling Validation: Never disable certificate validation in production environments, even for internal connections. Use proper internal CAs or certificates if needed.
  6. Keep Trust Stores Updated: Ensure the operating system and application trust stores (containing root CA certificates) are kept up-to-date.

Framework Context

Using libraries like requests, urllib3, or ldap3 without verifying server certificates, often by setting verify=False.

Vulnerable Scenario 1: requests with verify=False

Vulnerable Scenario 2: ldap3 Ignoring Certificate Validation

Connecting to LDAPS without proper TLS configuration.

Mitigation and Best Practices

  • requests: Ensure verify=True (the default). If connecting to internal systems with custom CAs, provide the path to the CA bundle file via verify='/path/to/ca-bundle.pem'.
  • ldap3: Set validate=ssl.CERT_REQUIRED and provide the correct CA certificate path via tls_cacerts_file or rely on the system’s trust store.

Secure Code Example

Testing Strategy

Use an intercepting proxy (like Burp Suite, mitmproxy) configured with its own root CA. Configure the client system/application to trust the proxy’s CA. Attempt to connect to the target HTTPS/LDAPS service through the proxy.
  • If verify=False or ssl.CERT_NONE: The connection will likely succeed without warnings, allowing the proxy to decrypt traffic (MitM successful).
  • If verify=True and system trust store used: The connection should fail if the target server presents the proxy’s certificate (as it won’t match the expected hostname or chain correctly).
  • If verify='/path/to/ca': The connection should fail unless the proxy can present a cert signed by that specific CA.