Repository navigation
fix(jwt): use Math.floor instead of bitwise OR for safe timestamp - #4754
Merged
Merged
Conversation
The bitwise OR operator `| 0` truncates numbers to 32-bit signed integers, causing overflow after 2038-01-19 when Unix timestamps exceed 2^31-1. This would make expired JWT tokens pass validation. Replace `(Date.now() / 1000) | 0` with `Math.floor(Date.now() / 1000)` and add a regression test that verifies expired tokens are correctly rejected when the current time is past the Y2038 boundary.
Contributor
Author
|
I saw an actual instance of the Y2038 bug for the first time. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4754 +/- ##
=======================================
Coverage 91.48% 91.48%
=======================================
Files 177 177
Lines 11556 11556
Branches 3357 3357
=======================================
Hits 10572 10572
Misses 983 983
Partials 1 1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Member
|
Hono will exist over 2038. Thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The bitwise OR operator
| 0truncates numbers to 32-bit signed integers, causing overflow after 2038-01-19 when Unix timestamps exceed 2^31-1. This would make expired JWT tokens pass validation.Replace
(Date.now() / 1000) | 0withMath.floor(Date.now() / 1000)and add a regression test that verifies expired tokens are correctly rejected when the current time is past the Y2038 boundary.While this would typically be a severe vulnerability, it is not expected to occur for another 10 years, so I believe it poses no immediate issue.
PoC
Result
The author should do the following, if applicable
bun run format:fix && bun run lint:fixto format the code