Repository navigation
fix: rotate and expire client session identities (#986) - #1042
Merged
DevMuhdishaq merged 1 commit intoOct 19, 2026
Merged
Conversation
Sign-in, wallet login and token refresh now rotate a sessionStorage-backed session id while invalidating the previous one, so a pre-auth id cannot be fixated. Logout clears it, and idle (30 min) / absolute (8 h) timeouts are enforced on boot and by a runtime activity monitor. 🤖 Generated with Codebuff Co-Authored-By: Codebuff <noreply@codebuff.com>
|
@danieloche635-bit Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
7 tasks
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
Closes #986.
Sign-in now regenerates the session identifier and invalidates the previous one. The identifier also rotates on every token refresh, is destroyed on logout, and idle/absolute timeouts are enforced both on boot and while the tab is open.
Changes
src/lib/session.ts(new)sessionStorage-scoped session record (id,issuedAt,lastActivityAt) generated withcrypto.randomUUID()(withgetRandomValues/counter fallbacks).rotateSession()creates a fresh id and remembers the old id as invalidated; a fixated pre-auth record cannot become active again, even if it is written back to storage.invalidateSession()on logout/expiry removes both the in-memory and persisted record.SESSION_IDLE_TIMEOUT_MS(30 min) andSESSION_ABSOLUTE_TIMEOUT_MS(8 h);touchSession()extends the idle window.getSessionStatus()returnsmissing | active | idle | expiredand clears timed-out records as a side effect.src/features/auth/stores/useAuthStore.tssetSession(password login, wallet login, registration) rotates the session id after successful auth.setTokens(refresh) rotates the id as well.clearSession(logout, failed revalidation) invalidates it immediately.src/features/auth/services/session.tsbootstrapSessionsigns out stored tokens whose session is idle/expired, and creates an id for existing token-only sessions (upgrade path).src/features/auth/hooks/useSessionTimeout.ts(new)pointerdown/keydown/touchstart/scrollas activity and checks every 30 s; idle/expired sessions are ended via the existingendSession().AuthProvider.src/lib/session.test.ts— 9 tests: creation/persistence, rotation, fixation replay, logout invalidation, idle/absolute timeouts, activity extension.src/features/auth/stores/useAuthStore.test.ts— 3 new tests: rotation on login, rotation on refresh, invalidation on logout (plus existing coverage, 9 total).Acceptance criteria
Testing
Pre-existing failures on
main(not introduced by this PR):src/features/messaging/index.ts,src/stores/useUiStore.ts,src/components/ui/Skeleton.tsxandvite.config.tscontain merge/syntax/type errors, so a fully green project-wide type-check/build is not possible onmain. This PR does not touch those files.