Repository navigation
[7.1.3 Cherry-pick] Always Encrypted: Validate attestation component lengths before allocation - #5176
Open
github-actions[bot] wants to merge 2 commits into
Open
github-actions[bot] wants to merge 2 commits into
github-actions[bot] wants to merge 2 commits into
Conversation
To resolve, run: git cherry-pick 0eeb306
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
…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
approved these changes
Dec 3, 2026
paulmedynski
marked this pull request as ready for review
December 3, 2026 12:41
paulmedynski
enabled auto-merge (squash)
December 3, 2026 12:41
Contributor
There was a problem hiding this comment.
🟡 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
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

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.csis identical to theirs. 7.1 already contains theEnclaveDiffieHellmanInfo.Sizefix from #4346, so nothing extra is needed.NoneAttestationEnclaveProvider.cs: main's async provider refactor isn't on 7.1. Kept the synchronousCreateEnclaveSessionand applied the same validation inline: header bounds check, direct session ID read, and the sharedEnclaveDiffieHellmanInfoparser.doc/always-encrypted-async.md: this file doesn't exist on 7.1, so the doc change was dropped.NoneAttestationEnclaveProviderTests.cs: removed the twoCreateEnclaveSessionAsynctests, 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.ECDiffieHellmanCngis unavailable, and so is the WindowsGetCurrentProcessIdP/Invoke used duringSqlConnectionstatic initialization. They are not related to this change. Windows CI covers net462.