Skip to content

fix(auth): two-factor final audit fixes - #10750

Merged
waleedlatif1 merged 3 commits into
stagingfrom
fix/two-factor-final-audit
Dec 3, 2026
Merged

waleedlatif1 merged 3 commits into
stagingfrom
fix/two-factor-final-audit

Conversation

@waleedlatif1

Copy link
Copy Markdown
Collaborator

Summary

Final-state audit fixes for two-factor (after #10723, #10739, #10748):

  • Desktop handoff sessions keep the authorizing browser session's sign-in time (createdAt, via Better Auth's createSession(..., overrideAll)). A stolen old session could mint a desktop handoff, redeem it for a "fresh" session and pass the passwordless 2FA enrollment check (enroll the thief's authenticator). The same inheritance stops a handoff from restarting an org's maximum session lifetime, which is measured from createdAt
  • The per-request sweep signs an unenrolled member of a requiring org out everywhere: revokeAllUserSessions(userId, { revokeOAuthGrants: true }) ends every session, moves the org cookie-cache version (no 5-minute cached tail, no repeated re-sweeps) and revokes OAuth grants after the sessions in the same transaction. The admin reset uses the same call
  • A sign-in lockout after repeated wrong codes now writes the auth.two_factor_locked audit entry the docs promise (recorded once, on the failure that sets the lock)
  • TWO_FACTOR_REQUIRED meant three things; split into TWO_FACTOR_REQUIRED (enrolled user, unknown sign-in path), TWO_FACTOR_SETUP_REQUIRED (member who must enroll) and TWO_FACTOR_REQUIRED_BY_ORGANIZATION (can't turn off); client messages reuse the server constants
  • Barrel exports for the sign-in redirect helpers, drop an unused export, docs mention the password for password accounts

Type of Change

  • Bug fix

Testing

  • lib/auth/two-factor/guard.integration.ts 22/22 against real Postgres + the Better Auth handler. New: a handed-over desktop session from an hour-old sign-in can't enable 2FA without a password (red without the fix: enrollment succeeds); the sweep ends both of a member's sessions; a lockout is audited exactly once (an extra attempt after the lock returns 429 and adds no second entry); the disable refusal carries the org code. Each red-checked against the pre-fix code
  • app/api/desktop/auth/handoff/route.test.ts, app/desktop, lib/organizations/members, use-verification.test.tsx (37 tests), biome, api-validation strict, boundaries, client-boundary, source-conventions, comment-hygiene, test-patterns, file-names, utils, explicit-any, tool-registry-boundary, type-check (pre-push); full check:audits and suites in CI
  • Quality review (reuse/simplification/efficiency/altitude, comments, test-audit) applied

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing (new tests pass the test-audit authoring gate)
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

@vercel

vercel Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated
docs Skipped Skipped Dec 3, 2026 11:39pm UTC

Request Review

@cubic-dev-ai cubic-dev-ai 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.

All reported issues were addressed across 15 files

Turn on auto-fix | Re-trigger cubic

Comment thread apps/sim/lib/auth/constants.ts Resolved
Comment thread apps/sim/lib/auth/two-factor/guard.ts Resolved
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cubic-dev-ai review this PR

@cubic-dev-ai

cubic-dev-ai Bot commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai review this PR

@waleedlatif1 I have started the AI code review. It will take a few minutes to complete.

@cubic-dev-ai cubic-dev-ai 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.

No issues found across 15 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Turn on auto-fix | Re-trigger cubic

@waleedlatif1
waleedlatif1 merged commit efae888 into staging Dec 3, 2026
86 checks passed
@waleedlatif1
waleedlatif1 deleted the fix/two-factor-final-audit branch December 4, 2026 00:10

This branch was previously deployed

1 inactive deployment
Preview — 61b1565f Deployed Dec 3, 2026 by vercel[bot]
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