Repository navigation
Description
Description
On Windows, an SslStream client configured with no client certificate
(no ClientCertificates, no ClientCertificateContext, no
LocalCertificateSelectionCallback) can end up sending a client
certificate anyway — specifically the certificate that a different
SslStream instance in the same process used earlier via
SslClientAuthenticationOptions.ClientCertificateContext (we also observed
it for a certificate supplied as a chain).
Neither side of the .NET API surface shows this: SslStream.LocalCertificate
is null on the certificate-less client and on the priming
context-based client. The certificate is only visible to the server, in
its RemoteCertificateValidationCallback.
When the server rejects that foreign certificate (its CA is unknown), a
TLS 1.3 client sees the failure only on the first read, as:
IOException (0x80131620): The decryption operation failed, see inner exception.
<= Win32Exception (native -2146893019 / 0x80090325 SEC_E_UNTRUSTED_ROOT):
Die Zertifikatkette wurde von einer nicht vertrauenswürdigen Zertifizierungsstelle ausgestellt.
(= "The certificate chain was issued by an authority that is not trusted.")
i.e. the server's unknown_ca alert — which makes the symptom look like a
crypto/keying bug and cost us a long day of misdirected debugging of a
flaky mutual-TLS test.
Evidence (instrumented run)
All six connections below happen within ~6 seconds in one test process
(NUnit, sequential). cli lines log SslStream.LocalCertificate after
AuthenticateAsClientAsync; srv lines log the certificate seen by the
server's RemoteCertificateValidationCallback. All certificates are
freshly generated per test, EC P-256, ephemeral (never in any cert store).
| Test | Client auth method | LocalCertificate |
Server callback sees | Result |
|---|---|---|---|---|
| 1 | ClientCertificates = [cert1] |
cert1 ✓ | cert1 | ok |
| 2 | ClientCertificates = [cert2] |
cert2 ✓ | cert2 | ok |
| 3 | ClientCertificateContext (cert3) |
null | cert3 | ok |
| 4 | certificate chain (cert4) | null | cert4 | ok |
| 5 | none configured | null | cert3 (!) | server rejects |
| 6 | none configured (TLS 1.3) | null | cert3 (!) | server rejects → client sees "decryption operation failed" |
Raw log excerpt (times, thread ids, thumbprints shortened):
13:29:43.89 cli target=:9001 proto=Tls13 sentClientCert='CN="client #3411"' thumb=70D11886…
13:29:43.89 srv local=:9001 valid=True clientCert='CN="client #3411"'
13:29:45.88 cli target=:9003 proto=Tls13 sentClientCert=none ← context-based client!
13:29:45.88 srv local=:9003 valid=True clientCert='CN="client #9332"' ← its own cert arrives anyway
13:29:47.88 cli target=:9005 proto=Tls13 sentClientCert=none ← certificate-less client
13:29:47.98 srv local=:9005 valid=False clientCert='CN="client #9332"' ← inherits test 3's cert!
13:29:49.98 cli target=:9007 proto=Tls13 sentClientCert=none ← certificate-less client
13:29:49.99 srv local=:9007 valid=False clientCert='CN="client #9332"' ← inherits test 3's cert!
The inherited handshake completes the TLS 1.3 CertificateVerify
signature, so Schannel also has access to the foreign certificate's
private key (an ephemeral CNG key created by the priming stream).
Reproduction
We do not yet have a small standalone repro — five naive two-connection
attempts (context donor → certless probe, in-process and cross-process) did
not reproduce. In our real test suite it reproduces deterministically,
and the necessary ingredients we bisected to are:
- a client handshake that authenticates via
SslStreamCertificateContext
(or a certificate chain) — the "priming" stream, and - a certificate-less TLS 1.3 client (
EnabledSslProtocols = Tls13,
AllowTlsResume = false) against a server with
RemoteCertificateValidationCallback+ client certs requested, and - volume: several hundred prior TLS client handshakes in the same
process (in our suite: removing any of three unrelated large test
groups makes it disappear, keeping them makes it fail deterministically,
~1000 tests / ~7 minutes).
Deterministic repro in our public code base (Vanaheimr Hermod):
git clone https://github.com/Vanaheimr/Hermod && cd Hermod
git checkout a5400af5 # last state before the workaround landed in Mutual_TLS_Tests
dotnet test HermodTests/HermodTests.csproj \
--filter "FullyQualifiedName~Tests.DNS|FullyQualifiedName~Tests.HTTP.|FullyQualifiedName~Tests.HTTP2|FullyQualifiedName~Tests.PKI|FullyQualifiedName~Tests.Modbus"
# Mutual_TLS_ECC__6b_WithAndWithoutAnyClientCert_TLS13_Test fails:
# the certless client presents the certificate of Mutual_TLS_ECC__3…
We are happy to help narrow this down further.
Expected behavior
A client with no configured certificate must never present one.
ClientCertificateContext of one SslStream must never leak into the
credentials of another.
Actual behavior
The certificate supplied via ClientCertificateContext (or chain) of an
earlier SslStream is attached by Schannel to later certificate-less
client handshakes of the same process.
What we ruled out (and why we suspect the managed credential cache key)
| Attempted mitigation on the certless client | Effect |
|---|---|
AllowTlsResume = false (was always set) |
none |
LocalCertificateSelectionCallback returning null |
none |
explicitly empty ClientCertificates collection |
none |
unique TargetHost/SNI per connection |
none |
schannel!SslEmptyCacheW(NULL, 0) at process start (verified to run and return TRUE) |
none |
different EnabledSslProtocols value (Tls12|Tls13 instead of Tls13) |
fixes it completely (5/5 full-suite runs green, was 7/7 red) |
Session resumption is ruled out (resume disabled, unique SNI, cache
emptied). The one thing that helps is changing a value that participates in
the key of .NET's process-wide Schannel credential-handle cache
(SslSessionsCache). That is consistent with the certificate supplied via
SslStreamCertificateContext not being part of that cache key: the
priming stream's credential handle (which carries the certificate) is then
found and reused by later clients whose options hash to the same
"no certificate" key.
Configuration
- .NET SDK 10.0.400, Microsoft.NETCore.App 10.0.11,
net10.0, x64 - Windows 11 Pro, 10.0.26200.9168
- Observed with Schannel only (the mechanism is Windows-specific;
not reproduced/tested on Linux)
Impact
- Functional: flaky/failing mutual-TLS tests and, in production, a
certificate-less client unintentionally authenticating with — and
disclosing — a client identity used elsewhere in the process. - Security-adjacent: a process-wide leak of a client identity (certificate
and use of its private key) across unrelatedSslStreaminstances.
Activity
dotnet-policy-service commentedon Aug 20, 2026
Tagging subscribers to this area: @dotnet/ncl, @bartonjs, @vcsjones
See info in area-owners.md if you want to be subscribed.
rzikm commentedon Aug 24, 2026
I believe this was fixed by #132079
ahzf commentedon Aug 25, 2026
Thanks @rzikm — confirmed, #132079 does fix it.
I ran the reported case against every runtime I have installed, the same binary each time:
mainnightly)Both TLS 1.2 and TLS 1.3 behave the same way, so the dividing line is exactly #132079.
It merged on 2026-08-12, one day after the August servicing release, so 10.0.11 / 9.0.19 / 8.0.30 all shipped without it, and
release/10.0still does not carrycertificateContextToRestore.Could this be considered for a servicing backport to 10.0, and ideally 9.0/8.0 too? 10.0 is LTS while the fix currently only lands in 11.0, which is STS, so applications on the current LTS have no released fix for a case where a certificate-less connection silently presents an unrelated client certificate, with
LocalCertificatenull on both ends. The change is small and self-contained, and #132079 already brings its own coverage,SslStreamCredentialCacheTest.SslStream_ClientCertificateContext_DoesNotPolluteAnonymousCredentialCache, so a backport would not need new tests written for it.ViveliDuCh commentedon Oct 27, 2026
Please consider backporting #132079 to
release/10.0; tracking request: #136532.