Open dlpetrie opened 9 months ago
Hello. Is there any confirmation that this is indeed a bug? I can potentially find time to look further into this if confirmation is given.
Thank you
Yes, this does look like a bug. Instead of only using the first key, we should attempt verification with previous keys as well.
PRs are welcome.
Preflight checklist
Ory Network Project
No response
Describe the bug
After creating/rotating a new JWK, when existing sessions call the
end_session_endpoint
with theid_token_hint
Hydra is redirecting to the error page with the following error:Reproducing the bug
access_token
andid_token
from Hydra.POST
call to/admin/keys/hydra.openid.id-token
end_session_endpoint
withid_token_hint
populated.Relevant log output
Relevant configuration
No response
Version
2.2.0-pre.1
On which operating system are you observing this issue?
None
In which environment are you deploying?
None
Additional Context
Digging into the code this is the trail I found:
h.r.ConsentStrategy().HandleOpenIDConnectLogout(...)
: https://github.com/ory/hydra/blob/0421fdad0b30b24a1aa5939e69c20e9d0d8b649f/oauth2/handler.go#L129s.issueLogoutVerifier(...)
because nologout_verifier
was passed: https://github.com/ory/hydra/blob/0421fdad0b30b24a1aa5939e69c20e9d0d8b649f/consent/strategy_default.go#L1091s.getIDTokenHintClaims(...)
with id token: https://github.com/ory/hydra/blob/0421fdad0b30b24a1aa5939e69c20e9d0d8b649f/consent/strategy_default.go#L878s.r.OpenIDJWTStrategy().Decode(ctx, idTokenHint)
usingjwk.NewDefaultJWTSigner()
: https://github.com/ory/hydra/blob/0421fdad0b30b24a1aa5939e69c20e9d0d8b649f/consent/strategy_default.go#L173NewDefaultJWTSigner
sets aGetPrivateKey
func to essentially: https://github.com/ory/hydra/blob/0421fdad0b30b24a1aa5939e69c20e9d0d8b649f/jwk/jwt_strategy.go#L42-L57GetOrGenerateKeys(...)
called by theGetPrivateKey
func and callsFindPrivateKey(...)
: https://github.com/ory/hydra/blob/0421fdad0b30b24a1aa5939e69c20e9d0d8b649f/jwk/helper.go#L46-L78FindPrivateKeys(...)
removes public keys and returns the First key in the set: https://github.com/ory/hydra/blob/0421fdad0b30b24a1aa5939e69c20e9d0d8b649f/jwk/helper.go#L96-L103This is where the issue lies, because the active
id_token
is no longer thefirst
token anymore since the JWK was rotated. It seems theid_tokens
KID
should be pulled out along the way at some point and passed in so the proper key is found instead of thefirst
one found.