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

Need to check for 'null-or-empty' issuer signing keys #2057

Merged
merged 1 commit into from Apr 19, 2023

Conversation

dannybtsai
Copy link
Contributor

@dannybtsai dannybtsai commented Apr 19, 2023

In JsonWebTokenHandler.ValidateSignature() method, the issuer signing keys are resolved based on the configuration or the issuer signing keys resolver delegate, and an IEnumerable keys is returned.

If no matching keys are found and the TokenValidationParameters.TryAllIssuerSigningKeys option is enabled, all signing keys from the configuration and TVP.IssuerSigningKeys will be tried.

However, we should check if the keys collection is null or empty (not just null) since a TVP.IssuerSigningKeyResolver can return an empty collection instead of null.

(Release notes)
In previous Wilson versions, when validating a JsonWebToken, all signing keys will be tried when TokenValidationParameters.TryAllIssuerSigningKeys is set to true and the TVP.IssuerSigningKeyResolver delegate (if present) returns null. This behavior could cause keys to not be found if this delegate is present but returns an empty collection instead of null. All signing keys will now be tried when TVP.IssuerSigningKeyResolver returns either null or an empty collection (assuming TokenValidationParameters.TryAllIssuerSigningKeys is set to true).

@TimHannMSFT
Copy link
Contributor

Thanks @dannybtsai , can you also include a section at the end of your description which can be copied into the release notes?

Should be of the form:
In Wilson 6.x.y this commit changed the way we lookup keys...this could cause keys not to be found when....this fix addresses that by...

Copy link
Contributor

@TimHannMSFT TimHannMSFT left a comment

Choose a reason for hiding this comment

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

Thanks for the good investigation and fix @dannybtsai

@dannybtsai dannybtsai merged commit 3d91c43 into dev Apr 19, 2023
1 of 2 checks passed
renovate bot added a commit to orso-co/Orso.Arpa.Api that referenced this pull request May 3, 2023
[![Mend
Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
|
[System.IdentityModel.Tokens.Jwt](https://togithub.com/AzureAD/azure-activedirectory-identitymodel-extensions-for-dotnet)
| nuget | minor | `6.29.0` -> `6.30.0` |

---

### Release Notes

<details>

<summary>AzureAD/azure-activedirectory-identitymodel-extensions-for-dotnet</summary>

###
[`v6.30.0`](https://togithub.com/AzureAD/azure-activedirectory-identitymodel-extensions-for-dotnet/releases/tag/6.30.0):
April release with new API and bug fixes (6.30.0)

[Compare
Source](https://togithub.com/AzureAD/azure-activedirectory-identitymodel-extensions-for-dotnet/compare/6.29.0...6.30.0)

Beginning in release
[6.28.0](https://togithub.com/AzureAD/azure-activedirectory-identitymodel-extensions-for-dotnet/releases/tag/6.28.0)
the library stopped throwing SecurityTokenUnableToValidateException.
This version (6.30.0) marks the exception type as obsolete to make this
change more discoverable. Not including it in the release notes
explicitly for 6.28.0 was a mistake. This exception type will be removed
completely in the next few months as the team moves towards a major
version bump. More information on how to replace the usage going forward
can be found here: https://aka.ms/SecurityTokenUnableToValidateException

Indicate that a SecurityTokenDescriptor can create JWS or JWE

[AzureAD/azure-activedirectory-identitymodel-extensions-for-dotnet#2055
Specify 'UTC' in log messages

AzureAD/azure-activedirectory-identitymodel-extensions-for-dotnet@ceb10b1
Fix order of log messages

AzureAD/azure-activedirectory-identitymodel-extensions-for-dotnet@05eeeb5

Fixed issues with matching Jwt.Kid with a X509SecurityKey.x5t

[AzureAD/azure-activedirectory-identitymodel-extensions-for-dotnet#2057

[AzureAD/azure-activedirectory-identitymodel-extensions-for-dotnet#2061

Marked Exception that is no longer used as obsolete

[AzureAD/azure-activedirectory-identitymodel-extensions-for-dotnet#2060

Added support for AesGcm on .NET 6.0 or higher

AzureAD/azure-activedirectory-identitymodel-extensions-for-dotnet@85fa86a

First round of triming analysis preperation for AOT

[AzureAD/azure-activedirectory-identitymodel-extensions-for-dotnet#2042

Added new API on TokenHandler.ValidateTokenAsync(SecurityToken ...)
implemented only on JsonWebTokenHandler.

[AzureAD/azure-activedirectory-identitymodel-extensions-for-dotnet#2056

</details>

---

### Configuration

📅 **Schedule**: Branch creation - "after 10pm every weekday,every
weekend,before 5am every weekday" in timezone Europe/Berlin, Automerge -
At any time (no schedule defined).

🚦 **Automerge**: Enabled.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Mend
Renovate](https://www.mend.io/free-developer-tools/renovate/). View
repository job log
[here](https://app.renovatebot.com/dashboard#github/orso-co/Orso.Arpa.Api).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNS42My4xIiwidXBkYXRlZEluVmVyIjoiMzUuNjMuMSJ9-->

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
@brentschmaltz brentschmaltz deleted the danny/Check-Empty-SigningKeys-Collection-dev branch June 2, 2023 21:51
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.

None yet

2 participants