- changed status to open
How to invalidate cache of RemoteJWKSet in nimbus-jose-jwt
We are making use of RemoteJWKSet in nimbus-jose-jwt third party library for JWKS endpoint based JWT validation.
My question is that, let's say a particular key set is removed from the remote JWKS endpoint due to security reasons. But when we get a JWT that was signed using the removed key, it will still be valid since that keyset is available in the cache (RemoteJWKSet will only update the cache when it gets a token with an unknown KID).
I need to know is there any possible way to invalidate the cached JWK set in RemoteJWKSet if required other that restarting the server?
Comments (4)
-
-
- changed status to resolved
To invalidate the cache:
RemoteJWK.getJWKSetCache().put(null);
-
@Vladimir Dzhuvinov
but to insert null, do i have to write an endpoint to explicitly do this when i want a cache refresh.
-
The endpoint URL should return a valid JWK set, otherwise the code is going to throw an error.
To force a cache refresh invalidate the cache as shown above.
RemoteJWK.getJWKSetCache().put(null);
- Log in to comment
What you could do now (with 6.4) is to put an empty JWK set which will cause the RemoteJWKSet to reload the key set from the URL on the next call:
https://static.javadoc.io/com.nimbusds/nimbus-jose-jwt/6.4/com/nimbusds/jose/jwk/source/JWKSetCache.html#put-com.nimbusds.jose.jwk.JWKSet-
It looks like we'll need to create a method to clear the underlying cache.