Description
The product communicates with a host that provides a certificate, but the product does not properly ensure that the certificate is actually associated with that host.
Even if a certificate is well-formed, signed, and follows the chain of trust, it may simply be a valid certificate for a different site than the site that the product is interacting with. In order to ensure data integrity, the certificate must be valid, and it must pertain to the site that is being accessed. Even if the product attempts to check the hostname, it is still possible to incorrectly check the hostname. For example, attackers could create a certificate with a name that begins with a trusted name followed by a NUL byte, which could cause some string-based comparisons to only examine the portion that contains the trusted name.
Potential Impact
Access Control
Gain Privileges or Assume Identity
Authentication, Other
Other
Access Control, Other
Gain Privileges or Assume Identity, Other
Demonstrative Examples
cert = SSL_get_peer_certificate(ssl);if (cert && (SSL_get_verify_result(ssl)==X509_V_OK)) {
// do secret things
}Mitigations & Prevention
Fully check the hostname of the certificate and provide the user with adequate information about the nature of the problem and how to proceed.
If certificate pinning is being used, ensure that all relevant properties of the certificate are fully validated before the certificate is pinned, including the hostname.
Detection Methods
- Automated Static Analysis High — Automated static analysis, commonly referred to as Static Application Security Testing (SAST), can find some instances of this weakness by analyzing source code (or binary/compiled code) without having to execute it. Typically, this is done by building a model of data flow and control flow, then sea
- Dynamic Analysis with Manual Results Interpretation — Set up an untrusted endpoint (e.g. a server) with which the product will connect. Create a test certificate that uses an invalid hostname but is signed by a trusted CA and provide this certificate from the untrusted endpoint. If the product performs any operations instead of disconnecting and repor
- Black Box — When Certificate Pinning is being used in a mobile application, consider using a tool such as Spinner [REF-955]. This methodology might be extensible to other technologies.
Real-World CVE Examples
| CVE ID | Description |
|---|---|
| CVE-2012-5810 | Mobile banking application does not verify hostname, leading to financial loss. |
| CVE-2012-5811 | Mobile application for printing documents does not verify hostname, allowing attackers to read sensitive documents. |
| CVE-2012-5807 | Software for electronic checking does not verify hostname, leading to financial loss. |
| CVE-2012-3446 | Cloud-support library written in Python uses incorrect regular expression when matching hostname. |
| CVE-2009-2408 | Web browser does not correctly handle '\0' character (NUL) in Common Name, allowing spoofing of https sites. |
| CVE-2012-0867 | Database program truncates the Common Name during hostname verification, allowing spoofing. |
| CVE-2010-2074 | Incorrect handling of '\0' character (NUL) in hostname verification allows spoofing. |
| CVE-2009-4565 | Mail server's incorrect handling of '\0' character (NUL) in hostname verification allows spoofing. |
| CVE-2009-3767 | LDAP server's incorrect handling of '\0' character (NUL) in hostname verification allows spoofing. |
| CVE-2012-5806 | Payment processing module does not verify hostname when connecting to PayPal using PHP fsockopen function. |
| CVE-2012-2993 | Smartphone device does not verify hostname, allowing spoofing of mail services. |
| CVE-2012-5804 | E-commerce module does not verify hostname when connecting to payment site. |
| CVE-2012-5824 | Chat application does not validate hostname, leading to loss of privacy. |
| CVE-2012-5822 | Application uses third-party library that does not validate hostname. |
| CVE-2012-5819 | Cloud storage management application does not validate hostname. |
Showing 15 of 20 observed examples.
Related Weaknesses
Taxonomy Mappings
- CLASP: — Failure to validate host-specific certificate data
Frequently Asked Questions
What is CWE-297?
CWE-297 (Improper Validation of Certificate with Host Mismatch) is a software weakness identified by MITRE's Common Weakness Enumeration. It is classified as a Variant-level weakness. The product communicates with a host that provides a certificate, but the product does not properly ensure that the certificate is actually associated with that host.
How can CWE-297 be exploited?
Attackers can exploit CWE-297 (Improper Validation of Certificate with Host Mismatch) to gain privileges or assume identity. This weakness is typically introduced during the Implementation, Implementation phase of software development.
How do I prevent CWE-297?
Key mitigations include: Fully check the hostname of the certificate and provide the user with adequate information about the nature of the problem and how to proceed.
What is the severity of CWE-297?
CWE-297 is classified as a Variant-level weakness (Low-Medium abstraction). It has been observed in 20 real-world CVEs.