security: add 7-day expiry to session JWTs#536
Open
xpoes123 wants to merge 1 commit into
Open
Conversation
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.
Session JWTs were signed with no
expclaim, meaning a stolen or leaked token remained valid indefinitely. This PR adds a 7-day expiry to tokens issued bygenerateToken, aligned with the existingCOOKIE_MAX_AGEconstant inserver/constants.js.Problem
In
server/authentication.js,generateTokencalledsign({ username, verifiedEmail }, secret)with no options object, producing tokens that never expire. A compromised token granted permanent account access regardless of when the theft occurred.Changes
{ expiresIn: '7d' }as the third argument tosign()ingenerateToken.Risk & testing
The
checkTokenverification path usesjsonwebtoken'sverify()with a callback that returnsfalseon any error, includingTokenExpiredError— expired tokens are rejected with no failure-open path. Existing tokens without anexpclaim continue to work until their session cookie expires naturally; only newly issued tokens carry the expiry. The password-reset token path (which uses its own 15-minute timestamp logic) is untouched.semistandardandnode --checkpass.