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

Precision of validation-timestamp #488

Closed
kronthto opened this issue Feb 13, 2023 · 4 comments
Closed

Precision of validation-timestamp #488

kronthto opened this issue Feb 13, 2023 · 4 comments
Assignees

Comments

@kronthto
Copy link

kronthto commented Feb 13, 2023

The default timestamp uses time() which just has second precision.
Some OAuth-Servers/Providers - like Laravels passport (with thephpleague-server and Carbon2) / lcobucci - issue tokens with microsecond precision in the iat/nbf fields.
If such a token is validated with this lib in standard-configuration the same second (of course after) it is issued, validation will wrongly fail with the Cannot handle token prior to error (without systemclock skew), as $payload->iat > ($timestamp ) e.g. 1676279484.234102 > 1676279484 albeit the time of validation is e.g. 1676279484.7 or 1676279484.4 .

This can be mitigated by setting a $leeway of 1 second of course.
I think however the validation should be enhanced by either rounding or using a microtime()-stamp.

$timestamp = \is_null(static::$timestamp) ? \time() : static::$timestamp;

Edit: May also apply to the nbf check - which is often also set to the issuance date

@RRosalia
Copy link

Yes experiencing exactly the same issue when trying to decode Laravel passport tokens.

@Krisell
Copy link

Krisell commented Feb 24, 2023

Related to #475 which discusses the strict check of iat that is not required by the JWT spec.

I suggest you (1) use the leeway to solve the issue, and (2) make a PR to this repository to either disable the strict iat check or add the rounding you suggest (the rounding might be releasable in a patch version).

@croensch
Copy link

croensch commented Mar 3, 2023

Talking about precision, for me this raises an:

ErrorException(code: 0): Deprecated: Implicit conversion from float 1677835376.492769 to int loses precision at /application/vendor/firebase/php-jwt/src/JWT.php:156

Because \date(DateTime::ISO8601, $payload->iat) does not accept float but integer.

@yash30201
Copy link
Collaborator

Closing this issue as the interim solution for this has already been merged and released in #492 .

Usage of microtime instead of time has been delayed for a major version release as explained in #523 .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants