Skip to content

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

FieldValue
IDCODE-0035
CategoryCrypto
SeverityHIGH
CWECWE-295
ConfidenceHIGH
ImpactHIGH
LikelihoodMEDIUM
ExploitabilityEASY
Tagscertificate validation, man-in-the-middle
OWASPN/A