Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return unwrapped keys if able #2812

Merged
merged 3 commits into from
Sep 9, 2024
Merged

Conversation

keegan-caruso
Copy link
Contributor

Description

JsonWebTokenHandler would only return unwrapped keys if there was no errors. This change is to align with the behavior in JwtSecurityTokenHandler, that is it returns the keys that were able to be unwrapped, and only throw if no keys were able to be unwrapped.

Relates to #2695

JsonWebTokenHandler would only return unwrapped keys if there was no errors.
This change is to align with the behavior in JwtSecurityTokenHandler, that is
it returns the keys that were able to be unwrapped, and only throw if no keys
were able to be unwrapped.

Relates to #2695
@keegan-caruso keegan-caruso requested a review from a team as a code owner September 5, 2024 20:54
@sruke
Copy link
Contributor

sruke commented Sep 5, 2024

Should the logic here in JsonWebTokenHandler.DecryptToken be updated as well?

@keegan-caruso
Copy link
Contributor Author

Should the logic here in JsonWebTokenHandler.DecryptToken be updated as well?

Yeah, good idea. done.

Copy link
Contributor

@iNinja iNinja left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small comment, otherwise looks good.

@keegan-caruso keegan-caruso merged commit ad4ec65 into dev Sep 9, 2024
6 checks passed
@keegan-caruso keegan-caruso deleted the kecaruso/fix-keywrap-error branch September 9, 2024 18:07
@@ -1422,7 +1422,7 @@ internal IEnumerable<SecurityKey> GetContentEncryptionKeys(JsonWebToken jwtToken
(keysAttempted ??= new StringBuilder()).AppendLine(key.ToString());
}

if (unwrappedKeys.Count > 0 && exceptionStrings is null)
if (unwrappedKeys.Count > 0 || exceptionStrings is null)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we care about exceptionStrings if we have found any possible keys?

@@ -202,7 +202,7 @@ internal Result<string> DecryptToken(
(keysAttempted ??= new StringBuilder()).AppendLine(key.ToString());
}

if (unwrappedKeys.Count > 0 && exceptionStrings is null)
if (unwrappedKeys.Count > 0 || exceptionStrings is null)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we care about exceptionStrings if we have some keys?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants