Browse Source

Update ValidateDataProtectionToken to support IDataProtectionProvider implementations that don't use the default magic header

pull/1824/head
sbolofsson 2 years ago
committed by GitHub
parent
commit
23d8d9bdfe
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 16
      src/OpenIddict.Client.DataProtection/OpenIddictClientDataProtectionHandlers.Protection.cs
  2. 16
      src/OpenIddict.Server.DataProtection/OpenIddictServerDataProtectionHandlers.Protection.cs
  3. 16
      src/OpenIddict.Validation.DataProtection/OpenIddictValidationDataProtectionHandlers.Protection.cs

16
src/OpenIddict.Client.DataProtection/OpenIddictClientDataProtectionHandlers.Protection.cs

@ -62,9 +62,19 @@ public static partial class OpenIddictClientDataProtectionHandlers
return default;
}
// Note: ASP.NET Core Data Protection tokens always start with "CfDJ8", that corresponds
// to the base64 representation of the magic "09 F0 C9 F0" header identifying DP payloads.
if (!context.Token.StartsWith("CfDJ8", StringComparison.Ordinal))
// Note: ASP.NET Core Data Protection tokens created by the default implementation always start
// with "CfDJ8", that corresponds to the base64 representation of the "09 F0 C9 F0" value used
// by KeyRingBasedDataProtectionProvider as a Data Protection version identifier/magic header.
//
// Unless a custom provider implementation - that may use a different mechanism - has been
// registered, return immediately if the token doesn't start with the expected magic header.
//
// See https://learn.microsoft.com/en-us/aspnet/core/security/data-protection/implementation/authenticated-encryption-details
// for more information.
if (!context.Token.StartsWith("CfDJ8", StringComparison.Ordinal) &&
string.Equals(_options.CurrentValue.DataProtectionProvider.GetType().FullName,
"Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRingBasedDataProtectionProvider",
StringComparison.Ordinal))
{
return default;
}

16
src/OpenIddict.Server.DataProtection/OpenIddictServerDataProtectionHandlers.Protection.cs

@ -62,9 +62,19 @@ public static partial class OpenIddictServerDataProtectionHandlers
return default;
}
// Note: ASP.NET Core Data Protection tokens always start with "CfDJ8", that corresponds
// to the base64 representation of the magic "09 F0 C9 F0" header identifying DP payloads.
if (!context.Token.StartsWith("CfDJ8", StringComparison.Ordinal))
// Note: ASP.NET Core Data Protection tokens created by the default implementation always start
// with "CfDJ8", that corresponds to the base64 representation of the "09 F0 C9 F0" value used
// by KeyRingBasedDataProtectionProvider as a Data Protection version identifier/magic header.
//
// Unless a custom provider implementation - that may use a different mechanism - has been
// registered, return immediately if the token doesn't start with the expected magic header.
//
// See https://learn.microsoft.com/en-us/aspnet/core/security/data-protection/implementation/authenticated-encryption-details
// for more information.
if (!context.Token.StartsWith("CfDJ8", StringComparison.Ordinal) &&
string.Equals(_options.CurrentValue.DataProtectionProvider.GetType().FullName,
"Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRingBasedDataProtectionProvider",
StringComparison.Ordinal))
{
return default;
}

16
src/OpenIddict.Validation.DataProtection/OpenIddictValidationDataProtectionHandlers.Protection.cs

@ -57,9 +57,19 @@ public static partial class OpenIddictValidationDataProtectionHandlers
return default;
}
// Note: ASP.NET Core Data Protection tokens always start with "CfDJ8", that corresponds
// to the base64 representation of the magic "09 F0 C9 F0" header identifying DP payloads.
if (!context.Token.StartsWith("CfDJ8", StringComparison.Ordinal))
// Note: ASP.NET Core Data Protection tokens created by the default implementation always start
// with "CfDJ8", that corresponds to the base64 representation of the "09 F0 C9 F0" value used
// by KeyRingBasedDataProtectionProvider as a Data Protection version identifier/magic header.
//
// Unless a custom provider implementation - that may use a different mechanism - has been
// registered, return immediately if the token doesn't start with the expected magic header.
//
// See https://learn.microsoft.com/en-us/aspnet/core/security/data-protection/implementation/authenticated-encryption-details
// for more information.
if (!context.Token.StartsWith("CfDJ8", StringComparison.Ordinal) &&
string.Equals(_options.CurrentValue.DataProtectionProvider.GetType().FullName,
"Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRingBasedDataProtectionProvider",
StringComparison.Ordinal))
{
return default;
}

Loading…
Cancel
Save