2FA setup required: the window of existing accounts starts once, at the first start after the upgrade

Owner's decision: for accounts that exist before the upgrade the 72 hours
count from the first start after it. The code already stamped them then; this
adds the tests that the moment is written once per account (a restart, two
instances starting at once, edits and logins do not move it; 71 h after it setup
is open, 73 h after it the account is blocked) and says so in the docs.

After the rebase on 1.16.5: tests that the setup-required notice and the stale
import-map notice both stand above the screen and never replace the code form,
and that requireSetup, safeBack and guard switch independently.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
This commit is contained in:
Radosław Smoliński
2026-11-24 18:56:07 +01:00
co-authored by Claude Fable 5.2
parent 5d44ac3135
commit 9d2ab43438
7 changed files with 191 additions and 6 deletions
+6 -1
View File
@@ -20,6 +20,8 @@ once there are more than 20.
account that never set 2FA up can be taken over by someone who learned its password.
- **Accounts that already exist** get their 72 hours from the **first start after the upgrade** (not from their
creation date), so nobody is blocked at the moment of the upgrade. The server log names how many there are.
That moment is written on each account once: later restarts, redeploys and further instances do not move it,
nor does editing the account. On Postgres / SQLite it is the first start with the migration applied.
### Added
- On every account in the panel: **Two-step verification** (sidebar) — set up / open until a date / blocked — and
@@ -40,7 +42,10 @@ once there are more than 20.
### Requires project changes
- **Before upgrading a live site:** `pnpm exec ipal-doctor --url <site>` → accounts without 2FA. Each sets 2FA up
now, or is removed. At least one administrator must have 2FA set up, or nobody can reopen setup from the panel.
- `pnpm payload generate:importmap` (commit `importMap.js`) and `pnpm payload generate:types`.
- `pnpm payload generate:importmap` (commit `importMap.js`) and `pnpm payload generate:types`, in the same
deploy as the upgrade (as for 1.16.5: a stale import map leaves the 2FA screens without a code form).
- **Plan the upgrade with the owner:** the 72 hours of every existing account without 2FA start at the deploy,
once. Deploy when those people can act within three days (not before a holiday), or have them set 2FA up first.
- **Postgres / SQLite:** `pnpm payload migrate:create` — the 2FA collection gets the column `totpSetupFrom`.
MongoDB: nothing.
- **An integration that logs in with a password and has no TOTP** stops working: give it an API key (passes as
+6 -2
View File
@@ -380,12 +380,14 @@ gets `403` from the same addresses and from `POST /api/setup-totp`. The Coolify
strips `back`, can keep them (`twoFactor.safeBack: false` turns the plugin's check off).
2. `pnpm ipal:skills`.
**→ the release after that — 2FA setup required (PROGRAMISTA §6, item 66; security.md "Setup required") — required
**→ the release with `twoFactor.requireSetup` — 2FA setup required (CHANGELOG "Unreleased — 2FA setup required"; PROGRAMISTA §6, item 68; security.md "Setup required") — required
with 2FA on:**
1. **Before upgrading a live site:** `pnpm exec ipal-doctor --url <site>` (doctor token) → accounts without 2FA.
Tell the owner: from the upgrade on, such an account can only set 2FA up, and has 72 hours for it; after that
an administrator must reopen setup on the account's page. Have them set it up now, or remove unused accounts.
Make sure at least one administrator has 2FA set up — otherwise nobody can reopen setup from the panel.
The 72 hours of existing accounts start at the first start after the deploy and are counted once (restarts
and redeploys do not extend them): agree the deploy day with the owner.
2. Update the package, `pnpm install`, `pnpm ipal:skills`, `pnpm payload generate:types`,
**`pnpm payload generate:importmap`** (new: `TwoFactorStatusField`, `TwoFactorAlert`; commit `importMap.js`).
3. Postgres/SQLite: `pnpm payload migrate:create` (adds `totpSetupFrom` to the 2FA collection), commit. MongoDB: nothing.
@@ -393,7 +395,9 @@ with 2FA on:**
`twoFactor.requireSetup: { exempt: ({ user }) => user.email === '…' }`. `grep -rn "overrideAccess: false" src`:
a `user` fetched by id is refused for every account now — take it from `payload.auth({ headers })`.
5. `rm -rf .next`, build, redeploy on Coolify. Read the first lines of the log: `[ipal] 2FA: N existing account(s)
without two-step verification…` — pass that number to the owner.
without two-step verification…` — pass that number to the owner. The line appears on that first start only.
Postgres/SQLite: the migration from step 3 must run in the same deploy; without it the log says
`could not start the setup window` and the window starts at the first start that has it.
**Check:** create a throwaway account → its token gets `403` from `/api/users/me`; in the panel it lands on the
setup screen with "Set up two-step verification by …"; after the code it is in. As an administrator open that
account → "Two-step verification: Set up." and the reset button; delete the account.
+8
View File
@@ -460,6 +460,14 @@ now to set it up…`. From that moment they can only set TOTP up; after 72 hours
administrator reopens setup. **Before upgrading a live site, run `pnpm exec ipal-doctor --url <site>`** (accounts
without 2FA) and have those accounts set TOTP up, or remove the ones nobody uses.
That starting moment is **written once**, on each such account (`totpSetupFrom`), by the start that first finds
the account without one. Later starts, redeploys and further instances find nothing left to do (the log line
appears on that first start only), and editing the account or logging in does not move it — so a redeploy never
hands out another 72 hours. Only an administrator's reset / "Reopen setup" opens a new window. An existing
account that **has** TOTP gets no start; if its TOTP is removed later, its window starts then. On Postgres /
SQLite "the first start" means the first start **with the migration applied**: before that there is no column
to write to, the log warns, and those accounts have no time limit yet.
```ts
twoFactor: {
issuer: 'Company Name',