Skip to content

feat(platform): enforce session idle timeout server-side (#1502) - #1862

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

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

Conversation

@yannickmonney

Copy link
Copy Markdown
Contributor

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_MINUTES unset (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) with updateAge tightened from 1 day to 60s, so every token refresh (~15 min per active client) slides session.updatedAt — making it a usable activity proxy for the sweep.
  • New convex/governance/session_idle_enforcement.ts: revokeIdleSessions internalMutation + pure, unit-tested decision helpers (resolveOrgIdleWindows, shouldRevokeIdleSession). Enumerates orgs with an enabled session_idle_timeout policy (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.
  • New cron in convex/crons.ts: revoke idle sessions (every 5 min).
  • One security-category audit row per revoked session: session.idle_revoked (actor system, resourceType session, metadata carries userId / window / session timestamps).

G2 — ?reason=idle was emitted but never consumed. app/routes/_auth/log-in.tsx now validates reason and 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 keys common.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 in docs/{en,de,fr}/self-hosted/configuration/environment-reference.md pointing at the policy.

Worst-case enforcement latency ≈ window + ~15-min updatedAt staleness + 5-min cron tick + ~15-min JWT tail; stated in the docs.

Decision-gate recommendations baked in

  • Enforcement keying: strictest-window-wins by org membership (precedent: getStrictestPasswordPolicyForUser, mergeStrictestTwoFactorPolicy), not activeOrganizationId-scoped.
  • Worst-case latency (~window + 35 min) accepted instead of lowering the convex plugin's jwt.expirationSeconds (which would cost more frequent token refreshes for every client).
  • Trusted-headers: reason=idle suppresses the automatic proxy re-auth behind an explicit Continue click — the IdP/proxy still owns real idle enforcement there (documented caveat).
  • Audit granularity: one security audit row per revoked session (bounded by the per-run revocation cap), not a per-org summary row.
  • Verified Better Auth api-key sessions (enableSessionForAPIKeys) are mock in-memory sessions, never persisted to the session model — the sweep cannot churn them.
  • Editor hint copy left unchanged (settings-UI changes kept minimal per the auth-cluster split; sweep granularity is documented in the docs instead).

Verification

Performed:

  • bun run check at repo root — 40/40 tasks green (format, lint, typecheck, platform server+pii suites: 366 files / 71910 tests).
  • New unit 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), extended lib/shared/session-idle.test.ts (always-on updateAge shape), new app/features/auth/login-idle-notice.test.tsx (notice render, no-param absence, trusted-headers click-through).
  • Targeted UI regression runs: login-form-error-clearing, use-session-idle-watchdog, session-idle-timeout-editor — all green.
  • Docs suite: 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):

  • Enable the policy at 1–2 min in Settings > Governance > Security & Monitoring; sign in from a second browser and close it; after window + cron tick confirm the session row is deleted, the session.idle_revoked audit row exists, and reopening the browser lands on /log-in.
  • Open-but-idle tab → watchdog toast then sign-out to /log-in?reason=idle with the notice.
  • Trusted-headers compose setup: confirm revocation plus the visible Continue click-through instead of silent re-auth.

Pre-PR checklist

  • Ran bun run check (format, lint, typecheck, all tests).
  • No hand-rolled skeletons or magic h-[…] on skeletons — N/A (no loading states touched).
  • Updated services/platform/messages/{en,de,fr}.json.
  • Updated /docs/{en,de,fr}/ for every user-visible change.
  • Every touched docs page has a real opening and a real closing (sections added to existing pages; opening/closing tests pass).
  • Ran bun run --filter @tale/docs lint and bun run --filter @tale/docs test.
  • Updated READMEs — N/A.

Part of #1803. Closes #1502.

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.
@coderabbitai

coderabbitai Bot commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

@yannickmonney, we couldn't start this review because you've reached your PR review rate limit.

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 @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 4f03a824-1172-43e8-927b-13a13b79e463

📥 Commits

Reviewing files that changed from the base of the PR and between 067b875 and c510206.

⛔ Files ignored due to path filters (1)
  • services/platform/convex/_generated/api.d.ts is excluded by !**/_generated/**
📒 Files selected for processing (17)
  • docs/de/platform/admin/governance/policies-and-limits.md
  • docs/de/self-hosted/configuration/environment-reference.md
  • docs/en/platform/admin/governance/policies-and-limits.md
  • docs/en/self-hosted/configuration/environment-reference.md
  • docs/fr/platform/admin/governance/policies-and-limits.md
  • docs/fr/self-hosted/configuration/environment-reference.md
  • services/platform/app/features/auth/login-idle-notice.test.tsx
  • services/platform/app/routes/_auth/log-in.tsx
  • services/platform/convex/auth.ts
  • services/platform/convex/crons.ts
  • services/platform/convex/governance/session_idle_enforcement.test.ts
  • services/platform/convex/governance/session_idle_enforcement.ts
  • services/platform/lib/shared/session-idle.test.ts
  • services/platform/lib/shared/session-idle.ts
  • services/platform/messages/de.json
  • services/platform/messages/en.json
  • services/platform/messages/fr.json
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/session-idle-enforcement

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.

@yannickmonney
yannickmonney merged commit 573c096 into main Jun 11, 2026
47 of 48 checks passed
@yannickmonney
yannickmonney deleted the feat/session-idle-enforcement branch June 11, 2026 07:52
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.

Feature: Session idle timeout (server-side enforcement + client watchdog)

1 participant