Skip to content

Improper Certificate Validation

Description

The `X509TrustManager` has been configured to return null, 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
public void checkClientTrusted(...) {}

Secure Code

java
TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
trustManagerFactory.init((KeyStore) null);
SSLContext tlsContext = SSLContext.getInstance("TLS");
tlsContext.init(null, trustManagerFactory.getTrustManagers(), new SecureRandom());

Remediation

Use the default `TrustManager` instead of implementing a custom one. If a custom implementation is necessary, properly implement `checkServerTrusted` and `checkClientTrusted` by throwing a `CertificateException` for invalid certificates.

Rule Details

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