Repository navigation
feat(platform): enforce session idle timeout server-side (#1502) - #1862
Conversation
Close the remaining gaps in the session idle timeout feature: - Revoke idle sessions server-side: a 5-minute cron sweep deletes session rows whose updatedAt is older than the user's strictest enabled per-org session_idle_timeout window (tightened against the SESSION_IDLE_TIMEOUT_MINUTES backstop). Previously the org policy was client-enforced only, so closed tabs and stolen cookies outlived the window whenever the env var was unset. - Make session.updatedAt a usable activity proxy when the env backstop is unset: keep Better Auth's default 7-day lifetime but tighten updateAge from 1 day to 60s so token refreshes slide updatedAt. - Write one security-category audit row (session.idle_revoked) per revoked session. - Surface ?reason=idle on the login page with a signed-out-for- inactivity notice; in trusted-headers mode, hold the automatic proxy re-auth behind an explicit continue click so the idle sign-out is visible instead of silently re-establishing the session. - Document the policy (platform governance page + environment reference) in en/de/fr.
|
Warning Review limit reached
More reviews will be available in 38 minutes and 6 seconds. Learn how PR review limits work. Your organization has run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (17)
✨ Finishing Touches🧪 Generate unit tests (beta)
Warning Billing warning: we have not been able to collect payment for this subscription for more than 72 hours. Please update the payment method or pay any pending invoices in Billing to avoid service interruption. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
What / why
Most of #1502 already shipped (#1808 env backstop, #1810 client watchdog, #1819 per-org governance policy). This PR closes the verified remaining gaps:
G1 — the per-org policy was client-enforced only. With
SESSION_IDLE_TIMEOUT_MINUTESunset (the default), sessions kept Better Auth's 7-day expiry, so a closed tab or stolen cookie outlived the org window.lib/shared/session-idle.ts:sessionIdleWindowSeconds()now always returns a config. Env set → unchanged. Env unset → Better Auth's default 7-day lifetime (pinned) withupdateAgetightened from 1 day to 60s, so every token refresh (~15 min per active client) slidessession.updatedAt— making it a usable activity proxy for the sweep.convex/governance/session_idle_enforcement.ts:revokeIdleSessionsinternalMutation + pure, unit-tested decision helpers (resolveOrgIdleWindows,shouldRevokeIdleSession). Enumerates orgs with an enabledsession_idle_timeoutpolicy (parse-or-skip on invalid configs), folds memberships into a per-user strictest window, and deletes session rows idle past it via the Better Auth adapter. Bounded per run (orgs / member pages / revocations caps); the 5-minute cadence drains any backlog.convex/crons.ts:revoke idle sessions (every 5 min).security-category audit row per revoked session:session.idle_revoked(actorsystem, resourceTypesession, metadata carries userId / window / session timestamps).G2 —
?reason=idlewas emitted but never consumed.app/routes/_auth/log-in.tsxnow validatesreasonand shows a "signed out due to inactivity" notice above the form. In trusted-headers mode the page previously auto-redirected to the proxy auth endpoint, silently re-establishing the session — after an idle sign-out the redirect is now held behind an explicit Continue click. New keyscommon.sessionIdle.{signedOutNotice,continueToSignIn}in en/de/fr.G3 — the org policy was undocumented. Added a "Session idle timeout" section to
docs/{en,de,fr}/platform/admin/governance/policies-and-limits.md(tighten-only semantics, ~5-min sweep granularity, worst-case latency, trusted-headers/IdP caveat, audit action) and one sentence indocs/{en,de,fr}/self-hosted/configuration/environment-reference.mdpointing at the policy.Worst-case enforcement latency ≈ window + ~15-min
updatedAtstaleness + 5-min cron tick + ~15-min JWT tail; stated in the docs.Decision-gate recommendations baked in
getStrictestPasswordPolicyForUser,mergeStrictestTwoFactorPolicy), notactiveOrganizationId-scoped.jwt.expirationSeconds(which would cost more frequent token refreshes for every client).reason=idlesuppresses the automatic proxy re-auth behind an explicit Continue click — the IdP/proxy still owns real idle enforcement there (documented caveat).enableSessionForAPIKeys) are mock in-memory sessions, never persisted to thesessionmodel — the sweep cannot churn them.Verification
Performed:
bun run checkat repo root — 40/40 tasks green (format, lint, typecheck, platform server+pii suites: 366 files / 71910 tests).convex/governance/session_idle_enforcement.test.ts(9 tests — pure helpers + mutation handler with mocked ctx: strictest-window-wins, audit attribution, expired-session skip, disabled-policy no-op), extendedlib/shared/session-idle.test.ts(always-onupdateAgeshape), newapp/features/auth/login-idle-notice.test.tsx(notice render, no-param absence, trusted-headers click-through).login-form-error-clearing,use-session-idle-watchdog,session-idle-timeout-editor— all green.bun run --filter @tale/docs lint+test(139 tests, locale/structure/terminology parity) green.Manual verification required (needs a running local stack; not performed here):
session.idle_revokedaudit row exists, and reopening the browser lands on/log-in./log-in?reason=idlewith the notice.Pre-PR checklist
bun run check(format, lint, typecheck, all tests).h-[…]on skeletons — N/A (no loading states touched).services/platform/messages/{en,de,fr}.json./docs/{en,de,fr}/for every user-visible change.bun run --filter @tale/docs lintandbun run --filter @tale/docs test.Part of #1803. Closes #1502.