-
Notifications
You must be signed in to change notification settings - Fork 25.2k
Fix refresh remote JWKS logic #42662
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
fd6cc8c
Fix refresh remote JWKS logic
jkakavas e0650af
Merge remote-tracking branch 'origin/master' into oidc-exception-hand…
jkakavas bfdc19b
Merge remote-tracking branch 'origin/master' into oidc-exception-hand…
jkakavas ef31690
Merge remote-tracking branch 'origin/master' into oidc-exception-hand…
jkakavas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jkakavas Can you please explain why
BadJOSEException
is not retry-able anymore?If I read the code correctly, https://bitbucket.org/connect2id/nimbus-jose-jwt/src/8bc51863af3c36ec3631878ac69c2ab59936cfae/src/main/java/com/nimbusds/jose/proc/DefaultJOSEProcessor.java#lines-234 , a
BadJOSEException
is triggered when there is no candidate key to do the signature verification, so it must be the case of a key rotation?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@albertzaharovits you are right about the above. The problem - which I tried to address - is that
BadJWTException
is also aBadJOSEException
and that aBadJWTException
can be thrown for many reasons ( Expired JWTs, wrong nonce, wrong issuer etc. etc. ) that have nothing to do with key rotation or reloadability of keys, so it didn't make sense to try and reload keys for any error that could happen in the context of the OIDC realm configuration or JWT parsing.I was under the impression that the error of not finding a suitable key would throw a
BadJWSException
and not aBadJOSEException
but you are right. It feels like the only way to try and reload only on errors that can be caused by key rotation, we'd have to both match the Exception class and the Exception message. This is what I was doing to start with here and we agreed it was not an elegant solutionAnother solution would be to add the possibility to refresh a remote JWKSet at will on configurable intervals. This way, if you're using an OP that has a frequent key rotation schedule you can adjust the polling frequency accordingly. This fails to address the situation where an OP rotates their keys because of a compromise though - which is what the original implementation would try to cater for with the simplistic retry on error approach.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jkakavas
I see, that I haven't noticed.
I think we might get a
BadJWSException
as well as aBadJOSEException
when the OP rotated the keys, depending on if the OP uses thekid
header parameter https://tools.ietf.org/html/rfc7515#section-4.1.4 . If it does I think the library would throw aBadJOSEException
; if the OP simply updates the key we will get aBadJWSException
.Therefore, I think we should reload for the
BadJOSEException
even thoughBadJOSEException
can also be caused by a user typo in the realm configuration. If we are concerned about doubling error messages for user misconfiguration, then we can only proceed with the claim validation retrial if the newly retrieved keys are different. I would not be concerned that a realm misconfiguration incurs an additional call to the OP.What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's BadJWTException being a BadJOSEException that is problematic, tbc.
Agreed, this is better than not reloading keys in case of a valid key rotation - this was an unintended consequence of the changes in this PR. I failed to notice that the library throws a
BadJOSEException
in some cases too.I'll raise a PR to change this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed in #42662