Skip to content

feat(platform): server-side session idle timeout - #1808

Merged
yannickmonney merged 1 commit into
mainfrom
feat/session-idle-timeout
Jun 1, 2026
Merged

yannickmonney merged 1 commit into
mainfrom
feat/session-idle-timeout

Conversation

@yannickmonney

@yannickmonney yannickmonney commented Jun 1, 2026 •

Copy link
Copy Markdown
Contributor

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:

  • Unset (default): no behaviour change — every session keeps its current lifetime.
  • Set (1–1440): sessions become a sliding window. Each authenticated request slides the expiry forward; a session idle past the window is rejected server-side on its next request.

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:

  • Better Auth's native sliding session — session.expiresIn + updateAge in getAuthOptions (governs email/password + SSO sessions via Better Auth's refresh).
  • The manual session-creation expiry on the trusted-headers (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. updateAge is capped at 60s so an active session slides without a write on every request.

Scope (deliberate)

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.
  • Behaviour when unset is unchanged — every call site falls back to its prior default.

Pre-PR checklist

  • Ran bun run check — green.
  • No hand-rolled skeletons — N/A (backend).
  • Updated messages/{en,de,fr}.json — N/A (no UI strings in this PR; the watchdog follow-up will add them).
  • Updated /docs/{en,de,fr}/ — new SESSION_IDLE_TIMEOUT_MINUTES in the environment reference (Sessions section), all three locales.
  • Docs lint + test — green (139 tests).
  • Updated README.* — N/A.

Part of #1803
Refs #1502

Summary by CodeRabbit

  • New Features

    • Added support for configurable session idle timeout, enabling automatic session expiration after specified periods of inactivity. Sessions reset the inactivity timer upon user activity.
  • Documentation

    • Expanded environment configuration reference with new "Sessions" section documenting the idle timeout setting in English, German, and French.
  • Tests

    • Added comprehensive test coverage for session idle timeout configuration parsing and behavior.

@coderabbitai

coderabbitai Bot commented Jun 1, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

This PR implements server-side session idle timeout functionality by introducing a new SESSION_IDLE_TIMEOUT_MINUTES environment variable and integrating it into the session lifecycle. A new session-idle.ts module exports three functions: parseSessionIdleTimeoutMinutes (reads and validates the env var with fail-open behavior and 24-hour clamping), sessionIdleWindowSeconds (converts minutes into Better Auth sliding-session parameters), and sessionExpiryMs (computes expiry timestamps using the configured window or a provided fallback). The Better Auth session config is updated to spread these parameters. Session creation across three flows—trusted headers, SSO, and direct creation—now use the shared expiry helper instead of hardcoded durations. Documentation in three languages describes the new variable and its server-side behavior.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related issues

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 60.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: server-side session idle timeout feature, which aligns with the primary objective of the changeset.
Description check ✅ Passed The description is comprehensive and follows the template structure with a clear summary, detailed implementation explanation, scope, verification, and completed pre-PR checklist items.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/session-idle-timeout

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 7f06536 and bdd71e2.

📒 Files selected for processing (8)
  • docs/de/self-hosted/configuration/environment-reference.md
  • docs/en/self-hosted/configuration/environment-reference.md
  • docs/fr/self-hosted/configuration/environment-reference.md
  • services/platform/convex/auth.ts
  • services/platform/convex/betterAuth/trusted_headers/create_session_for_trusted_user.ts
  • services/platform/convex/sso_providers/create_user_session.ts
  • services/platform/lib/shared/session-idle.test.ts
  • services/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
@yannickmonney
yannickmonney force-pushed the feat/session-idle-timeout branch from bdd71e2 to 19b6109 Compare June 1, 2026 16:48
@yannickmonney
yannickmonney merged commit 0c56486 into main Jun 1, 2026
28 checks passed
@yannickmonney
yannickmonney deleted the feat/session-idle-timeout branch June 1, 2026 17:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant