Skip to content

[7.0.3 Cherry-pick] Fix | Perform ServerCertificate pin validation to verify with server provided cert - #4583

Merged
paulmedynski merged 1 commit into
release/7.0from
dev/automation/pr-4445-to-7.0.3
Sep 1, 2026
Merged

[7.0.3 Cherry-pick] Fix | Perform ServerCertificate pin validation to verify with server provided cert#4583
paulmedynski merged 1 commit into
release/7.0from
dev/automation/pr-4445-to-7.0.3

Conversation

@github-actions

Copy link
Copy Markdown

Cherry-pick of #4445 (8acf068) into release/7.0.

…provided cert (#4445)

* Server Certificate validation changes

* Address comments

* Address review feedback: reorder pin check after policy checks

- Perform ServerCertificate pin validation after chain/name policy error
  handling, making the additive semantics explicit in control flow.
- Extract ValidateCertificatePin/LoadValidationCertificate helpers so the
  loaded pin certificate lives in a narrow 'using' scope (no try/finally).
- Guard against a null server certificate in the pin path.
- Clarify method docs on the policyErrors relationship and reword the
  no-pin fast-path trace message.
- Replace ambiguous 'platform trust' wording in docs with chain-and-name
  validation, and note that pinning does not itself confer trust.
- Add TempCertFile disposable test helper and a null-server-cert regression
  test for the policyErrors == None case.

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

* Revert to minimal design: pin always consulted, fail closed on load error

Restores the original semantic where an exact ServerCertificate match
satisfies certificate validation. The only behavior changes remain:

- The policyErrors == None fast path now also requires that no
  ServerCertificate was supplied, so a configured certificate is always
  compared against the one presented by the server.
- A ServerCertificate that cannot be loaded/parsed now fails the
  connection instead of being silently ignored.

Also keeps the non-design fixes: the loaded certificate is disposed via a
narrow using scope, and a null server certificate throws
AuthenticationException instead of NullReferenceException.

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

* Address review: dedicated string, RemoteCertificateNotAvailable guard, safe Dispose

- Add SQL_ServerCertificateNotAvailable so the failure names the option in
  play rather than reusing the generic policy-error text.
- A matching ServerCertificate no longer satisfies validation when
  RemoteCertificateNotAvailable is reported. The flag and a null serverCert
  are expected to agree, but both are now checked so the contradictory
  combination cannot be accepted via comparison. Documented the
  relationship on the method.
- Guard TempCertFile.Dispose so a cleanup failure cannot mask a real
  assertion failure.

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

---------

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@github-actions
github-actions Bot requested a review from a team as a code owner August 24, 2026 16:27
@github-actions github-actions Bot added this to the 7.0.3 milestone Aug 24, 2026
@github-project-automation github-project-automation Bot moved this to To triage in SqlClient Board Aug 24, 2026
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

@paulmedynski paulmedynski moved this from To triage to In review in SqlClient Board Aug 24, 2026
@paulmedynski
paulmedynski enabled auto-merge (squash) August 24, 2026 17:09
@benrr101

Copy link
Copy Markdown
Contributor

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 2 pipeline(s).
1 pipeline(s) were filtered out due to trigger conditions.

@paulmedynski

Copy link
Copy Markdown
Contributor

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 2 pipeline(s).
1 pipeline(s) were filtered out due to trigger conditions.

@paulmedynski

Copy link
Copy Markdown
Contributor

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).
1 pipeline(s) were filtered out due to trigger conditions.

@paulmedynski
paulmedynski merged commit 40c7841 into release/7.0 Sep 1, 2026
299 checks passed
@paulmedynski
paulmedynski deleted the dev/automation/pr-4445-to-7.0.3 branch September 1, 2026 23:47
@github-project-automation github-project-automation Bot moved this from In review to Done in SqlClient Board Sep 1, 2026
@codecov

codecov Bot commented Sep 1, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 93.61702% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 66.10%. Comparing base (e1e934e) to head (f582cc4).
⚠️ Report is 5 commits behind head on release/7.0.

Files with missing lines Patch % Lines
...oft/Data/SqlClient/ManagedSni/SniCommon.netcore.cs 93.61% 3 Missing ⚠️

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

HEAD has 1 upload less than BASE
Flag BASE (e1e934e) HEAD (f582cc4)
CI-SqlClient 1 0
Additional details and impacted files
@@               Coverage Diff               @@
##           release/7.0    #4583      +/-   ##
===============================================
- Coverage        74.70%   66.10%   -8.61%     
===============================================
  Files              280      275       -5     
  Lines            43929    66242   +22313     
===============================================
+ Hits             32816    43786   +10970     
- Misses           11113    22456   +11343     
Flag Coverage Δ
CI-SqlClient ?
PR-SqlClient-Project 66.10% <93.61%> (?)

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.

This was referenced Sep 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants