feat(security): add sliding session token refresh#2476
Open
dirkwa wants to merge 2 commits intoSignalK:masterfrom
Open
feat(security): add sliding session token refresh#2476dirkwa wants to merge 2 commits intoSignalK:masterfrom
dirkwa wants to merge 2 commits intoSignalK:masterfrom
Conversation
Active users are silently issued a fresh JWT when their token is past the midpoint of its lifetime, preventing unnecessary logouts. The rememberMe flag is embedded in the JWT payload so refreshed cookies retain the correct maxAge.
Update webapps and security architecture docs to describe the sliding session window and rememberMe flag preservation in refreshed tokens.
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.
Summary
Active users are silently issued a fresh JWT when their current token is past the midpoint of its lifetime, preventing unnecessary logouts. The
rememberMeflag is embedded in the JWT payload so refreshed cookies retain the correctmaxAge.Without this change, once a JWT expires the user must log in again regardless of how recently they used the server. This was reported by users who experienced frequent session loss despite having "Remember Me" enabled.
Changes
generateJWT()accepts an optionalrememberMeparameter and embeds it in the JWT payloadlogin()passes therememberMeflag through togenerateJWT()http_authorizemiddleware checks if a valid token is past 50% of its lifetime and silently issues a replacement viaSet-CookieJWTPayloadinterface extended withrememberMefieldwebapps.mdandsecurity-architecture.mdTesting
Tested against a live server with
expirationset to2m:rememberMe: true: Token issued withexpclaim, cookie set withMax-Age=120Set-Cookiecontaining a new JWT with updatediat/expand preservedrememberMe: true. CookieMax-Age=120correctly resetrememberMe: false: Session cookie (noMax-Age), refresh still works at midpoint, refreshed cookie remains a session cookieObservation
Each refresh response contains duplicate
Set-Cookieheaders (identical values) becausehttp_authorizeruns on two middleware mounts per request. This is harmless — the browser applies them idempotently — but could be cleaned up in a follow-up