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

Remote verifier reloads JWKs when encountering unknown kid #8

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

bittrance
Copy link
Contributor

@bittrance bittrance commented May 24, 2024

The current implementation of RemoteJwksVerifier relies on a fixed duration to cache the JwkSet it requested. I want to set cache_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 unknown kids 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 unknown kid. 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 the RemoteJwksVerifier 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 .

@bittrance bittrance changed the title Remote verifier reloads keys when encountering unknown keys Remote verifier reloads JWKs when encountering unknown kid May 24, 2024
@blckngm
Copy link
Owner

blckngm commented May 27, 2024

It's very reasonable to reload when encountering an unknown kid (with a cooldown). However I wonder whether we can have a better API (e.g. builder) for configuring RemoteJwksVerifier to do this while maintaining compatibility for users who don't opt-in. Let me try this.

@bittrance
Copy link
Contributor Author

Agreed. I cringed a bit at adding the fourth argument to the constructor and also thought that a builder might be an improvement.

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.

2 participants