TLS certificate validation is switched off by a callback that accepts every certificate
What it finds
A validation callback that returns true whatever it is given accepts any certificate, so anyone between the client and the server can read and change the traffic. The callbacks checked are ServerCertificateValidationCallback, ServerCertificateCustomValidationCallback and RemoteCertificateValidationCallback assigned a lambda that returns the literal true, and DangerousAcceptAnyServerCertificateValidator.
From the rule's source, certificate_validation_disabled.rs.
using System.Net;using System.Net.Http; class Client{ HttpClient Make() { ServicePointManager.ServerCertificateValidationCallback = (s, c, ch, e) => true;tx0 reports: this callback accepts every certificate var handler = new HttpClientHandler(); handler.ServerCertificateCustomValidationCallback = delegate { return true; };tx0 reports: this callback accepts every certificate handler.ServerCertificateCustomValidationCallback = (m, c, ch, e) => e == System.Net.Security.SslPolicyErrors.None; return new HttpClient(handler); }} 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/csharp:certificate-validation-disabled" = "error"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/csharp:certificate-validation-disabled] reason="..."tx0 explain tx0/csharp:certificate-validation-disabled shows the same in the terminal. Found a false positive? Report it.