Description
A server certificate callback that always returns true accepts TLS connections even when the chain or hostname check fails.
Potential impact
The application may send sensitive information to a server impersonating the intended service.
Remediation
Use the default certificate validation. If you need a custom policy, check the server identity and certificate trust before accepting the connection.
Examples
Before
csharp
handler.ServerCertificateCustomValidationCallback =
(message, cert, chain, errors) => true;
After
csharp
handler.ServerCertificateCustomValidationCallback =
(message, cert, chain, errors) => errors == SslPolicyErrors.None;
The example accepts the certificate only when errors == SslPolicyErrors.None.