logo

Database

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.

Weakness:

313 - Insecure service configuration - Certificates

Category: Functionality Abuse

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;...