2FA setup required: review round 2 — no SVG from the icon endpoint, migrations at container start
R2-1: /api/ipal/admin-icon answers with bytes only for a bitmap recognised by its first bytes (PNG, JPEG, GIF, WebP, ICO, AVIF). An SVG favicon keeps the redirect to the media file: a site-wide CSP rule overrides a route's own sandbox header, so the header alone protected nothing in a built site. buildUploadSecurityHeaders also returns a rule for the icon path, as a second layer. R2-2: the SQL migration runs when the new container starts (prodMigrations, or the start command), never in Coolify's pre-deployment command; docs and the log line say so and point to deployment.md 4.3. R2-3: requireSetup: null is the default. R2-4: the missing-column log line only for a column error. R2-5, R2-6: the resetAccess example keeps the code check; with guard: false the reset endpoint does not exist. Co-Authored-By: Claude Fable 5.2 <[email protected]>
This commit is contained in:
co-authored by
Claude Fable 5.2
parent
75a6f5209e
commit
01e3813723
+12
-6
@@ -479,7 +479,9 @@ twoFactor: {
|
||||
// requireSetup: { exempt: ({ user }) => user.email === '[email protected]' }, // a service account that logs in with a password, on purpose
|
||||
// requireSetup: { dashboardNotice: false, statusField: false, setupNotice: false }, // each panel part can be switched off; the lock stays
|
||||
// requireSetup: false, // the 2FA package's rule: redirect in the panel, API open until setup
|
||||
// resetAccess: ({ req }) => isAdmin(req.user, req.payload), // who may reset / reopen (default: a staff admin; the second factor is always required)
|
||||
// who may reset / reopen. Default: a staff admin whose session entered its own TOTP code. Your function replaces
|
||||
// that rule, so keep the code check in it unless you mean to let API-key / exempt admins reset:
|
||||
// resetAccess: ({ req }) => req.user?._strategy === 'totp' && isAdmin(req.user, req.payload),
|
||||
}
|
||||
```
|
||||
|
||||
@@ -487,8 +489,8 @@ twoFactor: {
|
||||
2FA is on** — also with `requireSetup: false` or `guard: false`, so that switching the mode does not change the
|
||||
schema — and, with the mode on, a panel-only field `totpSetupStatus`. MongoDB: nothing to do.
|
||||
**Postgres / SQLite: the migration is a required step of the same deploy.** Run `pnpm payload migrate:create`, commit the migration, and
|
||||
make sure it is applied (`pnpm payload migrate`, the Coolify pre-deploy command) **before the new version
|
||||
serves requests**. Without the column every query on the 2FA collection fails: **every login answers 500 —
|
||||
have it applied **when the new container starts** — `prodMigrations` in the database adapter, or the start command `pnpm payload migrate && pnpm start` ([deployment.md §4.3](./deployment.md#43-database-migrations-postgres)). **Not Coolify's Pre-deployment command:** it runs in the old container, which does not have the new migration, so the new version would start without the column.
|
||||
Without the column every query on the 2FA collection fails: **every login answers 500 —
|
||||
administrators with 2FA included — and nobody can sign in to the panel** (the public site keeps working). The
|
||||
log says `[ipal] 2FA: the column for "totpSetupFrom" is missing … NOBODY CAN LOG IN …` at start;
|
||||
`ipal-doctor` reports a SQL project whose migrations do not mention `totp_setup_from` (error; a warning when
|
||||
@@ -525,8 +527,8 @@ twoFactor: {
|
||||
**The brand on the setup and verify screens.** A session that still owes its code is refused `media` like every
|
||||
other collection, so the browser could not load the panel's logo or tab icon from it. The plugin therefore hands
|
||||
such a session the picture itself — fetched on the server without any credentials, exactly as an anonymous visitor
|
||||
gets it (`AdminLogo` / `AdminIcon` as a `data:` address; `GET /api/ipal/admin-icon` always answers with the image
|
||||
instead of a redirect). Nothing is opened by this: when `media` is not publicly readable, or the file is larger
|
||||
gets it (`AdminLogo` / `AdminIcon` as a `data:` address; `GET /api/ipal/admin-icon` answers with the image
|
||||
instead of a redirect when the favicon is a bitmap — never with an SVG, which keeps the redirect). Nothing is opened by this: when `media` is not publicly readable, or the file is larger
|
||||
than 512 KB, the site name (or the browser's own attempt) is used instead.
|
||||
|
||||
**What it does not do.** Inside the window, someone who knows the password of an account that has not set TOTP up
|
||||
@@ -786,12 +788,16 @@ show the QR code. `back=null` or a page that keeps reloading means the import ma
|
||||
An admin resets another user's 2FA (a lost phone) or reopens setup for a blocked account on that account's page
|
||||
in the panel: **Two-step verification** in the sidebar → "Reset two-step verification" / "Reopen setup". Behind
|
||||
it: `POST /api/ipal/two-factor/reset` `{ userId }`. The account must set TOTP up again within a new window.
|
||||
The endpoint comes with ipal-kit's own check: with `twoFactor.guard: false` it does not exist (404), and neither
|
||||
does the control in the panel.
|
||||
|
||||
- **Who may reset.** By default a staff admin whose session has **entered its own TOTP code**. An admin on an API
|
||||
key, and an admin that `requireSetup.exempt` lets work on its password, are refused: removing someone's second
|
||||
factor should take one. `twoFactor.resetAccess: ({ req }) => boolean` replaces the rule; a session that still
|
||||
owes its code is refused whatever the function says, and only an answer of exactly `true` allows
|
||||
(`req.user._strategy` is `'totp'`, `'api-key'` or `'local-jwt'`).
|
||||
(`req.user._strategy` is `'totp'`, `'api-key'` or `'local-jwt'`). Example that keeps the default's strength and
|
||||
narrows it to one address: `({ req }) => req.user?._strategy === 'totp' && req.user.email === 'owner@example.com'`.
|
||||
`({ req }) => isAdmin(req.user, req.payload)` alone would let an API-key or exempt admin reset.
|
||||
- **A reset ends the account's sessions.** Every token of that account stops working at once; its owner logs
|
||||
in again with the password and sets TOTP up. This matters when the account may be in someone else's hands: a
|
||||
session that had passed 2FA could otherwise enrol a new authenticator without the password (`/api/setup-totp`
|
||||
|
||||
Reference in New Issue
Block a user