feat: two-factor sign-in, required for sensitive permissions #12

Merged
dhkatz merged 1 commits from feat/two-factor into main 2026-11-06 03:23:03 +00:00
Owner

Phase 3d (docs/design.md): two-factor sign-in, required for sensitive permissions.

  • Sign-in: Better Auth's twoFactor plugin, using an authenticator app (TOTP) with 10 backup codes. Once it's on, signing in asks for a code from the app or a backup code, and each backup code works once.
  • Account page: a new Two-Factor Sign-In card.
    • To turn it on: enter your password, scan the QR code (the key is also shown as text), keep the backup codes, and confirm with a code.
    • Once it's on, you can make new backup codes or turn it off; both ask for the password.
    • If you hold sensitive permissions, the card lists the ones that need it.
  • Enforcement: the sensitive permissions are product:remove, person:ban, person:role, audit:read-sensitive, catalog:transfer, catalog:suspend, import:grant-on-behalf and settings:edit (permissions.ts sensitive). Without two-factor on, they answer 403 two_factor_required, and API tokens get the same check through their owner.
    • Routes guarded only by the moderator check now also check the permission: removing products, ban and unban, roles, and settings.
  • Console: a reminder on every console page while two-factor is needed. The People list notes staff without two-factor, and each person's page shows "two-factor on".
  • Closed Better Auth admin endpoints: /api/auth/admin/* now answers 404. Admins could have used these endpoints to ban people or change roles without the check or the audit log.
  • Tests: a new end-to-end test, test/two-factor.test.ts. Moderation tests turn two-factor on for their accounts directly (test/two-factor.ts). All 57 API tests pass, and type checks pass.
  • Checked on the scratch hub through the website:
    • turning it on with a real code
    • the console reminder appearing and disappearing
    • signing in again needing a code
    • a Ban form while two-factor is off showing "Turn on two-factor sign-in on your account page first."
  • Not checked in a browser: the QR and sign-in code screens.
  • Dependency: uqr draws the QR code; it has no dependencies of its own.

Later: auditing when two-factor is turned on or off, and an optional "trust this browser".

🤖 Generated with Claude Code

Phase 3d (docs/design.md): two-factor sign-in, required for sensitive permissions. - **Sign-in:** Better Auth's `twoFactor` plugin, using an authenticator app (TOTP) with 10 backup codes. Once it's on, signing in asks for a code from the app or a backup code, and each backup code works once. - **Account page:** a new Two-Factor Sign-In card. - To turn it on: enter your password, scan the QR code (the key is also shown as text), keep the backup codes, and confirm with a code. - Once it's on, you can make new backup codes or turn it off; both ask for the password. - If you hold sensitive permissions, the card lists the ones that need it. - **Enforcement:** the sensitive permissions are `product:remove`, `person:ban`, `person:role`, `audit:read-sensitive`, `catalog:transfer`, `catalog:suspend`, `import:grant-on-behalf` and `settings:edit` (`permissions.ts` `sensitive`). Without two-factor on, they answer 403 `two_factor_required`, and API tokens get the same check through their owner. - Routes guarded only by the moderator check now also check the permission: removing products, ban and unban, roles, and settings. - **Console:** a reminder on every console page while two-factor is needed. The People list notes staff without two-factor, and each person's page shows "two-factor on". - **Closed Better Auth admin endpoints:** `/api/auth/admin/*` now answers 404. Admins could have used these endpoints to ban people or change roles without the check or the audit log. - **Tests:** a new end-to-end test, `test/two-factor.test.ts`. Moderation tests turn two-factor on for their accounts directly (`test/two-factor.ts`). All 57 API tests pass, and type checks pass. - **Checked on the scratch hub through the website:** - turning it on with a real code - the console reminder appearing and disappearing - signing in again needing a code - a Ban form while two-factor is off showing "Turn on two-factor sign-in on your account page first." - **Not checked in a browser:** the QR and sign-in code screens. - **Dependency:** `uqr` draws the QR code; it has no dependencies of its own. Later: auditing when two-factor is turned on or off, and an optional "trust this browser". 🤖 Generated with [Claude Code](https://claude.com/claude-code)
dhkatz added 1 commit 2026-11-06 03:18:17 +00:00
feat: two-factor sign-in, required for sensitive permissions
Pull request / title (pull_request) Successful in 2s
CI / test (pull_request) Successful in 1m11s
CI / image (apps/api/Dockerfile, t5de-hub-api) (pull_request) Skipped
CI / image (apps/web/Dockerfile, t5de-hub-web) (pull_request) Skipped
d5bc792190
Better Auth's twoFactor plugin: an authenticator app (TOTP) with 10 backup codes.
Turning it on, making new backup codes and turning it off are on the account page,
and signing in asks for a code once it's on. Sensitive permissions (product:remove,
person:ban, person:role, settings:edit, catalog:suspend, ...) answer 403
two_factor_required without it, API tokens included; the console reminds people
who need it. Better Auth's own admin endpoints are closed (404).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
dhkatz merged commit eca1884918 into main 2026-11-06 03:23:03 +00:00
dhkatz deleted branch feat/two-factor 2026-11-06 03:23:03 +00:00
Sign in to join this conversation.
No Reviewers
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: t5de/t5de-hub#12