2FA back link: the stale import-map notice never replaces the screen
R2-1: the notice was rendered instead of the 2FA screen, and its flag is a text search of the importMap.js on disk — not the map in the build. A false alarm (map generated in the build with the repository's file in the running image, a re-exporting map) hid a working code form and locked everyone out. The notice is now rendered above the screen, the log line says "may be", and the flag goes to ipal-kit's own provider only. R2-2: views are compared against copies, so a factory that reuses its view objects is guarded too; copyViews, changedViewKeys, SAFE_TOTP_VIEW, totpViewImportKey, findImportMapFile and missingImportMapEntries are exported; ipal-doctor warns when the config registers the 2FA package's own view; docs wording and a misplaced comment fixed. Co-Authored-By: Claude Fable 5.2 <[email protected]>
This commit is contained in:
co-authored by
Claude Fable 5.2
parent
ad51456eaa
commit
b2c1dca5da
+13
-6
@@ -31,8 +31,14 @@ once there are more than 20.
|
||||
- **ipal-doctor**: the import-map rule also expects `@intecion/ipal-kit/admin#SafeTotpView` when the installed
|
||||
plugin has it and the config does not set `safeBack: false`.
|
||||
- **A stale import map is reported** (`twoFactor.importMapCheck`, on by default, `false` turns it off): in
|
||||
production the plugin reads the committed `importMap.js` at start; when the entry above is missing it logs an
|
||||
error and the 2FA screens show a message instead of staying empty.
|
||||
production the plugin searches the `importMap.js` on disk at start; when the entry above is not found it logs
|
||||
an error and puts a notice above the 2FA screens. The notice never replaces the screen: the file on disk is
|
||||
not always the map the build used (a Dockerfile with a separate runner stage, a re-exporting map file), and
|
||||
then the notice is wrong and sign-in still works — turn the check off for such a project.
|
||||
- **More building blocks exported** for a project that wraps the 2FA views itself: `copyViews`,
|
||||
`changedViewKeys`, `SAFE_TOTP_VIEW`, `totpViewImportKey`, `findImportMapFile`, `missingImportMapEntries`.
|
||||
- **ipal-doctor** warns when the config registers the 2FA package's own setup / verify view directly (such a
|
||||
view is outside the check).
|
||||
- **A project's own 2FA screen set through the wrapped factory** (a server or a client component) is rendered
|
||||
behind the check and gets the checked `back`.
|
||||
|
||||
@@ -40,10 +46,11 @@ once there are more than 20.
|
||||
- **Every site with 2FA: `pnpm payload generate:importmap`, commit `importMap.js`, `rm -rf .next`, redeploy —
|
||||
in the same deploy as the upgrade.** The plugin's view now stands in front of the package's two screens and
|
||||
needs its import-map entry (`@intecion/ipal-kit/admin#SafeTotpView`). **If you skip this, the build still
|
||||
passes and the site starts, but the 2FA setup and verify screens come back **empty** (HTTP 200, no code form), so nobody can sign in to the panel.** There is no error page. What tells you: `pnpm exec ipal-doctor`
|
||||
before the deploy (`import map lacks …SafeTotpView`), the line `[ipal] The admin import map is out of date` in
|
||||
the log at every start, and a message on the 2FA screens instead of an empty page ("Two-step verification is
|
||||
not available"). No option, env, schema or migration.
|
||||
passes and the site starts, but the 2FA setup and verify screens have no code form (HTTP 200), so nobody can
|
||||
sign in to the panel.** There is no error page. What tells you: `pnpm exec ipal-doctor` before the deploy
|
||||
(`import map lacks …SafeTotpView`); the line `[ipal] The admin import map may be out of date` in the log at
|
||||
every start; and, where the form should be, the notice "Two-step verification may not be available". No
|
||||
option, env, schema or migration.
|
||||
- **Check after deploy:** log in with the password only, open
|
||||
`/admin/verify-totp?back=https%3A%2F%2Fexample.com%2F`, enter the code → you land on `/admin`. A normal login
|
||||
still returns to the page you came from.
|
||||
|
||||
+1
-1
@@ -1167,7 +1167,7 @@ add missing hosts with flags / `extra`; (3) change `mode` to `'enforce'` in both
|
||||
| 2FA on the panel's login collection, mismatch = startup error; redirect to the 2FA screens by `TotpRedirectProvider` | `twoFactor: false` (discouraged) | `twoFactor.collectionSlug`, `allowCollectionMismatch: true`, `twoFactor.provider` (own component, or `false` for the package's) |
|
||||
| The second factor on every collection and global, whichever plugin added it, and on the plugin's endpoints; an unrecognised 2FA package = startup error | per entity: `custom.ipal.secondFactor: false` or `{ read: false }` (or the package's `custom.totp.disableAccessWrapper`); everywhere: `twoFactor.guard: false` (not recommended) | `requireSecondFactor` / `secondFactorPassed` in your own access functions and endpoints |
|
||||
| At most 5 verify attempts per account in 10 minutes (`POST /api/verify-totp` → `429`) | `twoFactor.verifyLimit: false` | `verifyLimit: { max, windowMinutes }` |
|
||||
| The `back` link of the 2FA setup and verify screens is checked on the server (`SafeTotpView` in front of the package's views): only a path on the site's origin inside the admin route is kept, anything else (`javascript:`, another host) becomes the admin root. Needs `generate:importmap` in the same deploy — with a stale map the 2FA screens are empty and nobody can sign in (`ipal-doctor`, the start log and a message on the screen report it; `twoFactor.importMapCheck: false` silences that); check: password only → `/admin/verify-totp?back=https%3A%2F%2Fexample.com%2F` → code → lands on `/admin` | `twoFactor.safeBack: false` | `safeBack: (back, { adminRoute, origin }) => string`; `safeAdminBack`, `wrapTotpViews` (`@intecion/ipal-kit`), `SafeTotpView` (`@intecion/ipal-kit/admin`) for own views |
|
||||
| The `back` link of the 2FA setup and verify screens is checked on the server (`SafeTotpView` in front of the package's views): only a path on the site's origin inside the admin route is kept, anything else (`javascript:`, another host) becomes the admin root. Needs `generate:importmap` in the same deploy — with a stale map the 2FA screens have no code form and nobody can sign in (`ipal-doctor`, the start log and a notice above the screen report it; the notice is a hint from the file on disk and never replaces the screen; `twoFactor.importMapCheck: false` turns it off); check: password only → `/admin/verify-totp?back=https%3A%2F%2Fexample.com%2F` → code → lands on `/admin` | `twoFactor.safeBack: false` | `safeBack: (back, { adminRoute, origin }) => string`; `safeAdminBack`, `wrapTotpViews` (`@intecion/ipal-kit`), `SafeTotpView` (`@intecion/ipal-kit/admin`) for own views |
|
||||
| The 2FA package's endpoints (`/api/setup-totp`, `verify-totp`, `remove-totp`, `admin/*`) answer accounts of the 2FA collection only; reset and remove need the second factor | — (always on with 2FA) | `adminManageAccess` through the wrapped factory (security.md "Resetting 2FA") |
|
||||
| Roles count only for accounts of a staff collection, in every predicate and access function | — | `access.staffCollections` |
|
||||
| `enabled: false` keeps the schema | — | — (no endpoints, `onInit` or admin components; no DROP TABLE in `migrate:create`) |
|
||||
|
||||
@@ -58,7 +58,8 @@ through this procedure. Ask only when you are missing something you cannot get y
|
||||
| Symptom | Cause | Fix |
|
||||
|---|---|---|
|
||||
| `PayloadComponent not found in importMap` (e.g. `@intecion/ipal-kit/admin#RowLabel`) | importMap out of date after a plugin update / adding `rowLabel` | `pnpm payload generate:importmap`, restart |
|
||||
| after an upgrade the 2FA setup / verify screen is **empty** (HTTP 200, no code form) or says "Two-step verification is not available"; nobody can sign in; the log has `[ipal] The admin import map is out of date` and `getFromImportMap: PayloadComponent not found in importMap … @intecion/ipal-kit/admin#SafeTotpView` | the import map was not regenerated after the upgrade that added the `back` link check (`twoFactor.safeBack`); the production build uses the committed, old `importMap.js` | `pnpm payload generate:importmap`, commit `importMap.js`, `rm -rf .next`, redeploy; `pnpm exec ipal-doctor` shows it before a deploy. The opposite case (wrapper present, package view missing) throws `[ipal] The admin import map has no "@clocklimited/payload-2fa/rsc#TOTPVerify"` — same fix |
|
||||
| after an upgrade the 2FA setup / verify screen has no code form (HTTP 200), only the notice "Two-step verification may not be available" (or nothing at all with `importMapCheck: false` / an own provider); nobody can sign in; the log has `[ipal] The admin import map may be out of date` and `getFromImportMap: PayloadComponent not found in importMap … @intecion/ipal-kit/admin#SafeTotpView` | the import map was not regenerated after the upgrade that added the `back` link check (`twoFactor.safeBack`); the production build uses the committed, old `importMap.js` | `pnpm payload generate:importmap`, commit `importMap.js`, `rm -rf .next`, redeploy; `pnpm exec ipal-doctor` shows it before a deploy. The opposite case (wrapper present, package view missing) throws `[ipal] The admin import map has no "@clocklimited/payload-2fa/rsc#TOTPVerify"` — same fix |
|
||||
| the notice "Two-step verification may not be available" and the log line `[ipal] The admin import map may be out of date` appear, but the code form is there and sign-in works | false alarm: the check searches the `importMap.js` on disk, which is not the map inside the build (map generated during the build and a Dockerfile runner stage that copies the repository's file; a map file that re-exports or computes its entries) | `twoFactor: { …, importMapCheck: false }`; or ship the generated `importMap.js` in the image |
|
||||
| an own 2FA screen (set through the wrapped factory) ignores the check on `back` | a client component reading `useSearchParams()` gets the raw query value | read the `back` prop (or `searchParams.back`) the wrapper passes — both are checked (security.md "Your own 2FA screen") |
|
||||
| after the 2FA code the user lands on `/admin` instead of the page in `back` | `back` pointed outside the admin route or to another origin (the check keeps only a path inside `routes.admin`; an absolute URL only on the `serverURL` origin) | expected; for another rule pass `twoFactor.safeBack: (back, { adminRoute, origin }) => string` (security.md) |
|
||||
| new admin stuck on `/admin/setup-totp?back=null` (the page keeps redirecting to itself) | ipal-kit ≤ 1.14.1: the 2FA package's provider needs an `x-pathname` header nothing sets on `/admin`; or `twoFactor.provider: false` without that header | update ipal-kit, `pnpm payload generate:importmap` (`TotpRedirectProvider`), restart; check: `/admin/setup-totp?back=%2Fadmin` shows the QR (security.md) |
|
||||
|
||||
@@ -38,7 +38,7 @@ description: Complete map of everything @intecion/ipal-kit provides — every ip
|
||||
| `twoFactor.collectionSlug` | the panel's login collection (`admin.user`, else the first auth collection) | collection with 2FA; startup fails with `[ipal] twoFactor…` when it is not an auth collection or differs from `admin.user` | point it at the login collection |
|
||||
| `twoFactor.provider` | `'@intecion/ipal-kit/admin#TotpRedirectProvider'` | admin provider that sends users to `setup-totp` / `verify-totp` (path read in the browser); replaces the package's header-based one | own component path / `{ path, clientProps, serverProps }` (gets clientProps `forceSetup`); `false` keeps the package's (needs `x-pathname` on `/admin`, else `setup-totp?back=null` loops) |
|
||||
| `twoFactor.safeBack` | on | the `back` query value of the 2FA setup and verify screens is checked on the server before the package's view gets it (`SafeTotpView` registered in place of the package's four views): kept only as a path on the site's origin inside `routes.admin`, else the admin root — no `javascript:` / off-site redirect after the code. Needs `generate:importmap` (`@intecion/ipal-kit/admin#SafeTotpView`) | `false` = the package's views untouched; a function `(back, { adminRoute, origin }) => string` = your own rule |
|
||||
| `twoFactor.importMapCheck` | on | production only: at start reads the committed `importMap.js` (where Payload looks for it); when `@intecion/ipal-kit/admin#SafeTotpView` is missing, logs `[ipal] The admin import map is out of date …` and the 2FA screens show "Two-step verification is not available" instead of staying empty. A file that cannot be found is not reported | `false` = no file read, log line or message |
|
||||
| `twoFactor.importMapCheck` | on | production only: at start searches the `importMap.js` on disk (where Payload looks for it) for `@intecion/ipal-kit/admin#SafeTotpView`; when not found, logs `[ipal] The admin import map may be out of date …` and ipal-kit's `TotpRedirectProvider` puts the notice "Two-step verification may not be available" above the 2FA screens (never instead of them). A hint only — the map in the build can differ from the file on disk (Dockerfile runner stage, re-exporting map); a file that is not found is not reported | `false` = no file read, log line or notice |
|
||||
| `twoFactor.texts` | ipal-kit's en/pl texts (`TOTP_TEXTS`) over the package's; 2FA screens titled "Two-step verification" / "Weryfikacja dwuetapowa" (site's language) | `false` = the package's texts; one text: `i18n.translations.<lang>.totpPlugin.<key>` (security.md) |
|
||||
| `twoFactor.guard` | on | ipal-kit's own second-factor check on every collection and global (also the plugin's own and those of plugins listed after ipalKit) and in `userMeetsRole`; startup fails with `[ipal] twoFactor: the injected 2FA plugin did not add …` when the 2FA package lacks the `totp` strategy / `hasTotp` / `totpSecret` | per entity: `custom.ipal.secondFactor: false` / `{ read: false }` or the package's `custom.totp.disableAccessWrapper.<op>`; `false` = the package's wrapper only (the plugin's own data then opens to a password without the code; not recommended). The package's endpoints stay limited to accounts of the 2FA collection either way |
|
||||
| `twoFactor.verifyLimit` | `{ max: 5, windowMinutes: 10 }` | attempts per account on `POST /api/verify-totp` (the 2FA package counts none): the sixth in the window, right or wrong, gets `429` + `Retry-After`; in memory per instance | `{ max, windowMinutes }`; `false` = no limit |
|
||||
|
||||
@@ -69,7 +69,7 @@ Admin panel components from `@intecion/ipal-kit/admin` — the project does NOT
|
||||
| `buildRolesField(defaultRole?, { firstUserAdmin? })` | `@intecion/ipal-kit` | The `roles` select field the plugin injects (only admins set roles; `firstUserAdmin` default `true` = the account made on "Create first user" gets `admin`). The plugin wires it itself — use it only for an auth collection the plugin does not manage. |
|
||||
| `injectRoles(config, accessOption)` | `@intecion/ipal-kit` | Adds `roles` to `accessOption.authCollection` in a config. The plugin calls it itself with `access` — do not call. |
|
||||
|
||||
**Types:** `VerifyLimitOptions` (`twoFactor.verifyLimit`: `{ max?, windowMinutes? }`), `SafeBackRule` / `SafeBackContext` (`twoFactor.safeBack` as a function: `(back, { adminRoute, origin? }) => string`), `SafeTotpViewProps` (`@intecion/ipal-kit/admin`), `Role` (`'user' \| 'editor' \| 'admin'`), `AccessOption` (the plugin's `access` option: `authCollection`, `defaultRole`, `authAccess`, `firstUserAdmin`, `staffCollections`).
|
||||
**Types:** `VerifyLimitOptions` (`twoFactor.verifyLimit`: `{ max?, windowMinutes? }`), `SafeBackRule` / `SafeBackContext` (`twoFactor.safeBack` as a function: `(back, { adminRoute, origin? }) => string`), `TotpViewComponent` (a view component as registered: a path or `{ path, exportName?, clientProps?, serverProps? }`), `SafeTotpViewProps` (`@intecion/ipal-kit/admin`), `Role` (`'user' \| 'editor' \| 'admin'`), `AccessOption` (the plugin's `access` option: `authCollection`, `defaultRole`, `authAccess`, `firstUserAdmin`, `staffCollections`).
|
||||
|
||||
## Accessibility — widget (`accessibility`) — details: `node_modules/@intecion/ipal-kit/docs/accessibility.md`
|
||||
|
||||
@@ -589,6 +589,9 @@ Server only (`pnpm payload run`); never import it from client code, the Payload
|
||||
| `secondFactorPassed(req)` | `@intecion/ipal-kit` | `boolean` with `req` (`{ payload, user }`): `false` only for an account of the 2FA collection that has TOTP set up and has not entered the code in this session (password only). `true` for a full login, an API key, an account that has not set TOTP up yet, accounts of other auth collections, no user, and with `twoFactor: false`. Guard your own endpoints with it: `if (!req.user \|\| !secondFactorPassed(req)) return 403`. |
|
||||
| `safeAdminBack(back, { adminRoute, origin? })` | `@intecion/ipal-kit` | The default `back` rule of the 2FA screens: returns `back` as a path when it resolves to the site's origin (the placeholder origin for relative values, `origin` for absolute ones), over HTTP(S), without credentials, inside `adminRoute`; otherwise the admin root. `safeAdminBack('javascript:alert(1)', { adminRoute: '/admin' })` → `'/admin'`; `safeAdminBack('/admin/collections/pages?page=2', { adminRoute: '/admin' })` → the same path. Use it in your own rule or view. |
|
||||
| `wrapTotpViews(views, added, rule?, wrapper?)` | `@intecion/ipal-kit` | Puts `SafeTotpView` in front of the views whose route is `setup-totp` / `verify-totp` and for which `added(key)` is true (keeps `exportName`, `serverProps`; `clientProps` travel as `ipalTotpClientProps`); returns `{ views, dependencies }` (`dependencies` → `admin.dependencies`, so the wrapped views stay in the import map). What `ipalKit` runs after the 2FA factory; for a project that registers the 2FA package itself. |
|
||||
| `copyViews(views)` / `changedViewKeys(before, after)` | `@intecion/ipal-kit` | The comparison `ipalKit` uses to tell which views a 2FA factory registered: put `copyViews(views)` into the config before calling the factory, then `changedViewKeys(before, viewsAfter)` gives the keys whose view object changed — the `added` argument of `wrapTotpViews` (`(key) => keys.has(key)`). By object, not by key: the 2FA package replaces a view that already stands under its keys. Example: security.md "Your own 2FA screen". |
|
||||
| `SAFE_TOTP_VIEW` / `totpViewImportKey(component)` | `@intecion/ipal-kit` | `'@intecion/ipal-kit/admin#SafeTotpView'`, the wrapper's import-map path (the default `wrapper` of `wrapTotpViews`); and the import-map key (`path#export`) of a component given as a string or `{ path, exportName }`. |
|
||||
| `findImportMapFile(config, cwd?)` / `missingImportMapEntries(config, entries, cwd?)` | `@intecion/ipal-kit` | Where the project's `importMap.js` is on disk (`admin.importMap.importMapFile`, else `app/(payload)<admin route>/` or `src/app/…` under `admin.importMap.baseDir` / the working directory; `null` when not found), and which of `entries` its text does not contain (`{ file, missing }`). A hint from the file on disk, not the map in the build: warn on it, never block on it. Behind `twoFactor.importMapCheck`. |
|
||||
| `requireSecondFactor(access?)` | `@intecion/ipal-kit` | Wraps an `Access` function: refused while the second factor is owed, otherwise the function itself (Payload's default "logged in" when none). ipalKit applies it to every collection and global in the config, and to those added by plugins listed after it (in `onInit` and at the start of the first request, so also after a dev hot reload); use it for access functions that are not part of the config. Per-entity opt-out: `custom.ipal.secondFactor: false \| { read: false }` or the package's `custom.totp.disableAccessWrapper`. Wrapping twice is harmless. |
|
||||
| `totpRedirectTarget({ adminRoute, forceSetup?, pathname, user, excludePaths? })`, `totpAdminPath(adminRoute, path)` | `@intecion/ipal-kit` | The 2FA redirect rules as pure functions: the setup / verify URL (with `back`) to send this user to, or `null` (no path, api key, already on a TOTP screen or logout). For an own `twoFactor.provider`. Types `TotpRedirectArgs`, `TotpUser` |
|
||||
| `buildCsp({ mode?, reportUri?, reportGroup?, r2Url?, analytics?, metaPixel?, linkedIn?, tiktok?, clarity?, turnstile?, youtube?, googleMaps?, nonce?, strictDynamic?, dev?, extra?, override? })` | `@intecion/ipal-kit` | Returns `{ key, value }` with a hardened CSP (`base-uri`, `object-src`, `frame-ancestors`, `form-action`) + sources for the enabled integrations. `mode: 'report-only'` → `…-Report-Only` (start here), `'enforce'` later. `extra` adds to any directive, `override` replaces / drops one (`null`). `dev` (default `NODE_ENV === 'development'`) adds `'unsafe-eval'`. `nonce` → `'nonce-…' 'strict-dynamic'`. |
|
||||
|
||||
@@ -228,8 +228,9 @@ the panel shows Site settings, Site integrations, Cookies, Form messages, the Fo
|
||||
The `back` link of the setup and verify screens is checked on the server (`twoFactor.safeBack`, on by default:
|
||||
only a path inside the admin route is kept; `false` turns it off, a function replaces the rule). It needs the
|
||||
import map entry `@intecion/ipal-kit/admin#SafeTotpView` — run `pnpm payload generate:importmap` and commit
|
||||
(a production build with a map that lacks it shows empty 2FA screens: nobody can sign in; `ipal-doctor` and the
|
||||
start log report it, `twoFactor.importMapCheck: false` turns that report off).
|
||||
(a production build with a map that lacks it shows 2FA screens without a code form: nobody can sign in;
|
||||
`ipal-doctor`, the start log and a notice above the screen report it; `twoFactor.importMapCheck: false` turns the
|
||||
log line and the notice off — needed when the `importMap.js` on disk is not the one the build used).
|
||||
Check: password only → `/admin/verify-totp?back=https%3A%2F%2Fexample.com%2F` → code → you land on `/admin`.
|
||||
**Set 2FA up right after creating an account** (log in as it, scan the code): until then its password alone
|
||||
opens everything its role allows. One entity reachable without the code: `custom.ipal.secondFactor`.
|
||||
|
||||
@@ -142,10 +142,13 @@ panel opens and a document saves.
|
||||
1. **Do this in the same deploy as the upgrade, or the panel is locked for everyone.**
|
||||
`pnpm payload generate:importmap` — the plugin puts `@intecion/ipal-kit/admin#SafeTotpView` in front of the
|
||||
2FA package's setup and verify views; commit `importMap.js`, `rm -rf .next`, redeploy on Coolify. With the old
|
||||
import map the build passes and the site starts, but the 2FA screens are **empty** (HTTP 200, no code form) —
|
||||
nobody can sign in. Signs: `pnpm exec ipal-doctor` → `import map lacks …SafeTotpView` (run it before deploying);
|
||||
the log line `[ipal] The admin import map is out of date` at start; the screen says "Two-step verification is
|
||||
not available". Fix: the same command, commit, redeploy.
|
||||
import map the build passes and the site starts, but the 2FA screens have no code form (HTTP 200) — nobody can
|
||||
sign in. Signs: `pnpm exec ipal-doctor` → `import map lacks …SafeTotpView` (run it before deploying); the log
|
||||
line `[ipal] The admin import map may be out of date` at start; the notice "Two-step verification may not be
|
||||
available" where the form should be. Fix: the same command, commit, redeploy.
|
||||
The log line and the notice with a **working** code form mean a false alarm (the `importMap.js` on disk is not
|
||||
the one the build used — a Dockerfile runner stage, a re-exporting map): sign-in works; set
|
||||
`twoFactor.importMapCheck: false`.
|
||||
**Check:** log in with the password only → open `/admin/verify-totp?back=https%3A%2F%2Fexample.com%2F` → enter
|
||||
the code → you land on `/admin` (not on example.com); a normal login still returns to the page you came from.
|
||||
No option, env, schema or migration. A project that registered its own 2FA views, or wrote a proxy rule that
|
||||
|
||||
+1
-1
@@ -89,7 +89,7 @@ Turn off: `ipalKit({ doctor: false })`. Adapt: `ipalKit({ doctor: { tokenVar: 'M
|
||||
| | `layout-forbidden` | error | no `middleware.ts`, no `lib/{pages,locales,navigation}.ts`, `fields/{link,sectionHeader,sectionSettings}.ts` |
|
||||
| | `layout-extra` | info | `src/` entries outside the allow list (AGENT.md §3 + `seed/`, `design/`, `db.ts`, `env.rules.ts`, `content.config.ts`; extend with `layout.allow`) |
|
||||
| | `naming` | warning | block folders, collection and global files PascalCase, `scripts/*` kebab-case, no `index.ts` barrels |
|
||||
| | `importmap` | error | the import map exists, holds the entries for what the config turns on (2FA, R2, cookie scanner, `adminMeta`), names no export the plugin no longer has; with `--deep`, equals a fresh one |
|
||||
| | `importmap` | error | the import map exists, holds the entries for what the config turns on (2FA, R2, cookie scanner, `adminMeta`), names no export the plugin no longer has; with `--deep`, equals a fresh one. Warning: the config registers the 2FA package's own setup / verify view directly (outside the `back` link check — security.md) |
|
||||
| | `tsconfig-skills` | error | `tsconfig.json` excludes the skills folder |
|
||||
| env | `db-name` | error | `DATABASE_URI` in `.env` and `.env.example` names `<domain without dots>_dev`; a local `.env` on `_prod` is an error; `--env-file` checks `_prod` (`databaseNamesFor`) |
|
||||
| | `env-rules` | error / warning | `instrumentation.ts` calls `assertEnv(ipalEnvRules(…))` from `/env`, with `storage` (R2), `cookieCrawl` (crawl), `ipHeader`; `databaseName` suggested (info) |
|
||||
|
||||
+38
-14
@@ -610,23 +610,46 @@ guarded. The same holds when the project also lists `payloadTotp(...)` in `plugi
|
||||
your `clientProps`, and `back` plus `searchParams` — both checked; read `back` from the props, not from
|
||||
`useSearchParams()`, which still holds the raw query value.
|
||||
- From a plugin listed after `ipalKit`, or under another key or route: that view is yours and is not wrapped. Use
|
||||
`wrapTotpViews` or `safeAdminBack` in it.
|
||||
`wrapTotpViews` or `safeAdminBack` in it. `ipal-doctor` warns when the config names the package's own view
|
||||
(`@clocklimited/payload-2fa/rsc#TOTPVerify` / `#TOTPSetup`) directly.
|
||||
|
||||
Wrapping views yourself, for a project that runs the 2FA package without `ipalKit`'s `twoFactor` (all from
|
||||
`@intecion/ipal-kit`):
|
||||
```ts
|
||||
const before = copyViews(config.admin?.components?.views) // copies: the factory's views are then never "the same object"
|
||||
config = await payloadTotp(options)({ ...config, admin: { ...config.admin, components: { ...config.admin?.components, views: before } } })
|
||||
const fromPackage = changedViewKeys(before, config.admin?.components?.views ?? {}) // by object — the package replaces views under its keys
|
||||
const { dependencies, views } = wrapTotpViews(config.admin?.components?.views ?? {}, (key) => fromPackage.has(key), undefined)
|
||||
config.admin = { ...config.admin, components: { ...config.admin?.components, views }, dependencies: { ...config.admin?.dependencies, ...dependencies } }
|
||||
```
|
||||
`SAFE_TOTP_VIEW` is the wrapper's import-map path; `findImportMapFile` / `missingImportMapEntries` are the
|
||||
stale-map check below (a hint from the file on disk — warn on it, never block on it).
|
||||
|
||||
**A stale import map (read this before upgrading a site with 2FA).** The check needs the import-map entry
|
||||
`@intecion/ipal-kit/admin#SafeTotpView`. A production build made with the import map of the previous version
|
||||
passes, the site starts, and the 2FA setup and verify screens come back **empty** (HTTP 200, no code form), so nobody can sign in to the panel. Payload renders nothing for a path its map lacks; the only trace is
|
||||
passes and the site starts, but Payload renders nothing for a path its map lacks: the 2FA setup and verify
|
||||
screens have no code form (HTTP 200), so nobody can sign in to the panel. Payload's only trace is
|
||||
`getFromImportMap: PayloadComponent not found in importMap` in the server log. Development is not affected (Payload
|
||||
regenerates the map there). ipal-kit makes this loud in three places:
|
||||
regenerates the map there). ipal-kit reports it in three places:
|
||||
- **Before deploy:** `pnpm exec ipal-doctor` reports `import map lacks @intecion/ipal-kit/admin#SafeTotpView` (error).
|
||||
- **At every start in production:** the log has `[ipal] The admin import map is out of date: … The 2FA setup and
|
||||
verify screens are EMPTY …`.
|
||||
- **On the screen:** instead of nothing, the 2FA screens say "Two-step verification is not available" and what a
|
||||
developer has to run (shown by `TotpRedirectProvider`; with your own `twoFactor.provider` it gets the clientProp
|
||||
`staleImportMap`, with `provider: false` there is only the log line).
|
||||
The check reads `importMap.js` where Payload looks for it (`admin.importMap.importMapFile`, else
|
||||
`app/(payload)<admin route>/` or `src/app/(payload)<admin route>/` under `admin.importMap.baseDir` or the working
|
||||
directory). A file it cannot find is never reported. `twoFactor: { …, importMapCheck: false }` turns the file read,
|
||||
the log line and the message off. **Fix:** `pnpm payload generate:importmap`, commit `importMap.js`, rebuild, redeploy.
|
||||
- **At every start in production:** the log has `[ipal] The admin import map may be out of date: … was not found
|
||||
in <file> …`.
|
||||
- **On the screen:** a notice above the 2FA screen, "Two-step verification may not be available", with what a
|
||||
developer has to run. With a really stale map the notice is all the user sees (the form is missing); it is
|
||||
shown by ipal-kit's `TotpRedirectProvider` only — with your own `twoFactor.provider`, or `provider: false`,
|
||||
there is the log line alone.
|
||||
|
||||
The start-up check is a guess, and is built so that a wrong guess costs a wrong notice and nothing else: it
|
||||
searches the text of the `importMap.js` **on disk** where Payload looks for it (`admin.importMap.importMapFile`,
|
||||
else `app/(payload)<admin route>/` or `src/app/(payload)<admin route>/` under `admin.importMap.baseDir` or the
|
||||
working directory), while the map the site really uses is inside the build. The two differ when the map is
|
||||
generated during the build and the running image carries the repository's file (a Dockerfile with a separate
|
||||
runner stage), or when the map file re-exports or computes its entries. Then the log line and the notice appear
|
||||
although the screen works — the code form stays on the page and sign-in is not affected. Turn the check off for
|
||||
such a project: `twoFactor: { …, importMapCheck: false }` (no file read, no log line, no notice). A file that is
|
||||
not found is not reported. Building in place (Coolify's Nixpacks) reads the same file the build used.
|
||||
|
||||
**Fix for a really stale map:** `pnpm payload generate:importmap`, commit `importMap.js`, rebuild, redeploy.
|
||||
A second error exists for the opposite case — the wrapper is in the map but the package's view is not:
|
||||
`[ipal] The admin import map has no "@clocklimited/payload-2fa/rsc#TOTPVerify"` (same fix).
|
||||
|
||||
@@ -732,8 +755,9 @@ size while reading, content signature, container and macro checks, an optional `
|
||||
|
||||
- **Verify limit:** `twoFactor.verifyLimit: { max, windowMinutes }`, or `false`.
|
||||
- **`back` link check of the 2FA screens:** `twoFactor.safeBack: false`, or a function as your own rule;
|
||||
`safeAdminBack`, `wrapTotpViews`, `SafeTotpView` are exported. The stale import-map warning that comes with it:
|
||||
`twoFactor.importMapCheck: false`.
|
||||
`safeAdminBack`, `wrapTotpViews`, `copyViews`, `changedViewKeys`, `SAFE_TOTP_VIEW`, `SafeTotpView` are exported.
|
||||
The stale import-map notice that comes with it: `twoFactor.importMapCheck: false`; its parts
|
||||
(`findImportMapFile`, `missingImportMapEntries`) are exported too.
|
||||
- **2FA check:** per entity `custom.ipal.secondFactor` / `custom.totp.disableAccessWrapper` (one operation or
|
||||
all); `twoFactor.guard: false` turns ipal-kit's own second-factor check off everywhere (not recommended);
|
||||
`requireSecondFactor` / `secondFactorPassed` are exported for your own access functions and endpoints.
|
||||
|
||||
Reference in New Issue
Block a user