Skip to content

[7.1.3 Cherry-pick] Always Encrypted: Validate attestation component lengths before allocation - #5176

Open
github-actions[bot] wants to merge 2 commits into
release/7.1from
dev/automation/pr-5162-to-7.1.3
Open

github-actions[bot] wants to merge 2 commits into
release/7.1from
dev/automation/pr-5162-to-7.1.3

Conversation

@github-actions

@github-actions github-actions Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

Cherry-pick of #5162 (0eeb306) into release/7.1.

Conflict resolution

Same resolution as the 6.1 (#5174) and 7.0 (#5175) backports; 7.1's NoneAttestationEnclaveProvider.cs is identical to theirs. 7.1 already contains the EnclaveDiffieHellmanInfo.Size fix from #4346, so nothing extra is needed.

  • NoneAttestationEnclaveProvider.cs: main's async provider refactor isn't on 7.1. Kept the synchronous CreateEnclaveSession and applied the same validation inline: header bounds check, direct session ID read, and the shared EnclaveDiffieHellmanInfo parser.
  • doc/always-encrypted-async.md: this file doesn't exist on 7.1, so the doc change was dropped.
  • NoneAttestationEnclaveProviderTests.cs: removed the two CreateEnclaveSessionAsync tests, which test an API not on 7.1. The sync tests remain.

The other source and test files applied cleanly.

Testing

  • dotnet build build.proj -t:BuildSqlClient — passed, 0 warnings.
  • dotnet test src/Microsoft.Data.SqlClient/tests/UnitTests/Microsoft.Data.SqlClient.UnitTests.csproj --filter "(FullyQualifiedName~EnclaveHelpersTests|FullyQualifiedName~EnclaveDiffieHellmanInfoTests|FullyQualifiedName~EnclaveReportPackageTests|FullyQualifiedName~NoneAttestationEnclaveProviderTests|FullyQualifiedName~AzureAttestationInfoTests|FullyQualifiedName~AttestationInfoTests|FullyQualifiedName~VirtualSecureMode|FullyQualifiedName~AzureAttestation|FullyQualifiedName~EnclaveSessionCache)&category!=failing&category!=flaky" — passed, 91/91 on net8.0, net9.0 and net10.0.
  • The same command also ran net462 under Mono on Linux: 74 passed, 4 failed. All 4 failures are Mono limitations: ECDiffieHellmanCng is unavailable, and so is the Windows GetCurrentProcessId P/Invoke used during SqlConnection static initialization. They are not related to this change. Windows CI covers net462.

To resolve, run:  git cherry-pick 0eeb306
@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 changed the title [7.1.3 Cherry-pick - CONFLICTS] Always Encrypted: Validate attestation component lengths before allocation [7.1.3 Cherry-pick] Always Encrypted: Validate attestation component lengths before allocation Dec 3, 2026
…ation (#5162)

Check attestation response component lengths, offsets and arithmetic against the enclosing buffer before allocating or copying in the shared helpers and the HGS, Azure and None providers. HGS enclave report packages must also be self-consistent. The None provider now reuses the shared Diffie-Hellman parser. Valid responses keep the same cryptographic verification and session caching.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
[7.1] Applied None-provider validation to the synchronous parser (no async provider path on 7.1); removed async-only tests and the unshipped doc change.

(cherry picked from commit 0eeb306)
@paulmedynski paulmedynski moved this from To triage to In review in SqlClient Board Dec 3, 2026
@paulmedynski
paulmedynski marked this pull request as ready for review December 3, 2026 12:41
@paulmedynski
paulmedynski requested a review from a team as a code owner December 3, 2026 12:41
Copilot AI balanced review requested due to automatic review settings December 3, 2026 12:41
@paulmedynski
paulmedynski enabled auto-merge (squash) December 3, 2026 12: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.

🟡 Changes recommended

The PR description needs an end-to-end HGS/Azure enclave CI-run link or an explanation of infeasibility, since the listed parser unit tests do not verify the server-dependent behavior.

1 open issue
What changed in this PR

Backports #5162’s Always Encrypted attestation parsing safeguards to release/7.1, preserving its synchronous provider API.

Changes:

  • Validates component lengths and buffer boundaries before allocation.
  • Reuses shared key-exchange parsing in the None provider.
  • Adds malformed-response, allocation, and valid-response regression tests.
File Description
src/​Microsoft.Data.SqlClient/​tests/​UnitTests/​Utilities/​AttestationTestData.cs Shared response builders and allocation assertions.
src/​Microsoft.Data.SqlClient/​tests/​UnitTests/​Microsoft/​Data/​SqlClient/​NoneAttestationEnclaveProviderTests.cs Tests rejection, key exchange, and caching.
src/​Microsoft.Data.SqlClient/​tests/​UnitTests/​Microsoft/​Data/​SqlClient/​EnclaveReportPackageTests.cs Tests nested report boundaries.
src/​Microsoft.Data.SqlClient/​tests/​UnitTests/​Microsoft/​Data/​SqlClient/​EnclaveHelpersTests.cs Tests safe buffer slicing.
src/​Microsoft.Data.SqlClient/​tests/​UnitTests/​Microsoft/​Data/​SqlClient/​EnclaveDiffieHellmanInfoTests.cs Tests key and signature lengths.
src/​Microsoft.Data.SqlClient/​tests/​UnitTests/​Microsoft/​Data/​SqlClient/​AzureAttestationInfoTests.cs Tests Azure response framing.
src/​Microsoft.Data.SqlClient/​tests/​UnitTests/​Microsoft/​Data/​SqlClient/​AttestationInfoTests.cs Tests HGS response framing.
src/​Microsoft.Data.SqlClient/​src/​Microsoft/​Data/​SqlClient/​VirtualSecureModeEnclaveProvider.cs Adds shared bounds checks and HGS report validation.
src/​Microsoft.Data.SqlClient/​src/​Microsoft/​Data/​SqlClient/​NoneAttestationEnclaveProvider.cs Validates headers and reuses shared parsing.
src/​Microsoft.Data.SqlClient/​src/​Microsoft/​Data/​SqlClient/​AzureAttestationBasedEnclaveProvider.cs Checks Azure component lengths before copying.
src/​Microsoft.Data.SqlClient/​src/​Microsoft/​Data/​SqlClient/​AlwaysEncryptedEnclaveProviderUtils.cs Validates key-exchange lengths before allocation.

Review effort: Balanced

@paulmedynski paulmedynski assigned saurabh500 and unassigned benrr101 Dec 4, 2026

This branch has not been deployed

No deployments
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.

4 participants