Repository navigation
Fix eager load of currentKeyRing on resolving IDataProtector - #67465
Merged
DeagleGross merged 3 commits intoJul 2, 2026
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This pull request fixes a startup-time regression in Data Protection where resolving an IDataProtector could eagerly load the current key ring (and therefore hit external key storage) by changing KeyRingBasedDataProtectionProvider.CreateProtector to avoid calling IKeyRingProvider.GetCurrentKeyRing() during protector creation.
Changes:
- Update
KeyRingBasedDataProtectionProvider.CreateProtectorto always returnKeyRingBasedSpanDataProtectoron .NET, deferring key-ring resolution untilProtect/Unprotect. - Adjust
KeyRingBasedSpanDataProtectorcommentary around the non-span-encryptor fallback path. - Add a regression test ensuring
CreateProtectordoes not callGetCurrentKeyRing.
Show a summary per file
| File | Description |
|---|---|
| src/DataProtection/DataProtection/src/KeyManagement/KeyRingBasedDataProtectionProvider.cs | Removes eager key-ring resolution by returning the span-capable protector on .NET without probing the encryptor up front. |
| src/DataProtection/DataProtection/src/KeyManagement/KeyRingBasedSpanDataProtector.cs | Updates the fallback-path commentary when the encryptor doesn’t implement span-based APIs. |
| src/DataProtection/DataProtection/test/Microsoft.AspNetCore.DataProtection.Tests/KeyManagement/KeyRingBasedDataProtectorTests.cs | Adds a regression test asserting CreateProtector does not resolve the key ring. |
Copilot's findings
- Files reviewed: 3/3 changed files
- Comments generated: 3
Closed
3 tasks
halter73
reviewed
Jul 2, 2026
BrennanConroy
approved these changes
Jul 2, 2026
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.
The reported bug eagerly resolves encryptor in order to determine whether
IAuthenticatedEncryptorsupports Span-based APIs (in other words isISpanAuthenticatedEncryptor):However, calling
_keyRingProvider.GetCurrentKeyRing()is not free, and in case keys are persisted to an external store, we now load them (which may be problematic in startup scenarios).The easy fix is to always return
KeyRingBasedSpanDataProtectorwhich isISpanDataProtector- even if underlyingIAuthenticatedEncryptoris notISpanAuthenticatedEncryptorit simply fallbacks to allocateybyte[]APIs.However that is a bit misleading in the usage scenarios:
So we can probably work on introducing new ISpanDataProtectorProvider:
which will match the type with the expectations. But I think fallback is anyway a good choice, so we can simply keep it.
Fixes #67447