Repository navigation
feat(platform): server-side session idle timeout - #1808
Conversation
📝 WalkthroughWalkthroughThis PR implements server-side session idle timeout functionality by introducing a new Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related issues
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 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 |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@services/platform/lib/shared/session-idle.ts`:
- Around line 30-47: parseSessionIdleTimeoutMinutes() currently logs warnings on
every call (hot path); cache the parsed outcome and dedupe warnings per raw ENV
value, e.g. add a module-level cachedResult variable and a Set of
warnedRawValues keyed by the raw string. On entry, if cachedResult is set return
it; otherwise read process.env[ENV_KEY] into raw, compute minutes as before, and
only call console.warn when the raw value hasn’t already been warned (add it to
warnedRawValues when warning); store the final parsed value (null or
Math.floor(minutes) or clamped MAX_MINUTES) into cachedResult before returning
so subsequent calls are cheap and warnings are not repeated. Ensure you still
reference ENV_KEY, MIN_MINUTES and MAX_MINUTES and preserve current
rounding/clamping behavior.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: 01f7d1c3-0c9e-4c22-bd7c-e13c087ef0d0
📒 Files selected for processing (8)
docs/de/self-hosted/configuration/environment-reference.mddocs/en/self-hosted/configuration/environment-reference.mddocs/fr/self-hosted/configuration/environment-reference.mdservices/platform/convex/auth.tsservices/platform/convex/betterAuth/trusted_headers/create_session_for_trusted_user.tsservices/platform/convex/sso_providers/create_user_session.tsservices/platform/lib/shared/session-idle.test.tsservices/platform/lib/shared/session-idle.ts
Add an opt-in, deployment-wide session inactivity timeout (SESSION_IDLE_TIMEOUT_MINUTES) enforced server-side — the SOC 2 CC6.1 / ISO 27001 A.8.5 control. When set, sessions become a sliding window: each authenticated request slides the expiry forward and a session idle past the window is rejected on its next request; unset keeps the current default lifetime (no behaviour change). A single shared helper (lib/shared/session-idle.ts) drives both Better Auth's native sliding session (expiresIn + updateAge) and the manual session-creation expiry on the trusted-headers and SSO paths, so the window applies uniformly across all session types. Invalid env values fail open to the default (logged) rather than breaking the auth path. Scoped global by design: per-org windows would require reading each org's policy on every request, defeating the JWT-only fast path. The client watchdog (proactive warn + sign-out UX) is a follow-up on top of this server enforcement; this PR delivers the enforcement. Part of #1803 Refs #1502
bdd71e2 to
19b6109
Compare
What
Server-side session idle timeout (#1502) — the SOC 2 CC6.1 / ISO 27001 A.8.5 control. Opt-in and deployment-wide via
SESSION_IDLE_TIMEOUT_MINUTES:How
A single shared helper (
services/platform/lib/shared/session-idle.ts) is the source of truth and drives both paths so the window applies uniformly:session.expiresIn+updateAgeingetAuthOptions(governs email/password + SSO sessions via Better Auth's refresh).create_session_for_trusted_user.ts, 3 sites) and SSO (create_user_session.ts) paths — each keeps its existing default as the no-timeout fallback.Invalid env values fail open to the default (logged), never breaking the auth path at startup.
updateAgeis capped at 60s so an active session slides without a write on every request.Scope (deliberate)
getAuthUserIdentity, 0 DB queries). A single deployment-wide value is the clean, low-risk control; per-org is out of scope.Verification
lib/shared/session-idle.test.ts— 5 cases (unset, valid window → Better Auth seconds config, short-window cadence cap, invalid → fail-open, >24h clamp).bun run check✓ (typecheck, platform lint, 71k+ tests, docs parity). CodeRabbit finding (warning wording) applied.Pre-PR checklist
bun run check— green.messages/{en,de,fr}.json— N/A (no UI strings in this PR; the watchdog follow-up will add them)./docs/{en,de,fr}/— newSESSION_IDLE_TIMEOUT_MINUTESin the environment reference (Sessions section), all three locales.README.*— N/A.Part of #1803
Refs #1502
Summary by CodeRabbit
New Features
Documentation
Tests