ReviewOS

stacks/ts-cloud

Harden authentication with recovery, MFA, session management, and optional SSO

#143
Closed chris opened this 2 months ago ·
2 months ago

Roadmap relationship

Outcome

Provide production-ready human authentication that supports secure onboarding and recovery without requiring operators to delete user files or share generated passwords manually.

Current gap

The first admin and collaborators currently rely on locally generated credentials, manual password transfer, fixed-duration cookies, and destructive file deletion for recovery. There is no password reset, MFA, session inventory, or federated login.

User experience

  • Add email-based invite/activation and password-reset flows with expiry, resend, invalid/used-token states, and generic anti-enumeration responses.
  • Support TOTP MFA with recovery codes, step-up prompts for sensitive actions, and a clear lost-device recovery path.
  • Show active sessions/devices with last-used metadata and one-click revocation.
  • Offer optional OIDC first; keep local auth available as an emergency path with explicit configuration.

Scope

  • Introduce verified email, password change/reset, login/session history, MFA enrollment/recovery, and session revocation.
  • Rotate signing keys safely and version session cookies; enforce idle and absolute expiry.
  • Add OIDC discovery, state/nonce/PKCE validation, organization-domain mapping, and provider disable/recovery controls.
  • Preserve loopback development ergonomics without allowing auth bypass in exposed box mode.

Technical direction

  • Use modern password hashing parameters with transparent rehash-on-login and constant-time comparisons.
  • Hash reset/invite/recovery tokens at rest; rate-limit by normalized identity and network signals without enabling trivial lockout abuse.
  • Separate authentication identity from organization membership and authorization.
  • Emit sanitized auth security events without passwords, OTPs, tokens, or raw provider assertions.

Safety and operability

  • Require recent authentication for password, MFA, SSO, owner, token, and secret-sensitive changes.
  • Provide admin recovery codes or documented offline recovery before SSO enforcement can be enabled.
  • Protect against CSRF, session fixation, open redirects, replay, OAuth mix-up, and user enumeration.

Acceptance criteria

  • A user can accept an invite, reset a forgotten password, enroll MFA, revoke another session, and recover with a code.
  • Disabling a user or removing membership invalidates access promptly.
  • OIDC login maps only verified identities according to explicit organization policy.
  • Existing local users continue to sign in and are prompted through a non-breaking upgrade path.

Verification

  • Token expiry/replay, rate-limit, CSRF, fixation, redirect, MFA recovery, and session rotation tests.
  • OIDC mock-provider integration tests including invalid state/nonce and provider outage.
  • Accessible end-to-end flows on mobile and desktop.

Non-goals

  • SAML or SCIM in the initial implementation.
  • Storing third-party provider access tokens unless a separate integration requires them.
  • Replacing provider IAM authentication.
9 days ago

Implemented top to bottom on main in small conventional commits.

Delivered

  • Durable identities, hashed action tokens, opaque versioned sessions, idle/absolute expiry, session inventory and revocation
  • Password reset/change, generic anti-enumeration responses, SES delivery, transparent password rehash, and offline recovery commands
  • TOTP MFA with encrypted seeds, one-time recovery codes, replay prevention, bounded challenges, recent-auth step-up, and lost-device recovery
  • Optional OIDC with exact discovery issuer binding, state/nonce/PKCE S256, signed ID-token verification, verified-domain policy, subject linking, and role-based provisioning
  • Encrypted OIDC provider credentials and transactions; access/refresh tokens are discarded
  • Owner/operator UI for provider configuration, callback guidance, enforcement safeguards, test guidance, and emergency disable
  • Offline OIDC configure/list/discovery-test/disable commands
  • Local owner emergency access, provider-disable cancellation, CSRF/open-redirect/mix-up/replay protections, and sanitized security events
  • Accessible login, recovery, MFA, session, account-security, and SSO states

Verification

  • Full suite: 2,536 passed, 0 failed, 2 intentional skips, 2 todos, 6,730 assertions across 307 files
  • TypeScript: clean
  • Dashboard SSG: 38/38 routes, 0 cached, 0 failed
  • Signed mock-provider integration covers configuration, PKCE login, verified-domain provisioning, OIDC session issuance, secret/token non-persistence, and provider disable
  • Protocol tests cover invalid/cross-provider state, replay, nonce mismatch, discovery issuer mismatch, provider outage, and external return URLs
  • Existing local users remain compatible and transparently migrate

Representative commits: 3f769e3, 90466a6, b9a6c82, 3099660, 370c43d, 5594bd9, f449cdf, 3e37b54, d2b9a53, dd901bd, 8a10ab7.

Sign in to comment on this issue.