Skip to content

Improper Certificate Validation

Description

The `HostnameVerifier` has been set to always return `true`, effectively disabling the validation of server or client certificates. This could allow an adversary to launch a Man-in-the-Middle (MITM) attack, intercepting potentially sensitive information or injecting malicious content into the communication stream.

Examples

Insecure Code

java
class CustomVerifier implements HostnameVerifier {
  @Override
  public boolean verify(String hostname, SSLSession session) {
    return true;
  }
}

Secure Code

java
HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
connection.setHostnameVerifier(HttpsURLConnection.getDefaultHostnameVerifier());

Remediation

Use the default `HostnameVerifier` by calling `HttpsURLConnection.getDefaultHostnameVerifier()`

Rule Details

FieldValue
IDCODE-0700
CategoryCrypto
SeverityMEDIUM
CWECWE-295
ConfidenceHIGH
ImpactHIGH
LikelihoodMEDIUM
ExploitabilityMODERATE
Tagscertificate validation, MITM attack
OWASPA6:2017-Security Misconfiguration, A05:2021-Security Misconfiguration