Repository navigation
[release/10.0] Fix SslStream client certificate credential caching - #136622
Merged
Merged
Conversation
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: 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. |
Contributor
|
Tagging subscribers to this area: @dotnet/ncl, @bartonjs, @vcsjones |
Allow SslStream to temporarily clear and restore the certificate context when acquiring anonymous client credentials, matching the upstream accessor. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
wfurt
approved these changes
Oct 29, 2026
Member
|
/ba-g test failure is unrelated |
Member
|
Approved by Jeff Schwartz over email |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.