Skip to content

Consider doing certificate revocation checking by default for SslStream/HttpClient #111704

Open
@rzikm

Description

@rzikm

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

However, SslAuthenticationOptions do not

private X509RevocationMode _checkCertificateRevocation = X509RevocationMode.NoCheck;

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.

Metadata

Metadata

Assignees

Labels

area-System.Net.Securitybreaking-changeIssue or PR that represents a breaking API or functional change over a prerelease.needs-breaking-change-doc-createdBreaking changes need an issue opened with https://github.com/dotnet/docs/issues/new?template=dotnet

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions