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.
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.
Consequences
- Access Control: Gain Privileges or Assume Identity
- Authentication, Other: Other
- Access Control, Other: Gain Privileges or Assume Identity, Other
How to prevent it
- 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.
Recent advisories
- GHSA-82r6-8w77-94w6 — AnyIO: TLSStream IDNA 2003 host name encoding enables potential TLS certificate spoofing
- GHSA-4m7w-qmgq-4wj5 — aiohttp: TLS Server Hostname Override Is Ignored When Reusing HTTPS Connections
- GHSA-hw58-3793-42gg — Keycloak hostname verification
- GHSA-67fw-w8f2-88wp — casdoor's use of`ssh.InsecureIgnoreHostKey()` disables host key verification
- GHSA-4h8f-2wvx-gg5w — Bouncy Castle Java Cryptography API vulnerable to DNS poisoning
- GHSA-7j7j-66cv-m239 — ZITADEL's Improper Lockout Mechanism Leads to MFA Bypass
- GHSA-c597-f74m-jgc2 — Improper Certificate Validation and Improper Validation of Certificate with Host Mismatch in Keycloak
MergeHarbor checks every repository's dependencies against this database, ranks what matters by exploitability and reachability, routes it to the owning team and opens the fix pull request.
Check your repos with MergeHarbor