Variant · Low-Medium

CWE-297: Improper Validation of Certificate with Host Mismatch

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.

CWE-297 · Variant Level ·20 CVEs ·2 Mitigations

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

The following OpenSSL code obtains a certificate and verifies it.
Bad
cert = SSL_get_peer_certificate(ssl);if (cert && (SSL_get_verify_result(ssl)==X509_V_OK)) {
                        
                           
                           // do secret things
                           
                        
                     }
Even though the "verify" step returns X509_V_OK, this step does not include checking the Common Name against the name of the host. That is, there is no guarantee that the certificate is for the desired host. The SSL connection could have been established with a malicious host that provided a valid certificate.

Mitigations & Prevention

Architecture and Design

Fully check the hostname of the certificate and provide the user with adequate information about the nature of the problem and how to proceed.

Implementation

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 IDDescription
CVE-2012-5810Mobile banking application does not verify hostname, leading to financial loss.
CVE-2012-5811Mobile application for printing documents does not verify hostname, allowing attackers to read sensitive documents.
CVE-2012-5807Software for electronic checking does not verify hostname, leading to financial loss.
CVE-2012-3446Cloud-support library written in Python uses incorrect regular expression when matching hostname.
CVE-2009-2408Web browser does not correctly handle '\0' character (NUL) in Common Name, allowing spoofing of https sites.
CVE-2012-0867Database program truncates the Common Name during hostname verification, allowing spoofing.
CVE-2010-2074Incorrect handling of '\0' character (NUL) in hostname verification allows spoofing.
CVE-2009-4565Mail server's incorrect handling of '\0' character (NUL) in hostname verification allows spoofing.
CVE-2009-3767LDAP server's incorrect handling of '\0' character (NUL) in hostname verification allows spoofing.
CVE-2012-5806Payment processing module does not verify hostname when connecting to PayPal using PHP fsockopen function.
CVE-2012-2993Smartphone device does not verify hostname, allowing spoofing of mail services.
CVE-2012-5804E-commerce module does not verify hostname when connecting to payment site.
CVE-2012-5824Chat application does not validate hostname, leading to loss of privacy.
CVE-2012-5822Application uses third-party library that does not validate hostname.
CVE-2012-5819Cloud storage management application does not validate hostname.

Showing 15 of 20 observed examples.

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.