Security: staff checks only for staff collections; 2FA covers what the plugin adds
Staff check (userMeetsRole): the 'no roles field = every account passes' rule applied to the account's own collection, so an account of a second auth collection (customers) passed every staff check. It now applies only to staff collections: the panel's login collection plus the new access.staffCollections. The injected auth collection uses the new adminOrSelfIn(slug), so an account of another collection with the same numeric id is not 'self'. 2FA: @clocklimited/payload-2fa wraps the collections and globals present when it runs; ipalKit's own globals and collections were added later and stayed unwrapped, so a password without the TOTP code opened them over REST and GraphQL. ipal-kit now has its own second-factor check (secondFactorPassed / requireSecondFactor): applied to every collection and global at the end of ipalKit, again in onInit for entities added by plugins listed after it, and inside userMeetsRole and the endpoints that take a project access function. It fails closed: an unrecognised user shape is refused, and startup stops when the injected 2FA plugin lacks the parts the check reads (twoFactor.guard: false opts out). Tests through real HTTP requests (REST and GraphQL) against Payload's route handlers, plus the reference smoke test. Docs, agent guide, skills and the reference skills copy updated; changelog entry without a version. Co-Authored-By: Claude Fable 5.2 <[email protected]>
This commit is contained in:
co-authored by
Claude Fable 5.2
parent
bc1045a5b7
commit
0c61ac231b
@@ -8,6 +8,55 @@ versions at once, go through every "Requires project changes" section in order,
|
||||
version you have. A new release = a new section at the top; we remove the oldest ones only
|
||||
once there are more than 20.
|
||||
|
||||
## Unreleased — security fixes (version to be set at release)
|
||||
|
||||
### Security
|
||||
- **2FA now covers what the plugin adds.** The 2FA package wraps the collections and globals that exist when it
|
||||
runs; the plugin's own globals and collections were added afterwards and were not wrapped. With 2FA on, an
|
||||
account that had typed its **password but not the code** could read and change them over the API (REST and
|
||||
GraphQL): Site settings, Site integrations (including the SMTP password and the Turnstile secret), Cookie banner,
|
||||
Notifications, forms, form submissions, consent records, cookie review, stats, and the plugin's staff endpoints.
|
||||
The project's own collections and the user accounts were protected. **Affects every site with 2FA on, in every
|
||||
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)).
|
||||
|
||||
### 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).
|
||||
|
||||
### 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.
|
||||
- **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
|
||||
simply do it once, it is cheap;
|
||||
- look through **Site settings and Site integrations** for values nobody on the team set (analytics and tag
|
||||
manager IDs, sender address, construction mode), and through each **form's Emails tab** for unknown
|
||||
recipients or BCC addresses;
|
||||
- form submissions and consent records could have been read; whether that needs a data-protection assessment
|
||||
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`.
|
||||
- **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
|
||||
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.
|
||||
- **Check after deploy:** security.md → "What the second factor covers" → Check (three `403`), then log in fully
|
||||
and open Site integrations and a form submission in the panel.
|
||||
|
||||
## 1.16.3
|
||||
|
||||
### Changed
|
||||
|
||||
+48
-15
@@ -13,6 +13,7 @@ ipalKit({
|
||||
// defaultRole: 'user', // role of new accounts
|
||||
// firstUserAdmin: true, // the account from "Create first user" → admin
|
||||
// authAccess: { … }, // access of the injected auth collection (your keys win)
|
||||
// staffCollections: ['partners'], // more auth collections whose accounts are staff
|
||||
},
|
||||
// globalOverrides: { … }, // access / admin / hooks / fields of the plugin's globals
|
||||
})
|
||||
@@ -24,6 +25,7 @@ ipalKit({
|
||||
| `access.defaultRole` | `'user'` | role of a new account when an admin did not set one |
|
||||
| `access.firstUserAdmin` | `true` | the account from the "Create first user" screen (`…/first-register` on an empty collection) gets `['admin']`, even when the form picked `user`; `false` = it gets what was submitted |
|
||||
| `access.authAccess` | see the table below | `access` of the **injected** auth collection, merged over the default (your keys win) |
|
||||
| `access.staffCollections` | `[]` | more auth collections whose accounts count as **staff**, besides the one the panel logs in with (`admin.user`); see "Who is staff" |
|
||||
| `globalOverrides` | — | changes to the plugin's globals: an object merges `access` / `admin` key by key (your keys win) and appends `hooks` (yours run after the plugin's), other keys (label, fields, …) replace; a function `(global) => global` takes over the whole global |
|
||||
|
||||
The `roles` field (select hasMany, required, `saveToJWT`): readable without limits; only an admin
|
||||
@@ -40,7 +42,7 @@ only checks that someone is logged in.
|
||||
|
||||
| Resource | Read | Write | How to change |
|
||||
|---|---|---|---|
|
||||
| auth collection **injected** by the plugin, with roles | admin: everyone; others: only themselves | `create` / `delete` / `unlock`: admin; `update`: admin or self | `access.authAccess`, or your own collection |
|
||||
| auth collection **injected** by the plugin, with roles | admin: everyone; other accounts **of that collection**: only themselves (`adminOrSelfIn`) | `create` / `delete` / `unlock`: admin; `update`: admin or self | `access.authAccess`, or your own collection |
|
||||
| Site settings, Cookie banner, Notifications | public | `editor+` | `globalOverrides` |
|
||||
| Site integrations | admin | admin | `globalOverrides` |
|
||||
| Forms | public (Emails tab only `editor+`) | `editor+` | `forms.formOverrides.access`, the Emails field in `formOverrides.fields` |
|
||||
@@ -58,27 +60,54 @@ ipalKit({
|
||||
```
|
||||
|
||||
The project's own auth collection keeps its own `access` — the plugin only adds the
|
||||
`roles` field. Give it at least `update: adminOrSelf`, `delete: adminOnly`, `create: adminOnly`,
|
||||
`roles` field. Give it at least `update: adminOrSelfIn('users')`, `delete: adminOnly`, `create: adminOnly`,
|
||||
`unlock: adminOnly`: Payload's default lets any logged-in account change the email and password
|
||||
of another account and unlock any account. A collection injected **without** `access` (no roles)
|
||||
keeps Payload's default rules — without roles all accounts are equal.
|
||||
|
||||
> **Without `access` there is no `roles` field**, so `isAdmin` always returns `false`. The plugin's own
|
||||
> staff features therefore check with `userMeetsRole(req, minimum)`: when the user's auth collection has no
|
||||
> `roles` field, every logged-in account passes (as in Payload's default — without roles all accounts are
|
||||
> equal). That keeps Site integrations, the settings globals, `/api/ipal/test-email`, stats, consent records
|
||||
> and form submissions reachable. To narrow them without roles: `globalOverrides` for the globals,
|
||||
> `forms.formSubmissionOverrides` for submissions, or add `access` to get roles.
|
||||
## Who is staff
|
||||
|
||||
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:
|
||||
|
||||
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).
|
||||
|
||||
**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.
|
||||
|
||||
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
|
||||
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.
|
||||
- **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.
|
||||
|
||||
> **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
|
||||
> `access.staffCollections`.
|
||||
|
||||
## Predicates (front end / hooks / access)
|
||||
|
||||
```ts
|
||||
import { isAdmin, isEditor, hasMinimumRole, userMeetsRole } from '@intecion/ipal-kit'
|
||||
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 logged-in user when the auth collection has no roles field
|
||||
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
|
||||
```
|
||||
|
||||
They take a loosely typed user (like `req.user`) and read `roles` defensively.
|
||||
@@ -88,7 +117,7 @@ They take a loosely typed user (like `req.user`) and read `roles` defensively.
|
||||
### Collection-level (return boolean | Where)
|
||||
|
||||
```ts
|
||||
import { adminOnly, adminOrEditor, adminOrSelf, requireRole, authenticated } from '@intecion/ipal-kit'
|
||||
import { adminOnly, adminOrEditor, adminOrSelf, adminOrSelfIn, requireRole, authenticated } from '@intecion/ipal-kit'
|
||||
|
||||
export const Articles = {
|
||||
slug: 'articles',
|
||||
@@ -101,8 +130,12 @@ export const Articles = {
|
||||
// ...
|
||||
}
|
||||
|
||||
// Users: everyone sees themselves, an admin sees everyone
|
||||
access: { read: adminOrSelf }
|
||||
// Users: everyone sees themselves, an admin sees everyone.
|
||||
// adminOrSelfIn(slug): "self" = an account of THAT collection. Use it for an auth collection whenever
|
||||
// the project has more than one: adminOrSelf only compares ids, and with numeric ids (Postgres, SQLite)
|
||||
// customer no. 5 would match staff account no. 5.
|
||||
access: { read: adminOrSelfIn('users') }
|
||||
access: { read: adminOrSelf } // fine with a single auth collection
|
||||
|
||||
// any minimum threshold
|
||||
access: { update: requireRole('editor') }
|
||||
@@ -143,10 +176,10 @@ Types: `AccessOption`, `Role`, `GlobalOverride`, `GlobalOverrides`, `IpalGlobalS
|
||||
|
||||
- **Turn off:** leave out `access` — no `roles` field, the auth collection keeps Payload's rules
|
||||
(or yours). `access.firstUserAdmin: false` stops giving admin to the first account.
|
||||
- **Override:** `access.authAccess` (injected collection), your own auth collection (wins whole),
|
||||
- **Override:** `access.staffCollections` (who is staff), `access.authAccess` (injected collection), your own auth collection (wins whole),
|
||||
`globalOverrides` (globals), `forms.formOverrides` / `formSubmissionOverrides` (forms),
|
||||
`defaultRole`. The role hierarchy (`ROLE_HIERARCHY`) is fixed.
|
||||
- **Extend:** `requireRole` / `requireRoleField`, predicates, `buildRolesField`, `injectRoles`,
|
||||
- **Extend:** `requireRole` / `requireRoleField`, `adminOrSelfIn`, predicates (`userMeetsRole`, `staffCollectionSlugs`), `buildRolesField`, `injectRoles`,
|
||||
`applyGlobalOverrides` in your own collections and globals.
|
||||
- **Check:** log in with a `user` account → `PATCH /api/globals/site-settings` = 403,
|
||||
`DELETE /api/users/<admin id>` = 403; the account from "Create first user" has the `admin` role.
|
||||
|
||||
+17
-3
@@ -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); `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)`; `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 |
|
||||
@@ -580,6 +580,19 @@ By default: `pages`, `media` + the plugin's globals (`site-settings`,
|
||||
you need extra fields (then your own `Users.ts` with the slug from `access.authCollection`;
|
||||
the plugin adds roles and 2FA to it).
|
||||
|
||||
**A second auth collection** (`customers`, `members`, a client zone) — only when the client requires accounts
|
||||
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").
|
||||
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`.
|
||||
|
||||
**NEVER:** a second `media`, `daneFirmy`/`settings`/
|
||||
`navigation`/`footer` as collections (they are globals), FAQ/hero/features as collections
|
||||
(they are blocks), a collection for a single thing (that is a page or a global).
|
||||
@@ -1040,7 +1053,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`, `authenticated`, `requireRole`, `hasMinimumRole` (+ `…Field`); injected `users`: `access.authAccess`, first user = admin (`access.firstUserAdmin`) | 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 |
|
||||
| Data from globals | `getGlobal`, `getSiteSettings`, `getSiteIntegrations` | payload-helpers.md |
|
||||
|
||||
**Links and navigation**
|
||||
@@ -1134,7 +1147,7 @@ add missing hosts with flags / `extra`; (3) change `mode` to `'enforce'` in both
|
||||
| Plugin globals: write editor+ (Site integrations: admin) | — | `ipalKit({ globalOverrides: { <slug>: { access, admin, hooks } } })`; a function `(global) => global` takes over (`applyGlobalOverrides`) |
|
||||
| Global saves revalidate the layout (with `ipalKit({ revalidatePath })`) | omit `revalidatePath`; once: `context: { disableRevalidate: true }` | `buildGlobalRevalidateHook` on your own globals |
|
||||
| Form files (`forms.attachments`): off; when on — 10 MB, PDF/DOC/DOCX ticked, programs/macros/archives refused, no antivirus, Graph sends files of 3 MB and more through a draft it deletes | omit `attachments`; `forms.fields.file: false`; `mailAdapter({ graph: { largeAttachments: false } })` | `maxSizeMB` / `maxTotalMB` / `maxFiles` / `fileTypes` / `allowRisky` / `scan` / `strictPdf` / `notice` / `submit`; `buildFileBlock`; `formSubmissionOverrides.fields` for the file fields of a submission |
|
||||
| Staff features without `access` (no roles field): every logged-in account passes (`userMeetsRole`) | add `access` (roles decide) | `globalOverrides`, `forms.formSubmissionOverrides`, `consentLog.collectionOverrides`, `stats.collectionOverrides` |
|
||||
| Staff features without `access` (no roles field): every account of the panel's login collection passes (`userMeetsRole`); accounts of other auth collections never do | add `access` (roles decide) | `access.staffCollections` (more staff collections), `globalOverrides`, `forms.formSubmissionOverrides`, `consentLog.collectionOverrides`, `stats.collectionOverrides` |
|
||||
| Cookie check (`crawl`): start editor+ or the token, results token-only for the running job, latest result only, dashboard warning on, e-mail off until recipients are set | omit `crawl`; `crawl.dashboard: false` | `crawl.serviceUrl` / `token` / `siteUrl` / `maxPages` / `acceptSelector` / `consentMode` / `trackerHosts` / `globalOverride`; *Cookie check → Warning e-mails to*; building blocks `ingestCrawlResult`, `findCrawlViolations`, `parseCrawlResult` |
|
||||
| Cookie admin: one *Cookies* entry — review list and site check as tabs, their own entries out of the navigation (pages and API kept) | `cookieScanner.adminLayout: 'separate'` | `addCookieScannerTabs`, `CookieReviewTab`, `CookieSiteCheckTab`; `collectionOverrides` / `crawl.globalOverride` win |
|
||||
| Theme choice in localStorage under `theme` (next-themes' key); old `ipal-theme` moved before paint; declared to the cookie scanner as necessary local storage | — | `ipalKit({ theme: { storageKey } })`; `<ThemeSwitcher storageKey>` / `useTheme({ storageKey })` |
|
||||
@@ -1146,6 +1159,7 @@ 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 |
|
||||
| `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 |
|
||||
|
||||
@@ -48,8 +48,13 @@ Ask only when the brief leaves a business question open (e.g. "do posts have aut
|
||||
generateStaticParams, hreflang.
|
||||
3. Entry list = a block (EntriesList) with `getEntries`; the entry page uses
|
||||
`resolveRoute` (type `entry`); JSON-LD per seo.md (e.g. Article).
|
||||
4. `pnpm generate:types`, `pnpm payload generate:importmap`.
|
||||
5. Postgres with migrations → `pnpm payload migrate:create`.
|
||||
4. **An auth collection for visitors** (`auth: true`: customers, members) only when the client requires it
|
||||
(AGENT.md §5 "A second auth collection"): `admin: { user: 'users' }` in `buildConfig`, `access` with
|
||||
`adminOrSelfIn('<slug>')` for read / update and an explicit `create`, never in `access.staffCollections`.
|
||||
Its accounts pass none of the plugin's staff checks. Check: its token → `403` from
|
||||
`/api/globals/site-integrations` and `/api/form-submissions`.
|
||||
5. `pnpm generate:types`, `pnpm payload generate:importmap`.
|
||||
6. Postgres with migrations → `pnpm payload migrate:create`.
|
||||
|
||||
## 4. Check
|
||||
The **ipal-audit** skill. By hand: an entry in the panel → visible at `/<locale>/<archive>/<slug>`,
|
||||
|
||||
@@ -34,6 +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") |
|
||||
| `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) |
|
||||
|
||||
@@ -25,11 +25,12 @@ description: Complete map of everything @intecion/ipal-kit provides — every ip
|
||||
| `i18n.fallback` | `true` | `localization.fallback` | `false` |
|
||||
| `i18n.locales[]` `{ code, label, rtl? }` | — | list of languages (min. 1); `rtl: true` → `rtl` in Payload | adding a language: skill **ipal-locale-add** |
|
||||
| admin languages (no option) | English + Polish | `i18n.supportedLanguages` set to `{ en, pl }` when the project has none; plugin component texts in `i18n.translations.<lang>.ipal` (`adminTexts`); every plugin label is `{ en, pl }` (rules: `docs/dev/admin-ux.md`) | your own `i18n.supportedLanguages` wins; override a component text with `i18n.translations.<lang>.ipal.<key>`; field/global labels via `globalOverrides` / `collectionOverrides` — see i18n.md "Admin panel languages and texts" |
|
||||
| `access` | none | `roles` field (`user` < `editor` < `admin`, `saveToJWT`) in the auth collection | omit → **no roles**: every logged-in account passes the plugin's admin/editor checks (`userMeetsRole`): Site integrations, the e-mail test, stats, consent-records, settings globals, `form-submissions`. Narrow them with `globalOverrides` / collection overrides |
|
||||
| `access` | none | `roles` field (`user` < `editor` < `admin`, `saveToJWT`) in the auth collection | omit → **no roles**: every account of the panel's login collection passes the plugin's admin/editor checks (`userMeetsRole`; accounts of other auth collections never pass): Site integrations, the e-mail test, stats, consent-records, settings globals, `form-submissions`. Narrow them with `globalOverrides` / collection overrides |
|
||||
| `access.authCollection` | — (required in `access`) | collection that gets `roles`; also the slug of the injected auth collection | your own collection with that slug wins |
|
||||
| `access.defaultRole` | `'user'` | `defaultValue` of the `roles` field | `'editor'` / `'admin'` |
|
||||
| `access.authAccess` | `{ create: adminOnly, delete: adminOnly, read: adminOrSelf, unlock: adminOnly, update: adminOrSelf }` | 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.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 |
|
||||
| `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 | — |
|
||||
@@ -37,6 +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.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 | — |
|
||||
|
||||
@@ -53,6 +53,7 @@ Admin panel components from `@intecion/ipal-kit/admin` — the project does NOT
|
||||
| `adminOnly` | `@intecion/ipal-kit` | Collection `Access`: `admin` role only. In `access.read/create/update/delete`. |
|
||||
| `adminOrEditor` | `@intecion/ipal-kit` | Collection `Access`: `editor` or `admin`. Typical for content edited in the panel. |
|
||||
| `adminOrSelf` | `@intecion/ipal-kit` | Collection `Access`: admin sees everything, a logged-in user only their own document (`Where` `id = user.id`), anonymous nothing. E.g. `users.read`. |
|
||||
| `adminOrSelfIn(slug)` | `@intecion/ipal-kit` | `adminOrSelf` for the auth collection `slug`: only an account **of that collection** is "self"; an account of another auth collection gets nothing. Use it whenever the project has more than one auth collection (with numeric ids `adminOrSelf` would match customer no. 5 with staff account no. 5). The injected auth collection uses it. |
|
||||
| `authenticated` | `@intecion/ipal-kit` | Collection `Access`: any logged-in user. |
|
||||
| `requireRole(minimum)` | `@intecion/ipal-kit` | Collection `Access` factory: at least the given role (`'user' \| 'editor' \| 'admin'`). |
|
||||
| `adminOnlyField` | `@intecion/ipal-kit` | `FieldAccess` (boolean only): field for admin only. In `field.access.read/update`. |
|
||||
@@ -61,12 +62,13 @@ Admin panel components from `@intecion/ipal-kit/admin` — the project does NOT
|
||||
| `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 logged-in user when the user's auth collection has no `roles` field (the project omitted `access`). The plugin's staff features use it (Site integrations, settings globals, test e-mail, stats, consent records, form submissions). Use it in your own access when the project may run without roles. |
|
||||
| `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`. |
|
||||
| `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. |
|
||||
|
||||
**Types:** `Role` (`'user' \| 'editor' \| 'admin'`), `AccessOption` (the plugin's `access` option: `authCollection`, `defaultRole`, `authAccess`, `firstUserAdmin`).
|
||||
**Types:** `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`
|
||||
|
||||
@@ -583,6 +585,8 @@ 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. |
|
||||
| `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`). |
|
||||
|
||||
@@ -217,11 +217,17 @@ the panel shows Site settings, Site integrations, Cookies, Form messages, the Fo
|
||||
(discouraged); without an injected `plugin: payloadTotp` it also throws. `forceSetup` currently always `true`.
|
||||
- `users`: the injected collection lets admins manage everyone and others only themselves — loosen with
|
||||
`access: { authCollection: 'users', authAccess: { read: authenticated } }` (your keys win); your own collection with
|
||||
that slug wins whole (the plugin only adds `roles` — give it `adminOrSelf` / `adminOnly`). The first account
|
||||
that slug wins whole (the plugin only adds `roles` — give it `adminOrSelfIn('users')` / `adminOnly`). The first account
|
||||
(Create first user) gets `admin` — `access.firstUserAdmin: false` turns that off. `localization` currently always
|
||||
overridden from `i18n`.
|
||||
- 2FA wraps the panel's login collection (`admin.user`); a different `twoFactor.collectionSlug` stops startup with
|
||||
`[ipal] twoFactor…` unless `allowCollectionMismatch: true`.
|
||||
`[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").
|
||||
- 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
|
||||
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
|
||||
Integrations: admin), the `/api/ipal/test-email` endpoint and dashboard alerts — currently always present; extend
|
||||
`siteSettingsFields` / `integrationsFields`; change access, admin or hooks with
|
||||
|
||||
@@ -328,6 +328,26 @@ recommended, not required (the plugin's peer range stays `^3.90.2`):**
|
||||
21.0.4; `pnpm audit --prod` → no high or critical; `pnpm exec ipal-doctor` → no `versions` finding; Coolify Terminal
|
||||
`node -v` → 22.23.5 or later; the panel opens, a document saves, a form submission arrives.
|
||||
|
||||
**→ 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;
|
||||
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.
|
||||
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
|
||||
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.
|
||||
|
||||
## 2. Inventory (no code changes)
|
||||
**What changed for projects** between your old and new plugin version is exactly the reference site's diff —
|
||||
`git diff v<old> v<new> -- reference/` in the ipal-kit repo (or the two `docs/agent/reference-site/INDEX.md` files):
|
||||
|
||||
@@ -672,6 +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" |
|
||||
|
||||
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`.
|
||||
|
||||
+79
-3
@@ -344,8 +344,9 @@ addition to real safeguards, not a replacement for them.
|
||||
|
||||
The plugin enforces two-factor authentication (TOTP) for ALL panel users —
|
||||
with no way to turn it off per user. Every project gets it automatically.
|
||||
It uses the proven `@clocklimited/payload-2fa` (it wraps access control — TOTP is
|
||||
checked before access to DATA, not only the panel UI).
|
||||
It uses `@clocklimited/payload-2fa`, which wraps access control: TOTP is checked before access to DATA
|
||||
(REST, GraphQL), not only in the panel UI. On top of the package ipal-kit runs its own check, so the second
|
||||
factor also covers what the package cannot see — see "What the second factor covers" below.
|
||||
|
||||
### Dependency
|
||||
|
||||
@@ -368,6 +369,7 @@ ipalKit({
|
||||
plugin: payloadTotp, // ← INJECT — see below why
|
||||
// collectionSlug: 'users', // default: the panel login collection (admin.user, else the first auth collection)
|
||||
// allowCollectionMismatch: true, // deliberate only: 2FA on a collection other than admin.user
|
||||
// guard: false, // NOT recommended: ipal-kit's own check off, the package's wrapper only
|
||||
},
|
||||
})
|
||||
```
|
||||
@@ -390,6 +392,67 @@ gets the injected plugin.
|
||||
The plugin sets `forceSetup: true` — every user MUST set up TOTP after
|
||||
logging in. There is no per-user "on/off" option.
|
||||
|
||||
### What the second factor covers
|
||||
|
||||
The package wraps the `access` functions of the collections and globals that are in the config **at the moment
|
||||
it runs**. ipalKit runs it early, so the plugin's own globals and collections (Site settings, Site integrations,
|
||||
Cookie banner, Notifications, forms, form submissions, consent records, cookie review, stats) and anything a
|
||||
plugin listed after `ipalKit` adds were not wrapped. **Up to 1.16.3 a staff password without the TOTP code
|
||||
therefore read and changed them over the API.** Since the release after 1.16.3 ipal-kit closes that itself:
|
||||
|
||||
| Where | How |
|
||||
|---|---|
|
||||
| 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 plugin's endpoints (`/api/ipal/test-email`, `cookie-scan`, `cookie-approval`, `cookie-crawl`, the `access` option of `/api/ipal/doctor`) | `userMeetsRole` and `secondFactorPassed` |
|
||||
|
||||
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
|
||||
entered inside the panel.
|
||||
|
||||
An account of the 2FA collection passes when it logged in with **password and code**, or uses an **API key**
|
||||
(`auth.useAPIKey`), or has **not set TOTP up yet** (the setup screen needs that; the package behaves the same).
|
||||
Everything else is refused, including a user object the check does not recognise. Accounts of other auth
|
||||
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.
|
||||
|
||||
Two things follow for project code:
|
||||
|
||||
- `payload.find({ …, user, overrideAccess: false })` on a plugin collection needs a `user` that came from
|
||||
`payload.auth({ headers })` (it carries how the account logged in). A user fetched with `findByID` and passed
|
||||
by hand is refused when it has TOTP set up.
|
||||
- Your own endpoints do not go through `access`. Guard them:
|
||||
|
||||
```ts
|
||||
import { requireSecondFactor, secondFactorPassed, userMeetsRole } from '@intecion/ipal-kit'
|
||||
|
||||
// an endpoint
|
||||
handler: async (req) => {
|
||||
if (!req.user || !secondFactorPassed(req)) return Response.json({ ok: false }, { status: 403 })
|
||||
// or: if (!userMeetsRole(req, 'editor')) … — it includes the second-factor check
|
||||
}
|
||||
// an access function (collections and globals in the config are wrapped for you; this is for the rest)
|
||||
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
|
||||
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.
|
||||
|
||||
**Check** (replace the address and the account):
|
||||
|
||||
```bash
|
||||
# password only, no code → 403 on all three
|
||||
TOKEN=$(curl -s https://example.com/api/users/login -H 'content-type: application/json' \
|
||||
-d '{"email":"admin@example.com","password":"…"}' | node -pe 'JSON.parse(require("fs").readFileSync(0)).token')
|
||||
for p in globals/site-integrations form-submissions users; do
|
||||
curl -s -o /dev/null -w "$p %{http_code}\n" -H "Authorization: JWT $TOKEN" https://example.com/api/$p
|
||||
done
|
||||
```
|
||||
|
||||
### Import map (required)
|
||||
|
||||
The 2FA screens and the redirect to them are admin components. After adding `twoFactor`, and after every
|
||||
@@ -469,7 +532,8 @@ An admin can reset another user's 2FA (when they lose their phone) — through
|
||||
Chosen because it wraps ACCESS CONTROL (TOTP before data access) + forceSetup
|
||||
(enforced for everyone). Other 2FA plugins for Payload only gate /admin
|
||||
navigation — a user with a password can bypass them through REST/GraphQL/Bearer. @clocklimited protects
|
||||
data access, not just the UI.
|
||||
data access, not just the UI — for what is in the config when it runs; ipal-kit's own check covers the rest
|
||||
("What the second factor covers").
|
||||
|
||||
## 1.9.1 — security review results
|
||||
|
||||
@@ -483,6 +547,16 @@ data access, not just the UI.
|
||||
- Uploads: `buildUploadSecurityHeaders()` in `next.config.ts` (an SVG cannot run a script on the site's domain).
|
||||
- `users`: the plugin injects an auth collection when the project has none (roles and 2FA always attach).
|
||||
|
||||
## 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".
|
||||
- **2FA and the plugin's own data.** See "What the second factor covers" above.
|
||||
- After upgrading: [PROGRAMISTA.md](./dev/PROGRAMISTA.md) upgrade table, and the CHANGELOG entry of that release.
|
||||
|
||||
## Form files (`forms.attachments`)
|
||||
|
||||
Files attached to a form are **never stored and cannot be downloaded**: they are checked in memory, attached to
|
||||
@@ -517,6 +591,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);
|
||||
`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);
|
||||
X-Powered-By hiding — `withSecurityConfig(config, { hidePoweredBy: false })` or do not call it;
|
||||
|
||||
Reference in New Issue
Block a user