Skip to content

Preserve peer certificate chain in TlsSession - #134570

Merged
wfurt merged 3 commits into
dotnet:mainfrom
wfurt:fix-tlssession-peer-chain
Sep 30, 2026
Merged

wfurt merged 3 commits into
dotnet:mainfrom
wfurt:fix-tlssession-peer-chain

Conversation

@wfurt

@wfurt wfurt commented Sep 24, 2026

Copy link
Copy Markdown
Member

Summary

  • capture peer-provided certificates from X509ChainPolicy.ExtraStore before the PAL chain is disposed
  • exclude the peer leaf from GetRemoteCertificates() consistently across platform PALs
  • preserve preconfigured chain-policy entries and avoid retaining session-owned certificates in a reusable TlsContext
  • add client- and server-side regression coverage, including TlsContext reuse

Testing

  • dotnet build in src/libraries/System.Net.Security
  • dotnet build /t:test tests/FunctionalTests/System.Net.Security.Tests.csproj (5,035 tests, 0 failures)
  • dotnet build /t:test tests/UnitTests/System.Net.Security.Unit.Tests.csproj (134 tests, 0 failures)
  • dotnet build /t:test tests/EnterpriseTests/System.Net.Security.Enterprise.Tests.csproj (no applicable tests on macOS)

Resolves #134567

Note

This pull request description was generated with GitHub Copilot.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

CertificateChainPolicy.ExtraStore is shared across sessions from a reusable context, creating concurrency and cross-session certificate contamination risks.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 1 High severity

Open (1)
What changed in this PR

Preserves peer certificate intermediates during external TLS validation, excludes the leaf certificate, and adds context-reuse regression coverage.

Changes:

  • Captures and manages peer intermediates from ExtraStore.
  • Preserves configured chain-policy entries.
  • Applies captured certificates during validation.
  • Adds client/server chain and reuse tests.
File Summary
src/​libraries/​System.Net.Security/​tests/​FunctionalTests/​TlsSessionTests.cs Adds chain-preservation and reuse coverage.
src/​libraries/​System.Net.Security/​src/​System/​Net/​Security/​TlsSession.cs Captures and manages peer intermediates.
src/​libraries/​System.Net.Security/​src/​System/​Net/​Security/​SslStream.Protocol.cs Applies captured certificates during validation.

Comment thread src/libraries/System.Net.Security/src/System/Net/Security/TlsSession.cs Outdated
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

@rzikm rzikm left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM modulo existing comment

Comment thread src/libraries/System.Net.Security/src/System/Net/Security/SslStream.Protocol.cs Outdated
Copilot AI review requested due to automatic review settings September 24, 2026 15:03

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

One or more issues must be addressed before approval.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 1 High severity

Open (1)
Resolved since last review (1)

Comment thread src/libraries/System.Net.Security/src/System/Net/Security/SslStream.Protocol.cs Outdated
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings September 24, 2026 16:41

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🔵 Needs a closer look

TLS certificate-chain validation and reusable context state warrant final human review.

Review effort: Lite
Findings: None

Resolved since last review (1)

@wfurt
wfurt merged commit 201d585 into dotnet:main Sep 30, 2026
81 of 84 checks passed
@wfurt
wfurt deleted the fix-tlssession-peer-chain branch September 30, 2026 16:33
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Oct 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TlsSession discards peer-sent intermediates before external certificate validation

3 participants