Improper Certificate Validation
Description
A HostnameVerifier that accepts any host is often used because of certificate reuse on many hosts. As a consequence, this is vulnerable to Man-in-the-middle attacks since the client will trust any certificate.
Examples
Insecure Code
scala
class MyHostnameVerifier extends HostnameVerifier { def verify(hostname: String, session: SSLSession) = true }Secure Code
scala
class MyHostnameVerifier extends HostnameVerifier { override def verify(hostname: String, session: SSLSession): Boolean = { /* proper validation logic */ } }Remediation
Properly validate the hostname of the server against the hostname in the certificate. Ensure the trust manager does not accept all certificates.
Rule Details
| Field | Value |
|---|---|
| ID | CODE-0035 |
| Category | Crypto |
| Severity | HIGH |
| CWE | CWE-295 |
| Confidence | HIGH |
| Impact | HIGH |
| Likelihood | MEDIUM |
| Exploitability | EASY |
| Tags | certificate validation, man-in-the-middle |
| OWASP | N/A |