Visitar URL original
Honor HostNameInCertificate in managed SNI certificate validation by apoorvdeshmukh · Pull Request #4905 · dotnet/SqlClient · GitHub
Skip to content

Honor HostNameInCertificate in managed SNI certificate validation - #4905

Merged
mdaigle merged 1 commit into
mainfrom
dev/automation/managed-sni-hnic-validation
Oct 23, 2026
Merged

mdaigle merged 1 commit into
mainfrom
dev/automation/managed-sni-hnic-validation

Conversation

@apoorvdeshmukh

Copy link
Copy Markdown
Contributor

Description

Updates managed SNI to use HostNameInCertificate as the sole expected certificate hostname when explicitly configured. During certificate hostname validation, certificates that do not match the configured name are rejected.

Preserves default hostname selection when the property is unset, certificate-chain checks, and existing ServerCertificate matching behavior. The connection destination and TLS routing are unchanged. No public API signatures or localized resources are added or changed.

Clarifies the HostNameInCertificate property documentation and adds regression coverage.

Issues

N/A.

Testing

  • 33 focused certificate-validation tests passed on Windows, including loopback TLS coverage.
  • The .NET Framework build and XML documentation validation passed.
  • Added conditional SQL Server integration coverage for Open and OpenAsync.
Validation commands and completion status
  • dotnet build build.proj -t:TestSqlClientUnit -p:TestFramework=net10.0 '-p:TestFilters=FullyQualifiedName~SniCommonValidateSslServerCertificateTest' -verbosity:quiet — passed, 33 tests.

  • dotnet build 'src\Microsoft.Data.SqlClient\src\Microsoft.Data.SqlClient.csproj' --framework net462 --verbosity quiet — passed.

  • & '.\eng\pipelines\onebranch\scripts\validate-xml-docs.ps1' -SnippetsDirectory '.\doc\snippets' — passed.

  • dotnet build build.proj -t:TestSqlClientManual -p:TestFramework=net10.0 '-p:TestFilters=FullyQualifiedName~HostNameInCertificateTest' -verbosity:quiet — project compiled; conditional integration test skipped because IsCertificateValidationConfigured was not satisfied. The build target reported failure from SQL connection-timeout diagnostics during test initialization.

  • Tests added or updated.

  • Public API behavior documented; no signature changes.

  • Verified against customer repro (not run).

  • Ensure no breaking changes introduced: configured HNIC is now enforced as documented; other certificate-validation behavior is preserved.

Guidelines

Please review the contribution guidelines before submitting a pull request:

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 18415205-5120-4f0e-9815-f2325898516c
Copilot AI balanced review requested due to automatic review settings October 22, 2026 15:28
@github-project-automation github-project-automation Bot moved this to To triage in SqlClient Board Oct 22, 2026

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.

🔵 Needs a closer look

This security-sensitive change needs human confirmation because reported TLS execution covers Windows only and SQL Server integration coverage was skipped.

No open issues 🎉

What changed in this PR

Updates managed SNI to enforce an explicitly configured HostNameInCertificate as the sole expected certificate hostname, without changing the connection destination or TLS routing.

Changes:

  • Checks explicit hostnames even when platform certificate validation reports no errors, while preserving chain checks and certificate-pin precedence.
  • Adds helper-level, loopback TLS, and conditional synchronous/asynchronous SQL Server regression coverage.
  • Clarifies the property’s hostname-override behavior in API documentation.
File Description
src/​Microsoft.Data.SqlClient/​tests/​UnitTests/​Microsoft/​Data/​SqlClient/​ManagedSni/​SniCommonValidateSslServerCertificateTest.cs Adds hostname, chain-error, pin-precedence, and loopback TLS tests.
src/​Microsoft.Data.SqlClient/​tests/​ManualTests/​SQL/​ConnectionTestWithSSLCert/​HostNameInCertificateTest.cs Adds conditional hostname-rejection tests for Open and OpenAsync.
src/​Microsoft.Data.SqlClient/​src/​Microsoft/​Data/​SqlClient/​ManagedSni/​SniCommon.netcore.cs Enforces explicit certificate hostnames and handles missing certificates.
doc/​snippets/​Microsoft.Data.SqlClient/​SqlConnectionStringBuilder.xml Documents explicit hostname precedence without destination changes.

Review effort: Balanced

@apoorvdeshmukh apoorvdeshmukh added this to the 8.0.0-preview1 milestone Oct 22, 2026
@apoorvdeshmukh apoorvdeshmukh moved this from To triage to In review in SqlClient Board Oct 22, 2026
@apoorvdeshmukh
apoorvdeshmukh marked this pull request as ready for review October 22, 2026 15:35
@apoorvdeshmukh
apoorvdeshmukh requested a review from a team as a code owner October 22, 2026 15:35
@codecov

codecov Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 65.80%. Comparing base (c7ab087) to head (a090da5).
⚠️ Report is 29 commits behind head on main.

❗ There is a different number of reports uploaded between BASE (c7ab087) and HEAD (a090da5). Click for more details.

HEAD has 2 uploads less than BASE
Flag BASE (c7ab087) HEAD (a090da5)
CI-SqlClient 2 0
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4905      +/-   ##
==========================================
- Coverage   72.40%   65.80%   -6.61%     
==========================================
  Files         292      286       -6     
  Lines       45471    68626   +23155     
==========================================
+ Hits        32924    45158   +12234     
- Misses      12547    23468   +10921     
Flag Coverage Δ
CI-SqlClient ?
PR-SqlClient-Project 65.80% <100.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@cheenamalhotra cheenamalhotra added Hotfix 7.0.5 PRs targeting main that should be backported to release/7.0 for 7.0.5 Hotfix 6.1.8 Hotfix 7.1.3 PRs targeting main that should be backported to release/7.1 for 7.1.3. labels Oct 22, 2026
@mdaigle
mdaigle merged commit 7c55ed0 into main Oct 23, 2026
137 of 138 checks passed
@mdaigle
mdaigle deleted the dev/automation/managed-sni-hnic-validation branch October 23, 2026 17:34
@github-project-automation github-project-automation Bot moved this from In review to Done in SqlClient Board Oct 23, 2026
priyankatiwari08 added a commit that referenced this pull request Oct 26, 2026
…icate validation (#4909)

* Honor HostNameInCertificate in managed SNI certificate validation (#4905)

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 18415205-5120-4f0e-9815-f2325898516c

* Fix certificate validation test compatibility in 6.1 backport

Use the .NET 8 certificate import fallback and branch-compatible nullable annotations. Register the manual hostname test in set 1 and construct connections using the release-branch API.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: d02b81a2-8d04-492b-8fc8-66d4dbb020f5

---------

Co-authored-by: Apoorv Deshmukh <apdeshmukh@microsoft.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Priyanka Tiwari <prtiwar@microsoft.com>
Copilot-Session: 18415205-5120-4f0e-9815-f2325898516c
Copilot-Session: d02b81a2-8d04-492b-8fc8-66d4dbb020f5
apoorvdeshmukh added a commit that referenced this pull request Nov 9, 2026
- Guard X509CertificateLoader with NET9_0_OR_GREATER; net8 uses Microsoft.Bcl.Cryptography 8.0.0, which lacks it.

- Use new SqlConnection(...) since DataTestUtility.CreateConnection does not exist on release/7.1.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
paulmedynski pushed a commit that referenced this pull request Nov 9, 2026
) (#4908)

Co-authored-by: Apoorv Deshmukh <apdeshmukh@microsoft.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 18415205-5120-4f0e-9815-f2325898516c
cheenamalhotra pushed a commit that referenced this pull request Nov 9, 2026
…icate validation (#4907)

* Honor HostNameInCertificate in managed SNI certificate validation (#4905)

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 18415205-5120-4f0e-9815-f2325898516c

* Adapt #4905 port tests for release/7.1

- Guard X509CertificateLoader with NET9_0_OR_GREATER; net8 uses Microsoft.Bcl.Cryptography 8.0.0, which lacks it.

- Use new SqlConnection(...) since DataTestUtility.CreateConnection does not exist on release/7.1.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

---------

Co-authored-by: Apoorv Deshmukh <apdeshmukh@microsoft.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 18415205-5120-4f0e-9815-f2325898516c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Hotfix 7.0.5 PRs targeting main that should be backported to release/7.0 for 7.0.5 Hotfix 7.1.3 PRs targeting main that should be backported to release/7.1 for 7.1.3.

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

5 participants