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

No way to distinguish between "invalid" and expired JWT token #1053

Open
guillerodriguez opened this issue Aug 29, 2023 · 8 comments
Open

No way to distinguish between "invalid" and expired JWT token #1053

guillerodriguez opened this issue Aug 29, 2023 · 8 comments

Comments

@guillerodriguez
Copy link

guillerodriguez commented Aug 29, 2023

When using the FirebaseJwt adapter, if an expired token is passed in the request, this is handled as an "invalid" token and there is no way to differentiate between this condition and a token with e.g. invalid signature.

This is inconvenient since it is normal for tokens to expire during regular operation, but if a token is invalid for other reasons this may indicate an issue somewhere or an attack. Thus it would be nice to be able to differentiate between these cases.

The call chain is the following:

The problem is that in FirebaseJwt, the decode method verifies the dates (this does not happen with the Jwt class).

There are two possible ways to fix this:

  1. Patch firebase/php-jwt and provide a way to disable the checking of the expiration date. The caller would then be responsible for this check. In our case this is done already in ResourceController::getAccessTokenData.
  2. Change the API of EncryptionUtil::decode, which currently returns either the JWT payload or false, so that it can return different values for "expired" and "any other decoding or validation problems".

A possible (non-optimal) workaround is to set JWT::leeway to a very large value, which effectively disables all date validations. Unfortunately this also disables the validation of the iat and nbf claims, which is undesirable.

@guillerodriguez
Copy link
Author

Also see: firebase/php-jwt#531

@bshaffer
Copy link
Owner

We could follow the pattern set by the other controllers here, and pass the Request to the encryption util, and that could set the proper response code and error message. Would that be sufficient?

@guillerodriguez
Copy link
Author

guillerodriguez commented Aug 29, 2023 via email

@bshaffer
Copy link
Owner

bshaffer commented Aug 29, 2023 via email

@guillerodriguez
Copy link
Author

guillerodriguez commented Aug 30, 2023

@bshaffer I can try. This requires modifying the API of AccessTokenInterface and EncryprionUtil to take a Response (I assume you meant this rather than Request), which will break API compatibility. Is this ok ?

@guillerodriguez
Copy link
Author

@bshaffer Specifically this would require the following API changes:

  • Modify AccessTokenInterface::getAccessToken to take a ResponseInterface
  • Modify EncryptionInterface::decode to take a ResponseInterface

Is this ok ?

@guillerodriguez
Copy link
Author

@bshaffer Can you confirm the outlined approach is OK?

@guillerodriguez
Copy link
Author

@bshaffer I am happy to prepare a PR with the changes that we have discussed but I would need some feedback on the suggested approach (see my earlier comment about API changes). Can you comment on this?

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

No branches or pull requests

2 participants