Skip to content

[release/10.0] Fix SslStream client certificate credential caching - #136622

Merged
svick merged 2 commits into
release/10.0from
backport/pr-132079-to-release/10.0
Nov 5, 2026
Merged

svick merged 2 commits into
release/10.0from
backport/pr-132079-to-release/10.0

Conversation

@github-actions

@github-actions github-actions Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Backport of #132079 to release/10.0

Fixes #136532

/cc @rzikm

Customer Impact

On Windows, a bug in SslStream credential cache allows (in a very specific scenario) a credential-less connection attempt to inherit a client certificate from a previous credential-ful connection attempt.

Since client certs are sent only if server explicitly asks for them, this does not matter too much in practice, and the primary motivation here is to de-noise our CI runs.

Regression

Possibly introduced several releases ago, definitely not a recent regression.

Testing

Appropriate functional tests were added and tested in CI.

Risk

Low, targeted tests exist, change is small.

Fixes #131992.

On Windows, `SslStream` intentionally starts mutual authentication with
anonymous credentials when no matching client-certificate credential is
cached. When the certificate was supplied through
`ClientCertificateContext`, the selected certificate state was cleared
but the context remained on the shared authentication options. The
TlsSession/Schannel path could therefore acquire a certificate-bearing
credential and cache it under the anonymous key, allowing a later
connection without a client certificate to reuse it.

This change temporarily detaches `ClientCertificateContext` while
acquiring the initial anonymous credential. It restores the context if
Schannel requests client credentials, or when the stream is disposed if
no request occurs.

A Windows-only `RemoteExecutor` regression test verifies that a
connection using `ClientCertificateContext` does not pollute the
anonymous credential cache for a subsequent connection with a different
target host and no certificate. The test covers TLS 1.2 and TLS 1.3.

Local validation:
- `build.cmd clr+libs -rc release`
- System.Net.Security product build
- New regression test: 2 passed
- `ClientChangeCert_NoResume`: 3 passed
- `SslStream_NegotiateClientCertificateAsyncTls13_Succeeds`: 2 passed
- `ServerAsyncAuthenticate_EachSupportedProtocol_Success`: 2 passed

The full System.Net.Security functional suite ran 5,279 tests with one
unrelated failure that reproduces in isolation:
`TlsSessionTests.ClientSession_ExternalCertificateValidation_AcceptWithDefaultValidation_FailsOnUntrustedCert`
(`Expected: Not None`, `Actual: None`).

> [!NOTE]
> This pull request description was generated with GitHub Copilot.

---------

Copilot-Session: 9c29577e-370e-4808-a07c-9b0063e6a94a
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 4 pipeline(s).
12 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @dotnet/ncl, @bartonjs, @vcsjones
See info in area-owners.md if you want to be subscribed.

@rzikm
rzikm requested a review from a team October 29, 2026 12:15
@rzikm rzikm added the Servicing-consider Issue for next servicing release review label Oct 29, 2026
Allow SslStream to temporarily clear and restore the certificate context when acquiring anonymous client credentials, matching the upstream accessor.

Co-authored-by: Copilot App <[email protected]>
@rzikm

rzikm commented Oct 30, 2026

Copy link
Copy Markdown
Member

/ba-g test failure is unrelated

@rzikm

rzikm commented Nov 5, 2026

Copy link
Copy Markdown
Member

Approved by Jeff Schwartz over email

@rzikm rzikm added Servicing-approved Approved for servicing release and removed Servicing-consider Issue for next servicing release review labels Nov 5, 2026
@svick
svick merged commit 137bf27 into release/10.0 Nov 5, 2026
98 of 103 checks passed
@svick
svick deleted the backport/pr-132079-to-release/10.0 branch November 5, 2026 10:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[release/10.0] Backport request: fix SslStream client certificate credential caching

3 participants