Security review fixes: staff collection first everywhere, 2FA package endpoints guarded, per-entity opt-out, hot reload
F1: roles count only for accounts of a staff collection, in every exported predicate and access builder (isAdmin, isEditor, hasMinimumRole, adminOnly, adminOrEditor, requireRole, adminOrSelf, adminOrSelfIn, the Field variants, the roles field) and first in userMeetsRole. An account of another auth collection with its own roles: ['admin'] gets nothing. Staff collections: admin.user, access.authCollection, access.staffCollections. Predicates take req.payload as an optional last argument and otherwise use the staff collections of the config ipalKit built in this process. F2: every endpoint @clocklimited/payload-2fa registers answers accounts of the 2FA collection only (setup-totp wrote the secret into the 2FA collection under the caller's id, whatever collection the caller came from); remove and the admin reset/remove endpoints also need the second factor. F3: per-entity opt-out honoured, operation by operation: the package's custom.totp.disableAccessWrapper and ipal-kit's custom.ipal.secondFactor (passed on to the package); the package's global disableAccessWrapper too. F4: a no-user auth strategy on the 2FA collection guards the live config at the start of each request, so entities from plugins listed after ipalKit stay guarded after a dev hot reload and with disableOnInit. Tests through HTTP for all four; the 2FA tests now run on payload-2fa 3.0.0-beta.7 (what client sites use), a second file on beta.1 (alias), and the HTTP files can run against Postgres (IPAL_TEST_POSTGRES_URI). Docs, agent guide, skills and changelog updated; the not-yet-enrolled limitation is stated plainly. Co-Authored-By: Claude Fable 5.2 <[email protected]>
This commit is contained in:
co-authored by
Claude Fable 5.2
parent
97ee1289aa
commit
32faaa5e30
+35
-12
@@ -20,23 +20,42 @@ once there are more than 20.
|
||||
earlier version.** It needed a valid staff password. Now ipal-kit runs its own second-factor check on every
|
||||
collection and global — whichever plugin added it and in whatever order — and on its endpoints
|
||||
([security.md](./security.md) "What the second factor covers").
|
||||
- **Accounts of a second auth collection are no longer staff.** `userMeetsRole` treated an account of any auth
|
||||
collection without a `roles` field as staff. In a project with a visitor account collection (`customers`, a client
|
||||
zone) such an account passed every staff check of the plugin, with the same reach as above; with open sign-up,
|
||||
anyone could make one. In the injected auth collection, "only my own record" also matched an account of another
|
||||
collection with the same numeric id (Postgres, SQLite). **Affects only projects with more than one auth
|
||||
collection.** Now only accounts of the panel's login collection (plus `access.staffCollections`) can pass, and
|
||||
the injected collection uses `adminOrSelfIn` ([access.md](./access.md#who-is-staff)).
|
||||
- **Accounts of a second auth collection are no longer staff.** Roles, and the rule "no `roles` field = every
|
||||
account passes", counted for an account of any auth collection. In a project with a visitor account collection
|
||||
(`customers`, a client zone) such an account passed the plugin's staff checks, with the same reach as above —
|
||||
every check when its collection had no `roles` field, and `isAdmin` / `adminOnly` / `requireRole` and the others
|
||||
when it had a `roles` field of its own. With open sign-up, anyone could make one. In the injected auth
|
||||
collection, "only my own record" also matched an account of another collection with the same numeric id
|
||||
(Postgres, SQLite). **Affects only projects with more than one auth collection.** Now the staff-collection check
|
||||
comes first in every predicate and access function: only accounts of the panel's login collection,
|
||||
`access.authCollection` and `access.staffCollections` count, and the injected collection uses `adminOrSelfIn`
|
||||
([access.md](./access.md#who-is-staff)).
|
||||
- **The 2FA package's endpoints accept accounts of the 2FA collection only.** `@clocklimited/payload-2fa` (checked
|
||||
in 3.0.0-beta.1 and beta.7) takes the logged-in account from any auth collection and writes the TOTP secret into
|
||||
the 2FA collection under that account's id. With numeric ids (Postgres, SQLite) an account of another auth
|
||||
collection could set the secret of the staff account with the same id; whoever knew that staff password then
|
||||
passed 2FA, and the owner's authenticator stopped working. **Affects only projects with more than one auth
|
||||
collection on Postgres or SQLite** (MongoDB ids do not repeat across collections). ipalKit now guards every
|
||||
endpoint the package registers; reset and remove also need the second factor
|
||||
([security.md](./security.md) "The 2FA package's endpoints").
|
||||
- **Not changed, and important:** an account that has **not set TOTP up yet** is an ordinary logged-in account —
|
||||
its password alone opens everything its role allows. Set 2FA up right after an account is created;
|
||||
`ipal-doctor --url` reports accounts without it.
|
||||
|
||||
### Added
|
||||
- `access.staffCollections`: name further auth collections whose accounts are staff.
|
||||
- `adminOrSelfIn(slug)`, `staffCollectionSlugs(payload)`, `secondFactorPassed(req)`, `requireSecondFactor(access)`
|
||||
for the project's own access functions and endpoints.
|
||||
- `twoFactor.guard: false`: ipal-kit's second-factor check off, the package's wrapper only (not recommended).
|
||||
for the project's own access functions and endpoints. `isAdmin`, `isEditor` and `hasMinimumRole` take
|
||||
`req.payload` as an optional last argument.
|
||||
- Per-entity opt-out from the second factor: `custom.ipal.secondFactor: false | { read: false }` on a collection
|
||||
or global; the package's `custom.totp.disableAccessWrapper` is honoured as before.
|
||||
- `twoFactor.guard: false`: ipal-kit's second-factor check off everywhere, the package's wrapper only (not recommended).
|
||||
|
||||
### Requires project changes
|
||||
- **Every site: upgrade and redeploy.** No config change for a site with one auth collection and
|
||||
`@clocklimited/payload-2fa` 3.0.0-beta.1 to beta.7. `pnpm ipal:skills` afterwards.
|
||||
`@clocklimited/payload-2fa` 3.0.0-beta.7 (tested: beta.1 and beta.7). `pnpm ipal:skills` afterwards.
|
||||
- **Every site: no account without 2FA.** `pnpm exec ipal-doctor --url <site>` → accounts without 2FA must be 0;
|
||||
have each such account set TOTP up now, or remove it.
|
||||
- **Because the earlier behaviour left no trace** (there is no audit log), decide per site with the owner:
|
||||
- change the **SMTP password** and the **Turnstile secret** stored in Site integrations when a staff password
|
||||
may have been known to someone else (a reused or shared password, a former employee, a phishing report) — or
|
||||
@@ -48,9 +67,13 @@ once there are more than 20.
|
||||
is the client's decision.
|
||||
- **A site with a second auth collection:** treat the points above as required, not optional. Set
|
||||
`admin: { user: '<staff collection>' }` in `buildConfig`, use `adminOrSelfIn('<slug>')` in your own auth
|
||||
collections, and if the second collection really is staff, name it in `access.staffCollections`.
|
||||
collections, and if the second collection really is staff, name it in `access.staffCollections`. Roles no
|
||||
longer count for accounts of other collections: a rule that used `isAdmin` / `adminOnly` for them needs its own
|
||||
check of `req.user.collection`. On Postgres or SQLite also ask every staff member to confirm their
|
||||
authenticator still works; if it does not, reset that account's 2FA and set it up again.
|
||||
- **Own code that reads a plugin collection or global with `overrideAccess: false`** must pass a `user` from
|
||||
`payload.auth({ headers })`; a user fetched by id and passed by hand is refused when it has TOTP set up. Own
|
||||
`payload.auth({ headers })`; a user fetched by id and passed by hand is refused when it has TOTP set up, and its
|
||||
role does not count without `collection`. Own
|
||||
endpoints: add `secondFactorPassed(req)` or `userMeetsRole(req, role)`.
|
||||
- **Startup stops with `[ipal] twoFactor: the injected 2FA plugin did not add …`:** the installed 2FA package is
|
||||
not one the check recognises. Install a supported version; `twoFactor.guard: false` only as a stop-gap.
|
||||
|
||||
+44
-25
@@ -67,35 +67,49 @@ keeps Payload's default rules — without roles all accounts are equal.
|
||||
|
||||
## Who is staff
|
||||
|
||||
**Staff collections** are the auth collections whose accounts work in the panel:
|
||||
|
||||
- the one the admin panel logs in with (`admin.user`; Payload's default is the **first** auth collection in the
|
||||
list — set `admin: { user: 'users' }` yourself as soon as the project has two);
|
||||
- the one that carries the plugin's roles (`access.authCollection`);
|
||||
- the ones named in `access.staffCollections`.
|
||||
|
||||
An account of **any other auth collection** — `customers`, `members`, a client zone — is a visitor to the
|
||||
plugin. **Nothing in the plugin counts a role for it**, also when its own collection has a `roles` field with
|
||||
the value `admin`: not `userMeetsRole`, not `isAdmin` / `isEditor` / `hasMinimumRole`, not `adminOnly`,
|
||||
`adminOrEditor`, `requireRole`, `adminOrSelf`, `adminOrSelfIn` or the `…Field` variants, not the `roles` field
|
||||
itself. The staff-collection check always comes first.
|
||||
|
||||
The plugin's own staff features — Site integrations, the settings globals, form submissions, consent records,
|
||||
stats, the cookie scanner, `/api/ipal/test-email` — check with `userMeetsRole(req, minimum)`. It passes when:
|
||||
stats, the cookie scanner, `/api/ipal/test-email` — check with `userMeetsRole(req, minimum)`, in this order:
|
||||
|
||||
1. the account holds at least the role `minimum`; or
|
||||
2. the account belongs to a **staff collection** that has **no `roles` field**. Then every account of that
|
||||
collection passes, as in Payload's default (without roles all accounts are equal).
|
||||
1. the account belongs to a staff collection;
|
||||
2. with 2FA on: an account that has TOTP set up has entered the code in this session
|
||||
([security.md](./security.md) → "What the second factor covers");
|
||||
3. it holds at least the role `minimum` — **or** its collection has no `roles` field at all. Then every account
|
||||
of that staff collection passes, as in Payload's default (without roles all accounts are equal).
|
||||
|
||||
**Staff collections** are the auth collection the admin panel logs in with (`admin.user`, by default the first
|
||||
auth collection) and the ones named in `access.staffCollections`. An account of **any other auth collection** —
|
||||
`customers`, `members`, a client zone — is a visitor to the plugin and never passes rule 2, with or without
|
||||
the `access` option.
|
||||
What follows:
|
||||
|
||||
With 2FA on, an account that has TOTP set up and has not entered the code in this session passes neither rule
|
||||
([security.md](./security.md) → 2FA).
|
||||
|
||||
- **Without `access`** there is no `roles` field, so `isAdmin` always returns `false` and rule 2 keeps the
|
||||
- **Without `access`** there is no `roles` field, so `isAdmin` always returns `false` and rule 3 keeps the
|
||||
staff features reachable: every account of the panel collection is admin to the plugin. To narrow that
|
||||
without roles: `globalOverrides` for the globals, `forms.formSubmissionOverrides` for submissions, or add
|
||||
`access` to get roles.
|
||||
- **A second staff collection** (e.g. `partners` who edit content): name it in
|
||||
`access.staffCollections`. Without a `roles` field every partner then passes every staff check, admin ones
|
||||
included. To tell them apart, add the field: `fields: [buildRolesField('editor')]` in that collection.
|
||||
`access.staffCollections`. That is the one switch that makes its roles count. Without a `roles` field every
|
||||
partner passes every staff check, admin ones included; to tell them apart add the field:
|
||||
`fields: [buildRolesField('editor')]` in that collection.
|
||||
- **A visitor collection that should reach one thing** (e.g. customers read their own form submissions):
|
||||
do not make it staff. Write that one rule: `forms.formSubmissionOverrides.access.read`, `globalOverrides`,
|
||||
`collectionOverrides` of the module.
|
||||
do not make it staff. Write that one rule yourself — `forms.formSubmissionOverrides.access.read`,
|
||||
`globalOverrides`, `collectionOverrides` of the module — and check `req.user.collection` in it.
|
||||
- **A user object you build yourself** (Local API with `overrideAccess: false`, a custom auth strategy) must
|
||||
carry `collection`: `{ ...doc, collection: 'users' }`. Payload's own strategies and `payload.auth()` set it. An
|
||||
account without it is not staff.
|
||||
|
||||
> **Changed in the release after 1.16.3.** Before, rule 2 applied to the account's own collection, whatever it
|
||||
> was: an account of a second auth collection without a `roles` field passed every staff check. A project
|
||||
> with one auth collection sees no difference. A project that relied on a second collection being staff sets
|
||||
> **Changed in the release after 1.16.3.** Before, a role or the "no roles field" rule counted for an account
|
||||
> of any auth collection: an account of a second auth collection passed staff checks — every one when its
|
||||
> collection had no `roles` field, and the matching ones when it had its own `roles` field. A project with one
|
||||
> auth collection sees no difference. A project that relied on a second collection being staff sets
|
||||
> `access.staffCollections`.
|
||||
|
||||
## Predicates (front end / hooks / access)
|
||||
@@ -103,14 +117,19 @@ With 2FA on, an account that has TOTP set up and has not entered the code in thi
|
||||
```ts
|
||||
import { isAdmin, isEditor, hasMinimumRole, staffCollectionSlugs, userMeetsRole } from '@intecion/ipal-kit'
|
||||
|
||||
isAdmin(user) // admin?
|
||||
isEditor(user) // editor or admin (hierarchy)
|
||||
hasMinimumRole(user, 'editor') // at least editor
|
||||
userMeetsRole(req, 'admin') // admin — or any account of a staff collection that has no roles field ("Who is staff")
|
||||
staffCollectionSlugs(req.payload) // ['users', …]: admin.user + access.staffCollections
|
||||
isAdmin(req.user, req.payload) // a staff account with the admin role
|
||||
isEditor(req.user, req.payload) // editor or admin (hierarchy)
|
||||
hasMinimumRole(req.user, 'editor', req.payload) // at least editor
|
||||
userMeetsRole(req, 'admin') // the plugin's staff check: staff collection, second factor, role ("Who is staff")
|
||||
staffCollectionSlugs(req.payload) // ['users', …]
|
||||
```
|
||||
|
||||
They take a loosely typed user (like `req.user`) and read `roles` defensively.
|
||||
They take a loosely typed user (like `req.user`) and read `roles` defensively. The last argument (`req.payload`)
|
||||
tells them which collections are staff. Without it — `isAdmin(req.user)` — they use the staff collections of
|
||||
the config `ipalKit` built in this process, so existing calls in hooks and endpoints are covered too. Only in a
|
||||
browser bundle, where there is no config, the roles are taken as they are: fine for showing or hiding a
|
||||
button, never a security check. `isAdmin` and the others do **not** check the second factor; `userMeetsRole`
|
||||
and every `access` function in the config do.
|
||||
|
||||
## Ready access functions
|
||||
|
||||
|
||||
+16
-10
@@ -203,7 +203,7 @@ site), **P** = a test in the panel. Full code: PROGRAMISTA.md §2.
|
||||
| 10 | **Forms** | every form from a **seed** (`scripts/seed-form-*.ts`: fields, confirmation, mail to the company **and** confirmation to the customer, every language); a block with `<RenderForm>` + `formClasses.ts` (look, once); `actions.ts` = `createSubmitAction({ getCachedPayload, headers })`; `forms: {…}` in `ipalKit`; `email: mailAdapter()` | `RenderForm` (`/rsc`), `createSubmitAction`, `mailAdapter` | A, P |
|
||||
| 11 | **Turnstile** | `<SiteProviders>` in `[locale]/layout.tsx` (wires `TurnstileProvider` with the key from the panel); `RenderForm` renders the widget; keys in Site integrations | `SiteProviders`, `getTurnstileConfig`, `TurnstileProvider` | A, P |
|
||||
| 12 | Consent + analytics | Consent Mode: `'advanced'` (default — the Google tag loads at once with every signal `denied`) or `'basic'` (`<SiteProviders analytics={{ consentMode: 'basic' }}>` — no request to Google before consent; a client who wants zero requests), the choice goes to "Project decisions"; `ipalKit({ consentLog: true })` (without it the `/api/ipal/consent` endpoint does not exist) + `<SiteProviders logEndpoint="/api/ipal/consent" banner={<CookieBanner equalChoice settings="detailed" />}>` (ConsentProvider, banner, CookieButton, Analytics in the right order); settings window mode (`settings`: `inline` / `modal` / `detailed`) per the design, brief is silent → `detailed`, the decision goes to "Project decisions"; tool IDs in the panel; the cookie list from a scan (`cookieScanner: true` → *Cookie review* → **Scan cookies** → *Approve cookies* → **Approve and add**; or cookie-scan → import) — feeds `<CookieTable>` on the policy page **and** the lists in the `detailed` window; Cookies → Settings window → Cookie list headings in every language | consent.md, analytics.md | A, `ipal-consent-check` |
|
||||
| 13 | Security | `buildSecurityHeaders` in `next.config.ts`; `withPayload(withSecurityConfig(nextConfig))` (no `X-Powered-By`); CSP: `buildSecurityHeaders({ csp: { mode: 'report-only', reportUri: '/api/csp-report', … } })` + `buildAdminCspHeaders` on `/admin/:path*` + `src/app/api/csp-report/route.ts` (`createCspReportRoute`) → read the reports → `mode: 'enforce'`; `twoFactor: { issuer, plugin: payloadTotp }` + `generate:importmap` (`TotpRedirectProvider`; check: a new admin lands on `/admin/setup-totp?back=%2Fadmin` with the QR, no reloading; a login with the password only gets `403` from `/api/globals/site-integrations` and `/api/form-submissions` — security.md "What the second factor covers"); own endpoints: `secondFactorPassed(req)` / `userMeetsRole(req, role)`; `IPAL_IP_HEADER` in production | security.md, forms.md | A |
|
||||
| 13 | Security | `buildSecurityHeaders` in `next.config.ts`; `withPayload(withSecurityConfig(nextConfig))` (no `X-Powered-By`); CSP: `buildSecurityHeaders({ csp: { mode: 'report-only', reportUri: '/api/csp-report', … } })` + `buildAdminCspHeaders` on `/admin/:path*` + `src/app/api/csp-report/route.ts` (`createCspReportRoute`) → read the reports → `mode: 'enforce'`; `twoFactor: { issuer, plugin: payloadTotp }` + `generate:importmap` (`TotpRedirectProvider`; check: a new admin lands on `/admin/setup-totp?back=%2Fadmin` with the QR, no reloading; a login with the password only gets `403` from `/api/globals/site-integrations` and `/api/form-submissions` — security.md "What the second factor covers"); own endpoints: `secondFactorPassed(req)` / `userMeetsRole(req, role)`; **set 2FA up right after creating an account** — until then its password alone opens everything its role allows; `ipal-doctor --url` must report 0 accounts without 2FA; `IPAL_IP_HEADER` in production | security.md, forms.md | A |
|
||||
| 14 | Operations | `src/app/api/health/route.ts` (`healthRoute`); `src/instrumentation.ts` with `assertEnv(ipalEnvRules({ storage: true, ipHeader: true }))`; staging with `IPAL_NOINDEX=1`; smoke tests (§8a) | `healthRoute`, `assertEnv`, `ipalEnvRules` | A |
|
||||
| 15 | System pages | Site settings → System pages: homepage, 404, privacy policy, cookies; legal links in the footer by role (`getSystemLinks(locale)`) | `getSystemLinks`, `getSystemPagePath`, `getNotFoundPage` | P |
|
||||
| 16 | **Nothing hardcoded** | every text, link, image, file, company data from the panel; domains and keys from `.env` (§2) | — | A, P |
|
||||
@@ -584,14 +584,18 @@ the plugin adds roles and 2FA to it).
|
||||
for visitors. Then, all four:
|
||||
1. `admin: { user: 'users' }` in `buildConfig` — Payload otherwise logs the panel in with the FIRST auth
|
||||
collection in the list, and 2FA and the staff checks follow the panel collection.
|
||||
2. Its accounts are visitors to the plugin: they pass none of its staff checks (`userMeetsRole`) — settings
|
||||
globals, Site integrations, form submissions, consent records, stats, cookie scanner. Give them exactly
|
||||
what they need with your own `access` rules; never add the collection to `access.staffCollections` to
|
||||
"make something work". `access.staffCollections` is for a second collection of STAFF (access.md → "Who
|
||||
is staff").
|
||||
2. Its accounts are visitors to the plugin: no role counts for them (also a `roles` field of their own with
|
||||
the value `admin`) and they pass none of its checks — `userMeetsRole`, `isAdmin`, `adminOnly`,
|
||||
`adminOrEditor`, `requireRole`, the settings globals, Site integrations, form submissions, consent records,
|
||||
stats, cookie scanner. Give them exactly what they need with your own `access` rules that check
|
||||
`req.user.collection`; never add the collection to `access.staffCollections` to "make something work".
|
||||
`access.staffCollections` is for a second collection of STAFF (access.md → "Who is staff").
|
||||
3. In every auth collection use `adminOrSelfIn('<its slug>')`, not `adminOrSelf`, for "only my own record".
|
||||
4. Check: log in as such an account (`POST /api/customers/login`), then `GET /api/globals/site-integrations`
|
||||
and `GET /api/form-submissions` with its token must answer `403`.
|
||||
4. Never let a sign-up write a field that grants rights (`roles`, `isAdmin`, …): give such a field
|
||||
`access: { create: adminOnlyField, update: adminOnlyField }`.
|
||||
5. Check: log in as such an account (`POST /api/customers/login`), then `GET /api/globals/site-integrations`,
|
||||
`GET /api/form-submissions` and `GET /api/users` with its token must answer `403`, and so must
|
||||
`POST /api/setup-totp`.
|
||||
|
||||
**NEVER:** a second `media`, `daneFirmy`/`settings`/
|
||||
`navigation`/`footer` as collections (they are globals), FAQ/hero/features as collections
|
||||
@@ -1053,7 +1057,7 @@ project → **plugin gap**, not a copy.
|
||||
| ISR after save, old slug → 308, images across languages | `buildRevalidateHook`, `trackSlugHistoryHook`, `buildCrossLocaleFieldSync` | hooks.md |
|
||||
| ISR after a global is saved | plugin globals: `ipalKit({ revalidatePath })`; your own globals: `buildGlobalRevalidateHook({ revalidatePath })` | hooks.md |
|
||||
| Change a plugin global (access, hooks, fields) | `ipalKit({ globalOverrides })` | access.md |
|
||||
| Roles and access | `adminOnly`, `adminOrEditor`, `adminOrSelf`, `adminOrSelfIn(slug)` (several auth collections), `authenticated`, `requireRole`, `hasMinimumRole` (+ `…Field`); staff checks: `userMeetsRole(req, role)`, `staffCollectionSlugs(payload)`, `access.staffCollections`; second factor in your own code: `secondFactorPassed(req)`, `requireSecondFactor(access)`; injected `users`: `access.authAccess`, first user = admin (`access.firstUserAdmin`) | access.md, security.md |
|
||||
| Roles and access | `adminOnly`, `adminOrEditor`, `adminOrSelf`, `adminOrSelfIn(slug)` (several auth collections), `authenticated`, `requireRole`, `hasMinimumRole` (+ `…Field`); staff checks: `userMeetsRole(req, role)`, `isAdmin(req.user, req.payload)` (roles count only for accounts of a staff collection), `staffCollectionSlugs(payload)`, `access.staffCollections`; second factor in your own code: `secondFactorPassed(req)`, `requireSecondFactor(access)`; injected `users`: `access.authAccess`, first user = admin (`access.firstUserAdmin`) | access.md, security.md |
|
||||
| Data from globals | `getGlobal`, `getSiteSettings`, `getSiteIntegrations` | payload-helpers.md |
|
||||
|
||||
**Links and navigation**
|
||||
@@ -1159,7 +1163,9 @@ add missing hosts with flags / `extra`; (3) change `mode` to `'enforce'` in both
|
||||
| Injected `users`: admin manages everyone, others only themselves | — | `access.authAccess` (your keys win); your own `users` collection wins whole |
|
||||
| First registered account = admin | `access.firstUserAdmin: false` | `buildRolesField(defaultRole, { firstUserAdmin })` |
|
||||
| 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 | `twoFactor.guard: false` (not recommended: the package's wrapper only) | `requireSecondFactor` / `secondFactorPassed` in your own access functions and endpoints |
|
||||
| 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 |
|
||||
| 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`) |
|
||||
| No client IP = one shared `unknown-ip` bucket at 20× the limit | `setUnknownIpFactor(0)` (only with a limiter in front) | `setUnknownIpFactor(n)`; `UNKNOWN_IP_FACTOR` |
|
||||
| Turnstile token domain not checked | (default) | `createSubmitAction({ turnstileHostnames })`, `verifyTurnstile({ hostnames })` — leave empty in dev |
|
||||
|
||||
@@ -34,9 +34,9 @@ through this procedure. Ask only when you are missing something you cannot get y
|
||||
### Build / TypeScript
|
||||
| Symptom | Cause | Fix |
|
||||
|---|---|---|
|
||||
| startup: `[ipal] twoFactor: the injected 2FA plugin did not add the totpSecret field / hasTotp field / totp auth strategy` | the installed `@clocklimited/payload-2fa` is not a version ipal-kit's second-factor check recognises (supported: 3.0.0-beta.1 to beta.7), or a custom factory was injected | install a supported version; stop-gap only: `twoFactor.guard: false` (the plugin's own data is then not covered by 2FA — security.md) |
|
||||
| own route or script gets `403` / "not allowed" on `form-submissions`, `forms`, a settings global with `overrideAccess: false`, although the user is an admin | the `user` was fetched by id and passed by hand: it does not carry how the account logged in, so the second-factor check refuses it | take the user from `payload.auth({ headers })`, or (server-only code that needs no access check) leave `overrideAccess` at its default |
|
||||
| an account of a second auth collection (`customers`) gets `403` from a settings global, submissions or `/api/ipal/*` after an upgrade | by design since the release after 1.16.3: only staff collections pass `userMeetsRole` | write the one rule it needs (`formSubmissionOverrides`, `globalOverrides`, `collectionOverrides`); a second STAFF collection: `access.staffCollections` (access.md "Who is staff") |
|
||||
| startup: `[ipal] twoFactor: the injected 2FA plugin did not add the totpSecret field / hasTotp field / totp auth strategy` | the installed `@clocklimited/payload-2fa` is not a version ipal-kit's second-factor check recognises (tested: 3.0.0-beta.1 and beta.7), or a custom factory was injected | install a supported version; stop-gap only: `twoFactor.guard: false` (the plugin's own data is then not covered by 2FA — security.md) |
|
||||
| own route or script gets `403` / "not allowed" on `form-submissions`, `forms`, a settings global with `overrideAccess: false`, although the user is an admin | the `user` was fetched by id and passed by hand: it does not carry how the account logged in, so the second-factor check refuses it | take the user from `payload.auth({ headers })` (it sets `collection` and how the account logged in), or (server-only code that needs no access check) leave `overrideAccess` at its default; a hand-built user needs at least `collection: 'users'` for its role to count |
|
||||
| an account of a second auth collection (`customers`) gets `403` from a settings global, submissions, `/api/ipal/*`, `/api/setup-totp`, or `isAdmin` / `adminOnly` say no although it has `roles: ['admin']`, after an upgrade | by design since the release after 1.16.3: roles and staff checks count only for accounts of a staff collection | write the one rule it needs (`formSubmissionOverrides`, `globalOverrides`, `collectionOverrides`); a second STAFF collection: `access.staffCollections` (access.md "Who is staff") |
|
||||
| `TS2307 next/navigation` in the plugin's `dist` | import without `.js` in the plugin client (NodeNext) | **ipal-kit bug** → plugin gap; the plugin imports `'next/navigation.js'` |
|
||||
| `TS2307 @payloadcms/storage-s3` | package missing when using `buildR2Storage` | `pnpm add @payloadcms/storage-s3` + `buildR2Storage(['media'], { s3Storage })` |
|
||||
| `does not provide an export named X` / `X is not a function` | symbol not exported from the entry point, or wrong subpath (`/client` vs root vs `/server` vs `/rsc`) | `docs/README.md` → the right import; missing from every entry → **ipal-kit bug** (export) |
|
||||
|
||||
@@ -30,7 +30,7 @@ description: Complete map of everything @intecion/ipal-kit provides — every ip
|
||||
| `access.defaultRole` | `'user'` | `defaultValue` of the `roles` field | `'editor'` / `'admin'` |
|
||||
| `access.authAccess` | `{ create: adminOnly, delete: adminOnly, read: adminOrSelfIn(slug), unlock: adminOnly, update: adminOrSelfIn(slug) }` | access of the auth collection the plugin **injects** (Payload's default lets any logged-in account edit or delete every other account) | your keys win, e.g. `{ read: authenticated }`; your own collection with that slug wins whole (give it `adminOrSelf` / `adminOnly` yourself) |
|
||||
| `access.firstUserAdmin` | `true` | the account made on Payload's "Create first user" screen (`/first-register` on an empty collection) gets `roles: ['admin']`; an open sign-up still gets `defaultRole` | `false` = that account gets what was submitted |
|
||||
| `access.staffCollections` | `[]` | more auth collections whose accounts are staff for `userMeetsRole`, besides the panel's login collection (`admin.user`); without a `roles` field there, every such account passes every staff check | add `buildRolesField()` to that collection to tell roles apart; a visitor collection (`customers`) is never listed here |
|
||||
| `access.staffCollections` | `[]` | more auth collections whose accounts are staff, besides the panel's login collection (`admin.user`) and `access.authCollection`; roles count **only** for accounts of a staff collection (every predicate and access function); without a `roles` field there, every such account passes every staff check | add `buildRolesField()` to that collection to tell roles apart; a visitor collection (`customers`) is never listed here |
|
||||
| `adminRoute` | `'/admin'` | `config.routes.admin`; stats link and views, `IntegrationAlerts` | the project moves `app/(payload)/<route>/` itself and adds the route to the proxy matcher (security.md) |
|
||||
| `twoFactor` | **none = error** | `@clocklimited/payload-2fa` with `forceSetup: true` (TOTP enforced, also checked in the API) | `twoFactor: false` (discouraged); omitting the option throws `[ipal] twoFactor.issuer is required` |
|
||||
| `twoFactor.issuer` | — (required) | name in the authenticator app | — |
|
||||
@@ -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.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` | `false` = the package's wrapper only (the plugin's own data then opens to a password without the code; not recommended) |
|
||||
| `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.allowCollectionMismatch` | `false` | allows `collectionSlug` ≠ `admin.user` (panel users of the other collection then skip 2FA) | `true` only when you protect a second auth collection on purpose |
|
||||
| `whiteLabel` | none | `admin.components.graphics.Logo/Icon` (`AdminLogo`/`AdminIcon`) from Site settings + vendor credit | omit / `false`; `true` = defaults |
|
||||
| `whiteLabel.settingsSlug` | `'site-settings'` | global it reads the logo/name from | — |
|
||||
|
||||
@@ -59,11 +59,11 @@ Admin panel components from `@intecion/ipal-kit/admin` — the project does NOT
|
||||
| `adminOnlyField` | `@intecion/ipal-kit` | `FieldAccess` (boolean only): field for admin only. In `field.access.read/update`. |
|
||||
| `adminOrEditorField` | `@intecion/ipal-kit` | `FieldAccess`: field for editor or admin. |
|
||||
| `requireRoleField(minimum)` | `@intecion/ipal-kit` | `FieldAccess` factory: at least the given role. |
|
||||
| `hasMinimumRole(user, minimum)` | `@intecion/ipal-kit` | Predicate → `boolean`: whether the user has a role ≥ `minimum` (reads `user.roles` safely). For your own access logic/hooks. |
|
||||
| `isAdmin(user)` | `@intecion/ipal-kit` | Predicate → `boolean`: `admin` role. |
|
||||
| `isEditor(user)` | `@intecion/ipal-kit` | Predicate → `boolean`: `editor` or higher. |
|
||||
| `userMeetsRole(req, minimum)` | `@intecion/ipal-kit` | Predicate → `boolean` with `req` (`{ payload, user }`): role ≥ `minimum`, **or** any account of a **staff collection** (the panel's login collection `admin.user`, plus `access.staffCollections`) that has no `roles` field (the project omitted `access`). An account of any other auth collection never passes without a role. With 2FA on it also requires the second factor (`secondFactorPassed`). The plugin's staff features (Site integrations, settings globals, form submissions, consent records, stats, cookie scanner, the e-mail test) use it; use it in your own endpoints. |
|
||||
| `staffCollectionSlugs(payload)` | `@intecion/ipal-kit` | `string[]`: the staff collections `userMeetsRole` accepts — `admin.user` plus `access.staffCollections`. |
|
||||
| `hasMinimumRole(user, minimum, payload?)` | `@intecion/ipal-kit` | Predicate → `boolean`: the user is an account of a **staff collection** and has a role ≥ `minimum` (reads `user.roles` and `user.collection` safely). A role on an account of another auth collection never counts. Pass `req.payload` where you have it; without it the staff collections of the config ipalKit built in this process are used (in a browser bundle, where there is none, the roles are taken as they are — UI only). Does not check the second factor. |
|
||||
| `isAdmin(user, payload?)` | `@intecion/ipal-kit` | Predicate → `boolean`: staff account with the `admin` role (see `hasMinimumRole`). In hooks and endpoints: `isAdmin(req.user, req.payload)`. |
|
||||
| `isEditor(user, payload?)` | `@intecion/ipal-kit` | Predicate → `boolean`: staff account with `editor` or higher. |
|
||||
| `userMeetsRole(req, minimum)` | `@intecion/ipal-kit` | Predicate → `boolean` with `req` (`{ payload, user }`), in this order: the account belongs to a **staff collection** (`admin.user`, `access.authCollection`, `access.staffCollections`); with 2FA on it has passed the second factor (`secondFactorPassed`); it has a role ≥ `minimum`, **or** its collection has no `roles` field (the project omitted `access`). An account of any other auth collection never passes, whatever fields it has. The plugin's staff features (Site integrations, settings globals, form submissions, consent records, stats, cookie scanner, the e-mail test) use it; use it in your own endpoints. |
|
||||
| `staffCollectionSlugs(payload)` | `@intecion/ipal-kit` | `string[]`: the staff collections — `admin.user`, `access.authCollection` and `access.staffCollections`. Roles and staff checks count only for accounts of these. |
|
||||
| `ROLE_HIERARCHY` | `@intecion/ipal-kit` | Constant `['user', 'editor', 'admin']` (lowest first) — a higher role meets the requirements of a lower one. The plugin injects the `roles` field into the auth collection (`access.authCollection`). |
|
||||
| `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. |
|
||||
@@ -586,7 +586,7 @@ Server only (`pnpm payload run`); never import it from client code, the Payload
|
||||
| `buildSecurityHeaders({ hsts?, csp?, additional?, coop?, frameOptions?, permissionsPolicy?, referrerPolicy?, … })` | `@intecion/ipal-kit` | Returns `SecurityHeader[]` (HSTS, X-Frame-Options, nosniff, Referrer-Policy, Permissions-Policy, COOP; with `IPAL_NOINDEX` also `X-Robots-Tag`) for `headers()` in `next.config.ts`. `csp` = `buildCsp` args → the CSP header (+ `Reporting-Endpoints` with `reportUri`); off by default. `additional` overrides by key. |
|
||||
| `withSecurityConfig(nextConfig, { hidePoweredBy? })` | `@intecion/ipal-kit` | Next config wrapper: `poweredByHeader: false` + drops `X-Powered-By` from `headers()` (Next's "Next.js" and withPayload's "Next.js, Payload"). `withPayload(withSecurityConfig(nextConfig))`; `hidePoweredBy: false` = no change. |
|
||||
| `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`. |
|
||||
| `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, in `onInit`, to those added by plugins listed after it); use it for access functions that are not part of the config. Wrapping twice is harmless. |
|
||||
| `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'`. |
|
||||
| `buildCspHeaders(args)` | `@intecion/ipal-kit` | `[csp, Reporting-Endpoints]` (the second only with `reportUri`). |
|
||||
|
||||
@@ -224,8 +224,11 @@ the panel shows Site settings, Site integrations, Cookies, Form messages, the Fo
|
||||
`[ipal] twoFactor…` unless `allowCollectionMismatch: true`. The second factor covers every collection and global
|
||||
(the plugin's own, and those of plugins listed after `ipalKit`) and the plugin's endpoints; guard your own
|
||||
endpoints with `secondFactorPassed(req)` or `userMeetsRole(req, role)` (security.md "What the second factor covers").
|
||||
**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`.
|
||||
- A second auth collection (`customers`, a client zone): set `admin: { user: 'users' }` in `buildConfig`; its
|
||||
accounts pass none of the plugin's staff checks; use `adminOrSelfIn('<slug>')` in every auth collection; a second
|
||||
accounts pass none of the plugin's checks and no role counts for them (not even their own `roles: ['admin']`);
|
||||
a field that grants rights is never writable at sign-up; use `adminOrSelfIn('<slug>')` in every auth collection; a second
|
||||
collection of STAFF goes in `access.staffCollections` (access.md "Who is staff"). Check: that account's token
|
||||
gets `403` from `/api/globals/site-integrations` and `/api/form-submissions`.
|
||||
- The `site-settings`, `site-integrations`, `cookie-settings`, `notifications` globals (write: editor+; Site
|
||||
|
||||
@@ -331,22 +331,27 @@ recommended, not required (the plugin's peer range stays `^3.90.2`):**
|
||||
**→ the release after 1.16.3 (PROGRAMISTA §6, item 65; security fixes: 2FA coverage and staff checks) — required
|
||||
for every site:**
|
||||
1. Update the package, `pnpm install`, `pnpm ipal:skills`, build, redeploy on Coolify. No migration, no config
|
||||
change for a site with one auth collection. `pnpm ls @clocklimited/payload-2fa` must show 3.0.0-beta.1 to beta.7;
|
||||
change for a site with one auth collection. `pnpm ls @clocklimited/payload-2fa` should show 3.0.0-beta.7 (tested: beta.1 and beta.7);
|
||||
another version may stop startup with `[ipal] twoFactor: the injected 2FA plugin did not add …`.
|
||||
2. `grep -rn "auth:" src/collections` — more than one auth collection? Then: `admin: { user: '<staff slug>' }` in
|
||||
`buildConfig`; `adminOrSelfIn('<slug>')` instead of `adminOrSelf` in each; `access.staffCollections` only when
|
||||
the second collection is staff (access.md "Who is staff"). Never list a visitor collection there.
|
||||
the second collection is staff (access.md "Who is staff"). Never list a visitor collection there. Roles now
|
||||
count only for accounts of a staff collection: code that relied on `isAdmin` / `adminOnly` for accounts of
|
||||
another collection needs its own rule (`req.user.collection === '…'`).
|
||||
3. `grep -rn "overrideAccess: false" src` — a call on a plugin collection or global (`form-submissions`, `forms`,
|
||||
`consent-records`, `stats-visits`, `cookie-review`, the settings globals) must pass the `user` from
|
||||
`payload.auth({ headers })`. Own endpoints that check `req.user`: add `secondFactorPassed(req)` or use
|
||||
`userMeetsRole(req, role)`.
|
||||
4. Tell the owner what the CHANGELOG entry says under "Requires project changes" and agree on it: new SMTP
|
||||
`payload.auth({ headers })`; a user object built by hand needs `collection: '<staff slug>'` for its role to
|
||||
count. Own endpoints that check `req.user`: add `secondFactorPassed(req)` or use `userMeetsRole(req, role)`.
|
||||
`isAdmin(req.user)` keeps working; prefer `isAdmin(req.user, req.payload)`.
|
||||
4. `pnpm exec ipal-doctor --url <site>` (with the doctor token) → accounts without 2FA must be 0. An account that
|
||||
has not set TOTP up opens everything with its password alone: have its owner set it up now, or remove it.
|
||||
5. Tell the owner what the CHANGELOG entry says under "Requires project changes" and agree on it: new SMTP
|
||||
password and Turnstile secret, a look through Site settings, Site integrations and each form's Emails tab.
|
||||
Do not change those values yourself without that decision.
|
||||
**Check:** with 2FA on, log in over the API with the password only (security.md → "What the second factor covers" →
|
||||
Check) → `403` from `/api/globals/site-integrations`, `/api/form-submissions`, `/api/users`; log in fully in the
|
||||
panel → Site integrations and a form submission open, a setting saves. With a second auth collection: its token
|
||||
gets `403` from the same addresses.
|
||||
gets `403` from the same addresses and from `POST /api/setup-totp`.
|
||||
|
||||
## 2. Inventory (no code changes)
|
||||
**What changed for projects** between your old and new plugin version is exactly the reference site's diff —
|
||||
|
||||
@@ -672,7 +672,7 @@ Do one item at a time, build, check. Order by importance:
|
||||
| 62 | **1.16.1** — `pnpm dev` warns "Next.js 16.4.3 is affected by a known security vulnerability"; ipal-doctor `next-min` error below 16.4.5 (GHSA-mfr8-8qww-v76h) | `pnpm add [email protected] [email protected]`, `rm -rf .next`, build, commit the lockfile, redeploy on Coolify; `pnpm ipal:skills`; no option, migration or import map change | CHANGELOG 1.16.1, AGENT.md §4 item 11 |
|
||||
| 63 | **1.16.2** — `pnpm audit --prod` shows `mongoose` (critical, via `@payloadcms/db-mongodb`) or `happy-dom` (high, via `@payloadcms/richtext-lexical`); ipal-doctor `transitive-min` | `pnpm.overrides`: `"mongoose@>=8 <8.24.7": "~8.24.10"` (MongoDB sites) and `"happy-dom@<21.0.4": "^21.0.4"`; `pnpm install`, build, commit the lockfile, redeploy on Coolify; `pnpm ipal:skills`; no migration | CHANGELOG 1.16.2, AGENT.md §4 item 12 |
|
||||
| 64 | **1.16.3** — the reference site and the starter run Payload 3.94.1; the site is still on 3.90–3.93, or `node -v` (locally or in the Coolify app's Terminal) is below 22.23.5 | Recommended, not required (the plugin still accepts `^3.90.2`). First make sure Node is 22.23.5 or later everywhere, Coolify included (Nixpacks picks the patch: check `node -v`, update Coolify if lower). Then every `payload` / `@payloadcms/*` 3.94.1 (in `dependencies` and `pnpm.overrides`), `react` / `react-dom` 19.3.1, `"engines": { "node": ">=22.23.5 <23" }`; overrides: keep `dompurify` and `happy-dom`, drop `mongoose`, `undici` and `graphql-scalars`; `pnpm install`, `generate:types`, `generate:importmap`, `rm -rf .next`, build, redeploy; Postgres/SQLite: `migrate:create`; `pnpm ipal:skills` | CHANGELOG 1.16.3, AGENT.md §4 items 11–12, ipal-upgrade "Every upgrade — Payload" |
|
||||
| 65 | **the release after 1.16.3 — security** — with 2FA on, a login with the password only gets `200` from `/api/globals/site-integrations` or `/api/form-submissions`; or the project has a second auth collection (`customers`) | Upgrade and redeploy (no config change with one auth collection). With the owner: change the SMTP password and the Turnstile secret, review Site settings / Site integrations / each form's Emails tab for values nobody set. Second auth collection: `admin: { user }` in `buildConfig`, `adminOrSelfIn('<slug>')`, `access.staffCollections` only for a second STAFF collection. Own endpoints: `secondFactorPassed(req)`; own `overrideAccess: false` calls: `user` from `payload.auth()`. `pnpm ipal:skills`; no migration | CHANGELOG "Unreleased — security fixes", security.md "What the second factor covers", access.md "Who is staff" |
|
||||
| 65 | **the release after 1.16.3 — security** — with 2FA on, a login with the password only gets `200` from `/api/globals/site-integrations` or `/api/form-submissions`; or the project has a second auth collection (`customers`) | Upgrade and redeploy (no config change with one auth collection). With the owner: change the SMTP password and the Turnstile secret, review Site settings / Site integrations / each form's Emails tab for values nobody set. Second auth collection: `admin: { user }` in `buildConfig`, `adminOrSelfIn('<slug>')`, `access.staffCollections` only for a second STAFF collection. Every account must have 2FA set up (`ipal-doctor --url` → 0 without). Own endpoints: `secondFactorPassed(req)`; own `overrideAccess: false` calls: `user` from `payload.auth()`. `pnpm ipal:skills`; no migration | CHANGELOG "Unreleased — security fixes", security.md "What the second factor covers", access.md "Who is staff" |
|
||||
|
||||
After updating the package: `pnpm ipal:skills` (new skill versions), `pnpm payload generate:importmap`, `rm -rf .next`, restart dev, grep for the new symbol in
|
||||
`node_modules/@intecion/ipal-kit/dist`.
|
||||
|
||||
+48
-8
@@ -404,7 +404,9 @@ therefore read and changed them over the API.** Since the release after 1.16.3 i
|
||||
|---|---|
|
||||
| every collection and global in the config when ipalKit finishes | `access` wrapped with `requireSecondFactor` |
|
||||
| collections and globals added by plugins listed **after** ipalKit | wrapped in ipalKit's `onInit`; the log line `[ipal] 2FA also enforced on entities added after ipalKit: …` names them |
|
||||
| the same after a dev hot reload, or when Payload runs with `disableOnInit` | an auth strategy that authenticates nobody (`ipal-second-factor-guard` on the 2FA collection) runs at the start of every request and guards the live config once |
|
||||
| the plugin's endpoints (`/api/ipal/test-email`, `cookie-scan`, `cookie-approval`, `cookie-crawl`, the `access` option of `/api/ipal/doctor`) | `userMeetsRole` and `secondFactorPassed` |
|
||||
| the 2FA package's own endpoints (`/api/setup-totp`, `/api/verify-totp`, `/api/remove-totp`, `/api/admin/reset-user-totp`, `/api/admin/remove-user-totp`, any a later version adds) | accounts of the 2FA collection only; everything except setup and verify also needs the second factor ("The 2FA package's endpoints" below) |
|
||||
|
||||
The order of the project's `plugins` array does not matter. Payload's own collections (`payload-preferences`,
|
||||
`payload-locked-documents`, …) and `access.admin` (may this account open the panel) are left alone: the code is
|
||||
@@ -416,6 +418,38 @@ Everything else is refused, including a user object the check does not recognise
|
||||
collections, anonymous visitors, bearer-token routes (`/api/ipal/doctor`, the cookie-crawl callback, MCP) and
|
||||
the Local API with `overrideAccess: true` (the default) are not affected.
|
||||
|
||||
> **Until an account has set TOTP up, its password alone opens everything its role allows** — Site
|
||||
> integrations with the SMTP password included. Enforced setup is a redirect in the panel; over the API such an
|
||||
> account is an ordinary logged-in account (it has to be, or it could not set TOTP up). So: **set 2FA up right
|
||||
> after an account is created** — create the account, log in as it, scan the code, in one sitting — and never
|
||||
> leave an invited account waiting. `ipal-doctor --url` reports the number of accounts without 2FA
|
||||
> (`2fa`, deep check); it must be 0.
|
||||
|
||||
**Per-entity opt-out.** A collection or global that may be reached with the password alone (a project decision,
|
||||
e.g. a health record the panel reads before the code is entered), operation by operation:
|
||||
|
||||
```ts
|
||||
// the 2FA package's own key — it leaves the operation unwrapped, and so does ipal-kit
|
||||
{ slug: 'notices', custom: { totp: { disableAccessWrapper: { read: true } } }, … }
|
||||
// ipal-kit's key — the same, and it also works for entities the package never sees
|
||||
{ slug: 'notices', custom: { ipal: { secondFactor: { read: false } } }, … } // or secondFactor: false = every operation
|
||||
```
|
||||
|
||||
Operations: `create`, `delete`, `read`, `readVersions`, `unlock`, `update` (collections); `read`, `readDrafts`,
|
||||
`readVersions`, `update` (globals). For one of the plugin's own globals set it through `globalOverrides`
|
||||
(`{ notifications: { custom: { ipal: { secondFactor: { read: false } } } } }`) — and note that the plugin's
|
||||
staff rules (`userMeetsRole`) ask for the second factor themselves, so also give that operation your own
|
||||
`access` function there. `disableAccessWrapper: true` passed to the package's factory turns all access
|
||||
wrapping off, ipal-kit's included; the endpoints stay guarded.
|
||||
|
||||
**The 2FA package's endpoints.** The package takes `req.user` from whatever auth collection it comes and then
|
||||
acts on the 2FA collection by id: `/api/setup-totp` writes the TOTP secret under the **caller's** id. With
|
||||
numeric ids (Postgres, SQLite) an account of another auth collection could therefore set the secret of the
|
||||
staff account that has the same id, and whoever knew that staff password then passed 2FA. ipalKit wraps every
|
||||
endpoint the package registers: a logged-in account of another collection gets `403`; remove and the admin
|
||||
reset / remove endpoints also need the second factor, so a password alone cannot reset TOTP and enrol again.
|
||||
This guard is on whenever 2FA is on, also with `twoFactor.guard: false`.
|
||||
|
||||
Two things follow for project code:
|
||||
|
||||
- `payload.find({ …, user, overrideAccess: false })` on a plugin collection needs a `user` that came from
|
||||
@@ -438,7 +472,7 @@ access: { read: requireSecondFactor(({ req }) => isAdmin(req.user)) }
|
||||
**Fails closed.** At startup ipalKit checks that the injected 2FA plugin added what the check reads (the
|
||||
`totpSecret` and `hasTotp` fields and the `totp` auth strategy on the 2FA collection). When it did not — a
|
||||
package version with another shape — startup stops with `[ipal] twoFactor: the injected 2FA plugin did not
|
||||
add …`. Supported: `@clocklimited/payload-2fa` 3.0.0-beta.1 to beta.7. `twoFactor.guard: false` switches
|
||||
add …`. Tested with `@clocklimited/payload-2fa` 3.0.0-beta.1 and 3.0.0-beta.7 (the versions in between are not run in the plugin's tests). `twoFactor.guard: false` switches
|
||||
ipal-kit's check off and leaves the package's wrapper alone; the plugin's own data is then open to a password
|
||||
without the code again, so use it only to get a site started while the package is being sorted out.
|
||||
|
||||
@@ -525,7 +559,10 @@ show the QR code. `back=null` or a page that keeps reloading means the import ma
|
||||
An admin can reset another user's 2FA (when they lose their phone) — through
|
||||
`adminManageAccess` in the @clocklimited configuration. ipalKit passes it only `collection`,
|
||||
`forceSetup` and `issuer`; pass other options by wrapping the injected factory:
|
||||
`plugin: (opts) => payloadTotp({ ...opts, adminManageAccess: ({ req }) => isAdmin(req.user) })`.
|
||||
`plugin: (opts) => payloadTotp({ ...opts, adminManageAccess: ({ req }) => isAdmin(req.user, req.payload) })`.
|
||||
ipal-kit's guard on those endpoints adds the rest: the caller must be an account of the 2FA collection that has
|
||||
passed the second factor itself. After a reset the account is "not set up" again — have its owner set TOTP up
|
||||
at once (see the note above).
|
||||
|
||||
### Why @clocklimited and not another one
|
||||
|
||||
@@ -549,12 +586,14 @@ data access, not just the UI — for what is in the config when it runs; ipal-ki
|
||||
|
||||
## The release after 1.16.3 — two access fixes
|
||||
|
||||
- **Staff checks and a second auth collection.** `userMeetsRole` treated an account of any auth collection
|
||||
without a `roles` field as staff — a `customers` account passed every check of the plugin, admin ones
|
||||
included. Now only accounts of a staff collection can pass: the panel's login collection plus
|
||||
`access.staffCollections` ([access.md](./access.md#who-is-staff)). The injected auth collection uses
|
||||
`adminOrSelfIn(slug)`, so an account of another collection with the same numeric id no longer counts as "self".
|
||||
- **Staff checks and a second auth collection.** Roles and the "no roles field" rule counted for an account of
|
||||
any auth collection — a `customers` account passed the plugin's staff checks, and with its own `roles` field
|
||||
also `isAdmin`, `adminOnly` and the rest. Now the staff-collection check comes first everywhere: the panel's
|
||||
login collection, `access.authCollection` and `access.staffCollections`
|
||||
([access.md](./access.md#who-is-staff)). The injected auth collection uses `adminOrSelfIn(slug)`, so an
|
||||
account of another collection with the same numeric id no longer counts as "self".
|
||||
- **2FA and the plugin's own data.** See "What the second factor covers" above.
|
||||
- **The 2FA package's endpoints** accept accounts of the 2FA collection only ("The 2FA package's endpoints").
|
||||
- After upgrading: [PROGRAMISTA.md](./dev/PROGRAMISTA.md) upgrade table, and the CHANGELOG entry of that release.
|
||||
|
||||
## Form files (`forms.attachments`)
|
||||
@@ -591,7 +630,8 @@ size while reading, content signature, container and macro checks, an optional `
|
||||
|
||||
## Turn off, override, extend
|
||||
|
||||
- **2FA check:** `twoFactor.guard: false` turns ipal-kit's own second-factor check off (not recommended);
|
||||
- **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.
|
||||
- **Turn off:** headers — do not call `buildSecurityHeaders`, or `null` / `false` per header (`frameOptions`,
|
||||
`referrerPolicy`, `permissionsPolicy`, `coop`), `hsts: false`; CSP — leave out `csp` (the default);
|
||||
|
||||
Reference in New Issue
Block a user