-
Notifications
You must be signed in to change notification settings - Fork 37
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
Bug: Incorrect Handling of Timestamps in exp, nbf, and iat Claims in fast-jwt #549
Comments
Hey, @rajibchy! I'm here to help you with any bugs, questions, or contributions. Let's work together to resolve the issue you're facing. The issue you've described involves a mismatch in units between the Your suggested fix is on the right track. By converting Here's a summary of the key changes:
This ensures that all time-related calculations are performed in seconds, aligning with the To continue talking to Dosu, mention @dosu. Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Bug Report | Other |
@rajibchy thanks for reporting, but I'm not sure I understand the issue. The documentation says that I'm also not sure how the fix addresses the issue, it looks like you're simply assuming that |
Oh.. Yes are you right according to documentation.
|
Description
There is an issue in
fast-jwt
where theexp
,nbf
, andiat
claims are incorrectly calculated whenexpiresIn
is provided in seconds. Specifically, the issue arises whenpayload.iat
is in milliseconds, butexpiresIn
is in seconds, which results in incorrect expiration calculations.Steps to Reproduce
expiresIn
in seconds.payload.iat
is set (or not set) and potentially in milliseconds.exp
andnbf
values are incorrectly calculated ifiat
is in milliseconds.Expected Behavior
exp
,nbf
, andiat
claims should all be calculated correctly with consistent units (typically in seconds).iat
is in milliseconds.Actual Behavior
payload.iat
is in milliseconds, andexpiresIn
is given in seconds, theexp
(expiration) andnbf
(not before) values are incorrectly calculated due to a mismatch in units.Code Snippet
The issue is occurring in the following code:
Suggested Fix
iat
should be converted to seconds before performing calculations forexp
andnbf
. Here’s the corrected solution:Explanation:
iat
is originally in milliseconds (as it's calculated byDate.now()
), so it is first converted to seconds (iatSec
).exp
(expiration) andnbf
(not before) are then calculated usingiatSec
, ensuring all timestamp calculations are in seconds.expiresIn
(in seconds) andiat
(in milliseconds).Environment
fast-jwt
version: 5.0.5Node.js
version: v20.9.0Additional Information
iat
is not manually set and theexpiresIn
is in seconds.iat
is in milliseconds.Link to Source Code
You can find the relevant code in the
fast-jwt
repository here: fast-jwt Signer.js - Line 93.The text was updated successfully, but these errors were encountered: