Skip to content

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

Open
github-actions[bot] wants to merge 1 commit into
release/6.1from
dev/automation/pr-4445-to-6.1.7
Open

[6.1.7 Cherry-pick] Fix | Perform ServerCertificate pin validation to verify with server provided cert#4584
github-actions[bot] wants to merge 1 commit into
release/6.1from
dev/automation/pr-4445-to-6.1.7

Conversation

@github-actions

Copy link
Copy Markdown

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

…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 6.1.7 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:06
@benrr101

Copy link
Copy Markdown
Contributor

/azp run

@azure-pipelines

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

@benrr101 benrr101 self-assigned this Aug 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In review

Development

Successfully merging this pull request may close these issues.

3 participants