fix(session): raise the default refresh_token_ttl from 1h to 1d - #145
Merged
Conversation
refreshTtl is the lifetime the server adapter gives the refresh cookie, so the 1h fallback capped a session at one hour regardless of user activity. An app that holds state locally and makes no API calls for a couple of hours could not refresh afterwards, so the first save returned 401. The session row already lives one day (computeSessionTimes), and server side acceptance is gated by expiresAt/idleExpiresAt rather than by this value, so the old fallback under-reported the real refresh window. Raise it in both call sites and ship 1d in .env.example and the compose files. Closes #144
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.
Closes #144
What changed
refresh_token_ttlnow falls back to1dinstead of1h:The shipped
.env.example,docker-compose.yml, anddocker-compose.dev.ymlnow setREFRESH_TOKEN_TTL=1dtoo. Those explicit1hvalues reproduce exactly the same one hour ceiling for anyone who copies them, which is the self hosted case the issue calls out, so leaving them at1hwould have fixed the fallback and not the default anyone actually runs.docs/configuration.mdis updated to match.Why 1d is the right number
refresh_token_ttlnever gates server side acceptance.findRefreshSessionByToken(src/services/sessionService.ts:118) filters onrevokedAt,expiresAt > now, andidleExpiresAt > now, and those timestamps come fromcomputeSessionTimes(src/utils/utils.ts:33) withMAX_SESSION_LIFETIME_DAYS = 1andIDLE_TIMEOUT_DAYS = 1.So the server already honored a refresh token for a full day. The
1hvalue only told the caller otherwise, and the caller believed it.1dmakes the advertised window match the window the server actually enforces.Contract impact
refreshTtlbinds behavior, it is not advisory. The server adapter uses it as the refresh cookie'smaxAgeinpackages/core/src/ensureCookies.ts:257andpackages/core/src/upstreamSession.ts:111, which is the mechanism behind the reported bug: the browser dropped the cookie at one hour while the session was still live.No sibling repo changes are needed. Both SDKs read the number and pass it through, neither one branches on its value, and
@seamless-auth/typestypes it asz.number().optional()with no bound.seamless-auth-reactdoes not referencerefreshTtlat all.Behavior does change at runtime for any deployment relying on the fallback or on the shipped
1h, so the changeset calls that out along with how to opt back into a shorter window.Verification
Three tests covered the fallback and were updated: the
/refreshdefault TTL integration test, the e2e flow, and the sessionIssuance unit test./security-reviewfound no HIGH or MEDIUM findings. Rotation on use, chain revocation on replay, and hashed storage are untouched. The one real delta is that a refresh cookie now sits in the browser for 24h rather than 1h, but an attacker who could read it already held a token the server would honor for the full day, so the change does not widen server side acceptance.Not addressed here
The React SDK still has no scheduled refresh, it refreshes on provider mount and on explicit calls only. Worth a separate issue as the issue notes.