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

"exp" claim not checked because of check_claims parameter (jwcrypto) #532

Closed
cm253 opened this issue Mar 4, 2024 · 5 comments · Fixed by #556
Closed

"exp" claim not checked because of check_claims parameter (jwcrypto) #532

cm253 opened this issue Mar 4, 2024 · 5 comments · Fixed by #556

Comments

@cm253
Copy link

cm253 commented Mar 4, 2024

Hi!

I'm referring to the pull request #531, where node-jose has been replaced by jwcrypto.

See the following comment:

# Per the jwcrypto dev, `exp` and `nbf` are always checked

You are passing the check_claims dict to the JWT constructor. In this case, the "exp" claim is not checked if it is valid. The reason is, jwcrypto doesn't check the expiration time if the check_claims parameter has been passed, see the following code:

https://github.com/latchset/jwcrypto/blob/5dc2ea2a87ea9fb3ed833f9f0f7864edc7b01e7b/jwcrypto/jwt.py#L472

An empty dict is not None, so currently we check only if the "exp" claim exists and is a valid integer. To test it you can add a breakpoint in the _check_exp function and see if this function is called:

https://github.com/latchset/jwcrypto/blob/5dc2ea2a87ea9fb3ed833f9f0f7864edc7b01e7b/jwcrypto/jwt.py#L452

In order to also check the validity of the token you have to set 'exp': None in the dict. I came across this when I implemented the token check by myself using the jwcrypto lib.

Regards,
Chris

@sauerburger
Copy link

sauerburger commented Mar 15, 2024

This needs urgent attention. @marcospereirampj

@aboubacs
Copy link

The change was for sure made too fast, there is no way to control the options anymore:

https://github.com/marcospereirampj/python-keycloak/pull/531/files#diff-0bbc8509272e0bb1f2f6be00fcb4f0ae29ff7522c88dcc085a305a0224659aa6R542-R547

=> What about all the other options ? Like verify_signature, etc

@Wim-De-Clercq
Copy link

Related conversation also at #503 (comment)

@waza-ari
Copy link
Contributor

Related conversation in a library relying on python-keycloak: waza-ari/fastapi-keycloak-middleware#30

@ryshoooo
Copy link
Collaborator

ryshoooo commented Apr 6, 2024

Thanks for bringing this up @cm253

I really feel reluctant to make a mapping between the old jose options to the jwcrypto options. Honestly, I prefer to make a breaking change here, change the signature completely, and just pass options for jwcrypto directly such that users can modify this to their own extent.

By merging #531 we have unfortunately made a breaking change already as the behavior is not the same anymore, so we might as well make it official and change the signature of the function.

@ryshoooo ryshoooo mentioned this issue Apr 27, 2024
@ryshoooo ryshoooo linked a pull request Apr 27, 2024 that will close this issue
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 a pull request may close this issue.

6 participants