A trust manager accepts every certificate, which turns off TLS server authentication

tx0/kotlin:trust-all-certificatesdefaulterrorsecurity/cryptodepth fastsecurity, cwe-295

What it finds

A X509TrustManager whose checkServerTrusted does nothing accepts any certificate, so anyone on the network path can impersonate the server and read or change the traffic.

From the rule's source, trust_all_certificates.rs.

Example from the rule's tests
import java.security.cert.X509Certificateimport javax.net.ssl.X509TrustManager object TrustAll : X509TrustManager {    override fun checkClientTrusted(chain: Array<X509Certificate>, authType: String) {}tx0 reports: checkClientTrusted accepts every certificate    override fun checkServerTrusted(chain: Array<X509Certificate>, authType: String) {}tx0 reports: checkServerTrusted accepts every certificate    override fun getAcceptedIssuers(): Array<X509Certificate> = arrayOf()} class Pinned(private val delegate: X509TrustManager) : X509TrustManager {    override fun checkClientTrusted(chain: Array<X509Certificate>, authType: String) = delegate.checkClientTrusted(chain, authType)    override fun checkServerTrusted(chain: Array<X509Certificate>, authType: String) {        delegate.checkServerTrusted(chain, authType)    }    override fun getAcceptedIssuers(): Array<X509Certificate> = delegate.acceptedIssuers}
Highlighted lines are the ones tx0 reports, with its message under each; the other lines are left alone.

Turn it on, off or suppress it

The rule runs in every tier. To turn it off for a project, set its level in tx0.toml:

tx0.toml
[rules]
"tx0/kotlin:trust-all-certificates" = "off"

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/kotlin:trust-all-certificates] reason="..."

tx0 explain tx0/kotlin:trust-all-certificates shows the same in the terminal. Found a false positive? Report it.