A certificate or host name check accepts everything
What it finds
A checkServerTrusted that returns without throwing accepts every certificate, and a verify of a HostnameVerifier that returns true accepts every host name: the TLS connection is then encrypted to whoever answers, including an attacker in the middle (CWE-295).
Reported are checkServerTrusted and checkClientTrusted methods whose body is empty or only returns, and verify(String, SSLSession) methods whose body is only return true;, in classes and anonymous classes. So are a lambda (host, session) -> true passed to setHostnameVerifier, setDefaultHostnameVerifier or hostnameVerifier, and the ready-made verifiers that accept every host, NoopHostnameVerifier and ALLOW_ALL_HOSTNAME_VERIFIER.
From the rule's source, trust_all_certificates.rs.
import java.security.cert.X509Certificate;import javax.net.ssl.HostnameVerifier;import javax.net.ssl.SSLSession;import javax.net.ssl.X509TrustManager; class Trusting implements X509TrustManager { public void checkClientTrusted(X509Certificate[] chain, String type) {tx0 reports: this checkClientTrusted accepts every certificate } public void checkServerTrusted(X509Certificate[] chain, String type) {tx0 reports: this checkServerTrusted accepts every certificate return; } public X509Certificate[] getAcceptedIssuers() { return new X509Certificate[0]; } HostnameVerifier any = new HostnameVerifier() { public boolean verify(String host, SSLSession session) {tx0 reports: this verify accepts every host name return true; } };} Turn it on, off or suppress it
The rule runs from the recommended tier up. To turn it on in a lower tier, give it a level in tx0.toml:
[rules]
"tx0/java:trust-all-certificates" = "warning"To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:
// tx0: ignore[tx0/java:trust-all-certificates] reason="..."tx0 explain tx0/java:trust-all-certificates shows the same in the terminal. Found a false positive? Report it.