C Sharp Insecure Certificate Validation
Description
Detects when SSL/TLS certificate validation is disabled or bypassed in C# applications through insecure ServerCertificateValidationCallback implementations. This vulnerability allows accepting invalid or untrusted SSL certificates, potentially enabling man-in-the-middle attacks and compromising secure communications.
Detection Strategy
• Identifies uses of ServerCertificateValidationCallback in the code
• Analyzes the callback implementation to check if it unconditionally returns true or bypasses certificate validation
• Reports a vulnerability when certificate validation logic is found to accept invalid or untrusted certificates without proper verification
Vulnerable code example
using System.Net;
class Program {
public static void Main() {
// VULNERABLE: Disables SSL certificate validation by accepting all certificates
ServicePointManager.ServerCertificateValidationCallback = (sender, cert, chain, errors) => true;
}
}✅ Secure code example
using System.Net;
using System.Net.Security;
using System.Security.Cryptography.X509Certificates;
class Program {
public static void Main() {
// SECURE: Validate certificates properly by checking trusted root and policy errors
ServicePointManager.ServerCertificateValidationCallback = ValidateServerCertificate;...Search for vulnerabilities in your apps for free with Fluid Attacks' automated security testing! Start your 21-day free trial and discover the benefits of the Continuous Hacking Essential plan. If you prefer the Advanced plan, which includes the expertise of Fluid Attacks' hacking team, fill out this contact form.