Wildcard Certificate Validation Limits for Multi‑Level Subdomains in Visual Studio
0 reputation · 19 Apr 2023, 05:29 UTC
0 reputation · 19 Apr 2023, 05:29 UTC
The goal is to allow Visual Studio to establish TLS connections to services whose hostname contains more than one subdomain level beyond a wildcard certificate (for example, foo.bar.example.com when the certificate is issued to *.example.com).
Current behavior depends on the .NET runtime version bundled with the IDE; some versions enforce a strict single‑subdomain rule and cause the certificate validation to fail, while Visual Studio provides no exposed option to adjust this validation policy.
It remains unclear which specific .NET versions produce the failure, whether newer Visual Studio releases have changed the underlying rule, and what configuration—if any—can be used to permit multi‑level subdomain hostnames without modifying system trust stores.
The .NET runtimes that ship with Visual Studio 2022 (up to version 17.8) enforce the RFC 6125 wildcard rule: a certificate for *.example.com is considered valid only for hostnames with exactly one additional label (e.g., bar.example.com). Hostnames with two or more extra labels, such as foo.bar.example.com, cause TLS validation to fail.
All of these are bundled with Visual Studio 2022 versions through at least 17.8, and they behave identically regarding wildcard matching.
No. Visual Studio does not provide an IDE‑level option to modify wildcard validation; the behavior is controlled solely by the underlying .NET SslStream/Schannel implementation.
foo.bar.example.comHttpClient use HttpClientHandler.ServerCertificateCustomValidationCallback; for lower‑level sockets use ServicePointManager.ServerCertificateValidationCallback or SslStream.AuthenticateAsClient with a validation delegate.bool ValidateCertificate(HttpRequestMessage request, X509Certificate2 certificate, X509Chain chain, SslPolicyErrors errors)
{
// Accept only if the hostname matches the target and the certificate is the known test cert
if (request.RequestUri.Host.Equals("foo.bar.example.com", StringComparison.OrdinalIgnoreCase) &&
certificate.Thumbprint.Equals("AB12CD34EF56...", StringComparison.OrdinalIgnoreCase))
{
return true;
}
// Otherwise rely on default validation
return errors == SslPolicyErrors.None;
}
var handler = new HttpClientHandler { ServerCertificateCustomValidationCallback = ValidateCertificate };
var client = new HttpClient(handler);
true indiscriminately in production.dotnet --info or check Visual Studio’s “About” dialog to confirm the bundled .NET version.foo.bar.example.com using a *.example.com certificate and observe whether an AuthenticationException is thrown.Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.