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.
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:- Always Validate Certificates: Ensure certificate validation is enabled in all production code making TLS/SSL connections.
- Verify Hostname: Ensure the hostname in the certificate matches the hostname the application is connecting to.
- 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.
- Check Expiry: Ensure the certificate is within its validity period.
- Avoid Disabling Validation: Never disable certificate validation in production environments, even for internal connections. Use proper internal CAs or certificates if needed.
- Keep Trust Stores Updated: Ensure the operating system and application trust stores (containing root CA certificates) are kept up-to-date.
- Python
- Java
- .NET(C#)
- PHP
- Node.js
- Ruby
Framework Context
Using libraries likerequests, 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: Ensureverify=True(the default). If connecting to internal systems with custom CAs, provide the path to the CA bundle file viaverify='/path/to/ca-bundle.pem'.ldap3: Setvalidate=ssl.CERT_REQUIREDand provide the correct CA certificate path viatls_cacerts_fileor 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=Falseorssl.CERT_NONE: The connection will likely succeed without warnings, allowing the proxy to decrypt traffic (MitM successful). - If
verify=Trueand 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.

