- 
                Notifications
    You must be signed in to change notification settings 
- Fork 5.2k
Description
By default, both SslStream and HttpClient will not perform any revocation checking. We should consider changing to a secure defaults.
Note that there is some inconsistency in different ways to configure Chain verification.
X509ChainPolicy specifies Online by default
Line 128 in 6249fd2
| _revocationMode = X509RevocationMode.Online; | 
However, SslAuthenticationOptions do not
runtime/src/libraries/System.Net.Security/src/System/Net/Security/SslClientAuthenticationOptions.cs
Line 14 in 1815306
| private X509RevocationMode _checkCertificateRevocation = X509RevocationMode.NoCheck; | 
runtime/src/libraries/System.Net.Security/src/System/Net/Security/SslServerAuthenticationOptions.cs
Line 12 in 1815306
| private X509RevocationMode _checkCertificateRevocation = X509RevocationMode.NoCheck; | 
And, by their extension, neither will SocketsHttpHandler. This leads to inconsistent behaviors, consider following
{
    System.Console.WriteLine("default HttpClient");
    using HttpClient client = new HttpClient();
    var response = await client.GetAsync("https://www.microsoft.com");
}
{
    System.Console.WriteLine("default SocketsHttpHandler");
    using HttpClient client = new HttpClient(new SocketsHttpHandler { });
    var response = await client.GetAsync("https://www.microsoft.com");
}
{
    System.Console.WriteLine("default SocketsHttpHandler with default ctor chain policy");
    using HttpClient client = new HttpClient(new SocketsHttpHandler
    {
        SslOptions = {
            CertificateChainPolicy = new X509ChainPolicy()
        }
    });
    var response = await client.GetAsync("https://www.microsoft.com");
}When I add debug console log of the effective revocation check mode, I get
❯ dotnet run
default HttpClient
ChainPolicy.RevocationMode = NoCheck
default SocketsHttpHandler
ChainPolicy.RevocationMode = NoCheck
default SocketsHttpHandler with default ctor chain policy
ChainPolicy.RevocationMode = Online
Despite not explicitly configuring revocation check mode in either case.
Note that this is also in line with new analyzers for CA5399: Enable HttpClient certificate revocation list check analyzer.