Remote verifier reloads JWKs when encountering unknown kid #8
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 current implementation of
RemoteJwksVerifier
relies on a fixed duration to cache theJwkSet
it requested. I want to setcache_duration
high so as not to have my availability constrained by the IDP. However, when the IDP rotates one of its signing keys, JWTs with unknownkid
s will start showing up which will incorrectly fail verification. I think periodic JWK rotation is an IDP good practice. Partly, this reduces the vulnerability window should the keys be exfiltrated, but it also ensures all consumers can deal with key rotation.The solution to this is to reload the
JwkSet
when encountering an unknownkid
. This way, the first unknown key will reload the set and try verification again. So long as the IDP does not rotate out a JWK which still has valid JWTs, key rotation will be transparent to clients. As a side-effect, if all JWKs are rotated at once (e.g. suspected breach), the first new JWT to show up will cause theRemoteJwksVerifier
to drop its old keys, thus reducing the vulnerability window. However, this would enable using the verifier to amplify DOS attacks on the IDP. To mitigate this, we introduce a cooldown timer that limits how often we will request JWKs.This solution is borrowed from https://github.com/panva/jose/blob/4261556a123ae2dc5c5f238465eff7eb9404b293/src/jwks/remote.ts#L121 .