From ccc6f859245bfdadaa84d545e7c72950a0275ba4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rados=C5=82aw=20Smoli=C5=84ski?= Date: Wed, 25 Nov 2026 02:59:44 +0100 Subject: [PATCH] Security follow-ups to 1.16.7: changelog, access guide, skills, API table, release gate, reference index Co-Authored-By: Claude Fable 5.2 --- docs/CHANGELOG.md | 67 +++++++++++++++++++ docs/access.md | 29 +++++++- docs/agent/AGENT.md | 2 +- docs/agent/reference-site/INDEX.md | 47 +++++++++++-- docs/agent/skills/ipal-debug/SKILL.md | 2 + .../skills/ipal-reference/resources/api.md | 4 +- docs/agent/skills/ipal-setup/SKILL.md | 2 +- docs/agent/skills/ipal-upgrade/SKILL.md | 8 ++- docs/dev/PROGRAMISTA.md | 20 +++++- docs/doctor.md | 2 +- reference/.agents/skills/ipal-debug/SKILL.md | 2 + .../skills/ipal-reference/resources/api.md | 4 +- reference/.agents/skills/ipal-setup/SKILL.md | 2 +- .../.agents/skills/ipal-upgrade/SKILL.md | 8 ++- scripts/reference-index.mjs | 5 +- 15 files changed, 183 insertions(+), 21 deletions(-) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 080a8f0..0ebc86e 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -8,6 +8,73 @@ 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 follow-ups to 1.16.7 (version to be set at release) + +> **Read before upgrading.** No option, schema, migration or import-map change. Two points: +> **What can stop people:** on a project's own staff collection **without access rules of its own** whose +> accounts can hold `editor` or `admin` although its roles are not just the plugin's — a `roles` select such as +> `user, editor, admin, boss` or `viewer, editor`, or a `roles` field that is text or json — an account that is +> not an admin can no longer create, delete or unlock accounts there, change another account, or change +> anybody's roles. If **no** staff account holds `admin`, nobody can (the start log says so; the way out is +> below). And a site **built with Turbopack** (`next build` without `--webpack`): see Security. + +### Security +- **A staff collection whose accounts can hold `editor` or `admin` gets the admin rules.** The plugin's checks go + by the value on the account: `admin` on an account of a staff collection makes a plugin admin, `editor` an + editor — whatever else the collection's `roles` field offers. But a project's own staff collection without + rules got the admin rules only when ALL its role values were the plugin's; otherwise "an account of this + collection" could create, change and delete accounts. So with roles `user, editor, admin, boss` an account + with the role `user` created an `admin` there (or set the admin's password) and then read Site integrations, + changed other staff collections' roles and listed the panel's accounts; with `viewer, editor` a `viewer` made + an `editor` who saves Site settings; the same with a `roles` field that is text or json. In 1.16.7 and, wider, + before it. Now such a collection — in the config or added by a later plugin — gets: create, delete, unlock — + an admin; update — an admin or the account itself; roles — only an admin. Not affected: `access.authCollection`, + collections with rules of their own, a `roles` select whose values hold neither `editor` nor `admin`. No known + site has such a collection ([access.md](./access.md) "Account rules"). +- **A Turbopack build of a site published the plugin's `package.json`.** The plugin read its own version from + that file by a path relative to its module, and a bundler takes such a file for an asset: Turbopack copied it + to `/_next/static/media/package..json`, where anyone could fetch it. It is the **plugin's** manifest, not + the project's: the plugin's name and version, its dependency lists with version ranges (also the development + ones), its script names, and the addresses of the package registry and the git repository it comes from. **No + secret, token or password**, and nothing of the project. The file name is a content hash and no page links to + it. A webpack build (`next build --webpack`, what the starter and the reference site use) kept the file on the + server side: not served. The version is now a constant in the code (`src/version.ts`); nothing is read from + disk at run time. + +### Added +- A start-log warning when staff collections run on the admin rules and no staff account holds `admin`. +- `pnpm e2e:built` (plugin repository): builds the reference site with webpack and with Turbopack and checks, + on each, the account rules on a built site and that no package manifest is among the public files. Part of + the release gate (PROGRAMISTA §8.1). The reference site's Playwright runs reset the test admins first + (`e2e/global-setup.ts`), so a spec no longer fails because of what ran before it. +- Exports: `canHoldStaffRole`, `staffCollectionsNobodyManages`. + +### Requires project changes +- **A staff collection of your own, without access rules, whose accounts can hold `editor` or `admin`** (a + `roles` select with one of them next to values of your own, or a text / json `roles` field): only an admin + creates, deletes and unlocks accounts there and changes roles; another account is changed by an admin or by + itself. If accounts with a role of your own (`boss`, `viewer`) managed accounts there, write that as the + collection's own rules (`access.create` / `update` / `delete`, field access on `roles`) — the plugin gives + your values no rights. In a collection where nobody can be an `admin` (`viewer, editor`), accounts are + managed by an admin of another staff collection (the panel's). +- **Read the start log after the upgrade.** `[ipal] No staff account holds the role "admin", so NOBODY can + create, delete or unlock accounts in "…"`: no account of any staff collection is an admin. Give one account + the role with a script (`payload.update({ collection, id, data: { roles: ['admin'] } })`, `pnpm payload run`), + or write the collection's own rules. To switch the default off for every staff collection: `accounts: { + adminOnlyCreate: false, adminOnlyWrite: false }` (that also takes the protection off). +- **A site built with Turbopack:** update and rebuild — the new build has no `package..json` under + `/_next/static/media/`. Check: `find .next/static -name 'package*.json'` prints nothing. Nothing to do for a + webpack build. +- `pnpm ipal:skills`. + +### Known limitations +- A staff collection **without a `roles` field** is unchanged: every account of it is an admin to the plugin. +- A `roles` select of your own whose values hold neither `editor` nor `admin` is unchanged: inside it every + account may create, change and delete accounts (`ipal-doctor --url` → `staff-own-roles`). +- The warning counts accounts whose `roles` hold `admin`; where a `roles` field cannot be queried it says nothing. +- **Not run for this change:** the starter built with Turbopack (it is generated from the reference site and uses + the same plugin code; the reference site was built with both bundlers). + ## 1.16.7 — hardening > **Read before upgrading.** Several defaults get stricter. Most sites change nothing, but check diff --git a/docs/access.md b/docs/access.md index e1577b6..8d731fa 100644 --- a/docs/access.md +++ b/docs/access.md @@ -290,11 +290,36 @@ list the staff accounts, and lift the lock after failed logins. | The collection | `create`, `delete`, `unlock` | `update` | the `roles` field (when it has no `access.update`) | `read`, `readVersions` | |---|---|---|---|---| -| carries **the plugin's roles**: it is `access.authCollection`, or has a `roles` select whose values are all `user` / `editor` / `admin` (`hasPluginRoles`) | an admin (`staffCreateAccess`) | an admin, or the account itself (`staffUpdateAccess(slug)`) | only an admin changes it (`rolesByAdminOnly`) | a staff account (`staffReadAccess`) | -| has **roles of its own** (`superadmin`, `writer`, …) or no `roles` field — the plugin cannot tell who its admins are | an account of that same collection, or a plugin admin of another staff collection (`sameStaffCollectionAccess(slug)`) | the same | an account never changes its **own** (`rolesNotOwn(slug)`) | a staff account | +| carries **the plugin's roles**: it is `access.authCollection`, or has a `roles` select whose values are all `user` / `editor` / `admin` (`hasPluginRoles`), **or one whose accounts can hold `editor` or `admin`**, whatever else its `roles` field offers (`canHoldStaffRole`, below) | an admin (`staffCreateAccess`) | an admin, or the account itself (`staffUpdateAccess(slug)`) | only an admin changes it (`rolesByAdminOnly`) | a staff account (`staffReadAccess`) | +| has **roles of its own that hold neither `editor` nor `admin`** (`superadmin`, `writer`, …) or no `roles` field — the plugin cannot tell who its admins are | an account of that same collection, or a plugin admin of another staff collection (`sameStaffCollectionAccess(slug)`) | the same | an account never changes its **own** (`rolesNotOwn(slug)`) | a staff account | Always "fully signed in": a session that still owes its second factor passes none of them. +**A `roles` field that can hold `editor` or `admin`.** The plugin's checks go by the **value on the account** +(`isAdmin`, `isEditor`): an account of a staff collection whose `roles` hold `admin` is a plugin admin, one that +holds `editor` edits the site's settings — whatever else the field offers. So wherever an account of the +collection **can** hold one of the two, the collection gets the admin rules (`canHoldStaffRole`): + +| The collection's `roles` field | Rules | +|---|---| +| a select with `editor` or `admin` among its values — `user, editor, admin, boss`; `viewer, editor` | the admin rules (first row above) | +| a field whose values cannot be listed — text, json, a select without options: anything can be written there | the admin rules | +| a select whose values are all your own and hold neither — `lead, member` | "an account of that same collection" (second row) | +| no `roles` field | second row; every account of it is an admin to the plugin (below) | + +Otherwise any account of such a collection could hand the value out: create an `admin` and be in Site +integrations and every other staff collection, or create an `editor` and change the site's settings. (Until this +change these collections got the second row, and an account with the lowest role could do exactly that.) +**What it means for your accounts:** a role the plugin does not know (`boss`, `viewer`) carries no rights of the +plugin's — such an account no longer creates, deletes or unlocks accounts there, changes another account or +anybody's roles. Give it what it needs with rules of your own (`access.create` / `update` / `delete`, field +access on `roles`), which win as always. In a collection where nobody can be an `admin` (`viewer, editor`) the +accounts are managed by an admin of another staff collection — the panel's. +**If no staff account holds `admin` at all**, nobody can create, delete or unlock accounts in such a collection. +The start log says so: `[ipal] No staff account holds the role "admin", so NOBODY can create, delete or unlock +accounts in "…"`. Way out: give one account the role with a script (`payload.update`, Local API), or write the +collection's own rules. + **Roles of your own — what the plugin does and does not hold.** It cannot rank `superadmin` against `writer`, so inside such a collection it enforces one thing only: an account does not change its own roles. Everything else that was allowed inside the collection stays allowed — **every account of it may still create an account diff --git a/docs/agent/AGENT.md b/docs/agent/AGENT.md index b63edc0..49f0e11 100644 --- a/docs/agent/AGENT.md +++ b/docs/agent/AGENT.md @@ -1172,7 +1172,7 @@ add missing hosts with flags / `extra`; (3) change `mode` to `'enforce'` in both | Stored secrets are write-only: `smtpPassword` and `turnstileSecretKey` come back as `'********'` over REST, GraphQL and in the panel; an empty save keeps the value, `'[[clear]]'` removes it; server code reads the real value with the Local API. **The panel is the source — never add an env variable for them** (`TURNSTILE_SECRET_KEY` is deprecated) | `secrets: { writeOnly: false }` | `writeOnlySecret(field)` / `writeOnlySecrets(fields, names)` for your own secret fields; with versions on the entity add `hooks.afterRead: [maskSecretsOnRestore]` | | The SMTP password stays with its server: a save in the panel or over the API that changes the server, port or user name without the password is refused (`400` "Enter the password again…"), whatever the transport says — otherwise an admin session points the server at its own machine and a test e-mail hands the password over. A change of the transport alone asks for nothing. Seeds and scripts (Local API, access control off) are not asked | `secrets: { reenterOnChange: false }` | `writeOnlySecret(field, { boundTo: [...] })`, `buildKeepSecret`, `SMTP_PASSWORD_BOUND_TO` | | The admin panel opens for `editor` and above; an account with only `user` sees "Unauthorized" (the API is not touched). First start logs how many accounts are below the role | `accounts: { panelRole: 'user' }` (or `false`) | `panelRole: 'admin'`; your own `access.admin`; `panelAccess(role)` | -| Nobody creates an account for themselves, or takes one over. A staff collection (also the project's own, also one a later plugin adds) without a `create` / `update` / `delete` / `unlock` / `read` / `readVersions` rule gets one (on a collection a later plugin adds the plugin's rule is put in front of its own and both must allow; `custom: { ipal: { accountRules: false } }` on it keeps its own): with the plugin's roles — create, delete, unlock: an admin; update: an admin or the account itself; the `roles` field: only an admin. With roles of its own, or none: an account of that same collection, or a plugin admin, and an account never changes its own roles — **the plugin cannot rank a project's own roles: write that collection's rules** (`ipal-doctor` → `staff-own-roles`). `read`: a staff account. Payload's first-user route answers only for the panel's login collection (the first account, which becomes admin), in any spelling of the URL. `access.firstUserAdmin: false` with a default role below the panel role: the default panel role is not applied (logged), an explicit one is refused at start. With a slug in `access.staffCollections` that is not an auth collection Payload does not start (`/api/health` 503) | `accounts: { adminOnlyCreate: false, adminOnlyWrite: false, staffOnlyRead: false, firstUserRoute: 'all' }` | your own rule wins; `firstUserRoute: ['users', 'partners']`; a collection with open sign-up keeps its routes; `staffCreateAccess`, `staffUpdateAccess(slug)`, `staffReadAccess`, `sameStaffCollectionAccess(slug)`, `rolesByAdminOnly`, `rolesNotOwn(slug)`, `hasPluginRoles`, `applyStaffAccountAccess`, `adoptLateAuthCollections`, `buildFirstUserEndpoint` | +| Nobody creates an account for themselves, or takes one over. A staff collection (also the project's own, also one a later plugin adds) without a `create` / `update` / `delete` / `unlock` / `read` / `readVersions` rule gets one (on a collection a later plugin adds the plugin's rule is put in front of its own and both must allow; `custom: { ipal: { accountRules: false } }` on it keeps its own): with the plugin's roles, or wherever an account of it can hold `editor` or `admin` (`user, editor, admin, boss`; `viewer, editor`; a `roles` field that is text or json — the value on the account makes a plugin admin or editor) — create, delete, unlock: an admin; update: an admin or the account itself; the `roles` field: only an admin. With roles of its own that hold neither `editor` nor `admin`, or none: an account of that same collection, or a plugin admin, and an account never changes its own roles — **the plugin cannot rank a project's own roles: write that collection's rules** (`ipal-doctor` → `staff-own-roles`). `read`: a staff account. Payload's first-user route answers only for the panel's login collection (the first account, which becomes admin), in any spelling of the URL. `access.firstUserAdmin: false` with a default role below the panel role: the default panel role is not applied (logged), an explicit one is refused at start. With a slug in `access.staffCollections` that is not an auth collection Payload does not start (`/api/health` 503) | `accounts: { adminOnlyCreate: false, adminOnlyWrite: false, staffOnlyRead: false, firstUserRoute: 'all' }` | your own rule wins; `firstUserRoute: ['users', 'partners']`; a collection with open sign-up keeps its routes; `staffCreateAccess`, `staffUpdateAccess(slug)`, `staffReadAccess`, `sameStaffCollectionAccess(slug)`, `rolesByAdminOnly`, `rolesNotOwn(slug)`, `hasPluginRoles`, `applyStaffAccountAccess`, `adoptLateAuthCollections`, `buildFirstUserEndpoint` | | A password set on a staff account has at least 12 characters and is not the e-mail address; existing passwords are not checked | `accounts: { password: false }` | `password: { minLength }`; `checkPassword`, `buildPasswordRuleHook` | | While Turnstile cannot check (wrong secret, Cloudflare down): a text form is accepted, a form with files is refused | `forms: { turnstileOnConfigError: 'allow' }` | `'reject'`, `{ text, files }`; `turnstileOnConfigError` at a call site wins | | Dashboard alerts by role: integration details for admins, a neutral line for editors, nothing for others; cookie alerts for editors and above. `'all'` checks nothing — no role, no second factor | `dashboardAlerts: { integrations: 'all', cookies: 'all' }` | `integrations: 'editor'`; the components' `details` / `audience` props | diff --git a/docs/agent/reference-site/INDEX.md b/docs/agent/reference-site/INDEX.md index e49b92e..d81e54a 100644 --- a/docs/agent/reference-site/INDEX.md +++ b/docs/agent/reference-site/INDEX.md @@ -93,9 +93,10 @@ try { } /** - * Smoke tests against a built, seeded site: pnpm build && pnpm seed && pnpm payload run e2e/create-test-admin.ts. - * Run create-test-admin.ts again before repeating the tests within ten minutes: the 2FA verify limit (5 attempts per - * account in 10 minutes) is stored in the database, and that script clears the test admins' counts. + * Smoke tests against a built, seeded site: pnpm seed && pnpm build. + * The 2FA verify limit (5 attempts per account in 10 minutes) is stored in the database; the global setup resets the + * test admins and clears their counts before every run (e2e/global-setup.ts; E2E_SKIP_ADMIN_SETUP=1 for a run that + * needs an EMPTY database, the fresh-site spec). * E2E_BASE_URL picks the port (default 3100). Playwright starts its own server there and fails when the port is * taken, so another project's dev server is never tested by mistake; E2E_REUSE_SERVER=1 uses a server you started. */ @@ -103,6 +104,8 @@ const baseURL = process.env.E2E_BASE_URL ?? 'http://localhost:3100' export default defineConfig({ forbidOnly: !!process.env.CI, + // makes every run independent of the one before: test admins reset, stored 2FA attempt counts cleared + globalSetup: './e2e/global-setup.ts', projects: [{ name: 'chromium', use: { ...devices['Desktop Chrome'] } }], reporter: process.env.CI ? 'line' : 'list', retries: process.env.CI ? 1 : 0, @@ -1160,14 +1163,34 @@ Rules: AGENT.md §8a. | File | What it shows | |---|---| | `e2e/create-test-admin.ts` | two test admins with a known TOTP secret (the specs share out the five 2FA verify attempts per account), their stored verify counts cleared, and e-mail sending pointed at the tests' mail sink (local / CI database only) | -| `e2e/late-staff-fixture.ts` | test fixture, on only with E2E_LATE_STAFF=1: a plugin listed after ipalKit that adds a staff collection without rules and a visitor collection with open sign-up (below) | -| `e2e/late-staff.spec.ts` | the account rules on a BUILT site for a staff collection a later plugin adds (run after a webpack and a Turbopack build): a visitor account gets nothing, nobody raises its own role | +| `e2e/global-setup.ts` | Playwright global setup: resets the test admins and clears their stored 2FA attempt counts before every run, so specs do not depend on run order (below) | +| `e2e/late-staff-fixture.ts` | test fixture, on only with E2E_LATE_STAFF=1: one plugin before ipalKit (a staff collection of the config whose roles are the plugin's values plus one more) and one after it (a staff collection without rules, one whose roles field is text, a visitor collection with open sign-up) (below) | +| `e2e/late-staff.spec.ts` | the account rules on a BUILT site (run by `pnpm e2e:built` after a webpack and a Turbopack build): a staff collection a later plugin adds, and staff collections whose accounts can hold `admin` — a visitor account gets nothing, nobody raises its own role or makes an admin | | `e2e/smoke.spec.ts` | the smoke tests every release must pass: pages, showcase, forms (also a file sent by e-mail), sitemap, SEO/GEO, headers, consent, 2FA | | `e2e/smtp-sink.ts` | a local mail sink for the smoke tests: reads what the site really sent (recipients, attachments) | | `e2e/totp.ts` | RFC 6238 code generator for the 2FA sign-in in the smoke test, and the address of the second test admin (below) | | `e2e/two-factor-back.spec.ts` | browser test of the 2FA screens' `back` link (twoFactor.safeBack): a prepared link — script or another host — ends on the admin root, an ordinary one is followed | | `e2e/two-factor-setup.spec.ts` | browser check of "2FA setup required": the first admin of a fresh site, a new editor, the administrator's reset on the account page | +### `e2e/global-setup.ts` + +```ts +import { execFileSync } from 'node:child_process' + +/** + * Before every Playwright run: the test admins are made (or reset) and their stored 2FA attempt counts cleared + * (e2e/create-test-admin.ts). The count is kept in the database — 5 verify attempts per account in 10 minutes — + * so without this a second run within ten minutes, or one spec run after the whole suite, would find the test + * admin locked out: the result would depend on what ran before. Skipped when the test admin is not configured + * (the specs that need it skip themselves) or with E2E_SKIP_ADMIN_SETUP=1. + */ +export default function globalSetup(): void { + const { E2E_ADMIN_EMAIL, E2E_ADMIN_PASSWORD, E2E_SKIP_ADMIN_SETUP, E2E_TOTP_SECRET } = process.env + if (E2E_SKIP_ADMIN_SETUP === '1' || !E2E_ADMIN_EMAIL || !E2E_ADMIN_PASSWORD || !E2E_TOTP_SECRET) {return} + execFileSync('pnpm', ['payload', 'run', 'e2e/create-test-admin.ts'], { env: { ...process.env, NODE_ENV: 'development' }, stdio: 'inherit' }) +} +``` + ### `e2e/late-staff-fixture.ts` ```ts @@ -1182,6 +1205,18 @@ import type { Config, Plugin } from 'payload' */ export const E2E_LATE_STAFF = process.env.E2E_LATE_STAFF === '1' +/** Slugs the fixture names as staff (payload.config.ts → `access.staffCollections`). */ +export const E2E_STAFF_SLUGS = ['late-staff', 'e2e-crew', 'e2e-late-text'] + +/** + * Listed BEFORE ipalKit: a staff collection of the project's own, without rules, whose roles are the plugin's values + * PLUS one more. `admin` on an account of it makes a plugin admin, so its accounts must not hand that value out. + */ +export const e2eEarlyStaff: Plugin = (config: Config) => + E2E_LATE_STAFF + ? { ...config, collections: [...(config.collections ?? []), { slug: 'e2e-crew', auth: true, fields: [{ name: 'roles', type: 'select', hasMany: true, options: ['user', 'editor', 'admin', 'boss'], saveToJWT: true }] }] } + : config + export const e2eLateStaff: Plugin = (config: Config) => E2E_LATE_STAFF ? { @@ -1190,6 +1225,8 @@ export const e2eLateStaff: Plugin = (config: Config) => ...(config.collections ?? []), // no access rules at all: Payload's defaults ("any logged-in user") are what ipalKit must replace { slug: 'late-staff', auth: true, fields: [{ name: 'roles', type: 'select', hasMany: true, options: ['user', 'editor', 'admin'], saveToJWT: true }], versions: true }, + // a late staff collection whose `roles` is a text field: any value can be written there, `admin` included + { slug: 'e2e-late-text', auth: true, fields: [{ name: 'roles', type: 'text', hasMany: true }] }, { slug: 'e2e-visitors', access: { create: () => true }, auth: true, fields: [] }, ], } diff --git a/docs/agent/skills/ipal-debug/SKILL.md b/docs/agent/skills/ipal-debug/SKILL.md index 81483c5..3b68f31 100644 --- a/docs/agent/skills/ipal-debug/SKILL.md +++ b/docs/agent/skills/ipal-debug/SKILL.md @@ -103,6 +103,8 @@ through this procedure. Ask only when you are missing something you cannot get y | an account logs in to `/admin` and sees "Unauthorized" (its API calls still work) | `accounts.panelRole`: the panel opens for `editor` and above; the account has only `user`, or no role | give it `editor` (an admin edits the account), or `accounts: { panelRole: 'user' }`; nobody can get in: a script with the Local API sets `roles: ['admin']`, or `accounts: { panelRole: false }` + redeploy | | `POST /api//first-register` answers `403` on an empty collection | `accounts.firstUserRoute`: only the panel's login collection may register its first account that way (the plugin's own endpoint sits in front of Payload's) | an admin creates the account; or the collection's own `create: () => true` (sign-up); or `accounts: { firstUserRoute: [''] }` | | an editor (or a script with its token) gets `403` creating an account in the project's own `users` | `accounts.adminOnlyCreate`: only admins create staff accounts where the roles are the plugin's | create as an admin; or write the collection's `create` rule; or `adminOnlyCreate: false` | +| log at start: `[ipal] No staff account holds the role "admin", so NOBODY can create, delete or unlock accounts in "…"` | a staff collection whose accounts can hold `editor` or `admin` runs on the admin rules, and no staff account is an admin | give one account `admin` with a script (`payload.update`, Local API); or write the collection's own `access.create` / `update` / `delete` | +| an account with a role of the project's own (`boss`, `viewer`) gets `403` creating or editing accounts in its staff collection (it worked on 1.16.7) | the collection's `roles` can hold `editor` or `admin` (a select with one of them, or a text / json field): the admin rules apply | do it as an admin; or write the collection's own rules for that role | | an account gets `403` changing or deleting ANOTHER account of a staff collection (it worked before) | `accounts.adminOnlyWrite`: an admin, or the account itself (update only); on a collection with roles of its own: accounts of that collection | do it as an admin; or write the collection's `update` / `delete` rule; or `adminOnlyWrite: false` | | an account saves its own profile and its `roles` do not change (no error) | `accounts.adminOnlyWrite`: nobody changes its own roles; with the plugin's roles only an admin changes roles | an admin changes the role; or give the `roles` field its own `access.update` | | a logged-in visitor (customer) gets `403` reading a staff collection — an author box went empty | `accounts.staffOnlyRead`: only staff accounts read a staff collection without a `read` rule | write that collection's `read` rule; or `staffOnlyRead: false` | diff --git a/docs/agent/skills/ipal-reference/resources/api.md b/docs/agent/skills/ipal-reference/resources/api.md index e61142e..dccc47d 100644 --- a/docs/agent/skills/ipal-reference/resources/api.md +++ b/docs/agent/skills/ipal-reference/resources/api.md @@ -67,8 +67,8 @@ Admin panel components from `@intecion/ipal-kit/admin` — the project does NOT | `isAdmin(user, source?)` | `@intecion/ipal-kit`; in client components `@intecion/ipal-kit/client` | Predicate → `boolean`: staff account with the `admin` role (see `hasMinimumRole`). In hooks and endpoints: `isAdmin(req.user, req.payload)`; in a client component: `isAdmin(user, config)` from `/client` — the main entry does not build there with webpack (`'server-only' cannot be imported…`). | | `isEditor(user, source?)` | `@intecion/ipal-kit`; in client components `@intecion/ipal-kit/client` | Predicate → `boolean`: staff account with `editor` or higher. | | `panelAccess(minimum?)`, `applyPanelRole(config, slug, role)`, `resolvePanelRole(option)`, `countBelowPanelRole(payload, slug, role)`, `DEFAULT_PANEL_ROLE` | `@intecion/ipal-kit` | `accounts.panelRole`: an `access.admin` function ("holds at least `minimum`", default `'editor'`; role only, not the second factor); the applier (skips a collection that has its own `access.admin`); the option → role or `null` when off; `{ all, below }` counts for the start-up line; `'editor'`. | -| `staffCreateAccess`, `staffUpdateAccess(slug)`, `staffReadAccess`, `sameStaffCollectionAccess(slug)`, `rolesByAdminOnly`, `rolesNotOwn(slug)`, `hasPluginRoles(collection)`, `applyStaffAccountAccess(config, staffSlugs, { create?, write?, read?, pluginRoles? })` | `@intecion/ipal-kit` | `accounts.adminOnlyCreate` / `adminOnlyWrite` / `staffOnlyRead`: the access functions — "an admin, fully signed in" (create, delete, unlock); "an admin, or the account itself" (update; self = an account of THAT collection); "a fully signed-in account of a staff collection" (read); "an account of this staff collection, or a plugin admin of another" (a collection whose roles are not the plugin's); the two field-access functions for a `roles` field (`update`: only an admin / never the account itself); whether a collection carries the plugin's roles (a `roles` select at the top level of the data with only `user` / `editor` / `admin`); the applier — puts the rules on the named staff collections for the operations that have none and closes the `roles` field where the plugin's `update` rule is in force, `pluginRoles` = slugs whose roles field is injected later. Run it before any plugin that wraps access (the 2FA package). | -| `buildFirstUserEndpoint(option?)`, `applyFirstUserRoute(config, option?)`, `adoptLateAuthCollections(config, staffSlugs, { access?, beforeOperation?, firstUserRoute? })`, `bothAllow(first, second)`, `unknownStaffCollections(config, staffSlugs)`, `openSignUpCollections(payload)`, `staffCollectionsOpenToOthers(payload)`, `staffCollectionsOnOwnRoles(payload)` | `@intecion/ipal-kit` | `accounts.firstUserRoute`: the plugin's own `POST /first-register` collection endpoint, matched before Payload's — `403` unless the collection is the panel's login collection (`'panel'`), is in the list, or its own `create` lets an anonymous request through; otherwise it calls Payload's handler (and sets `req.context.ipalFirstRegister`); the applier (every auth collection; `'all'` adds nothing; `endpoints: false` is left alone). For the doctor: slugs of auth collections with open sign-up; `':'` for every staff collection an account of a non-staff collection may create in, read, update, delete from or unlock; slugs of staff collections with role values of their own on the default rules. `adoptLateAuthCollections` takes the LIVE config (`payload.config`) and gives auth collections that a plugin listed after ipalKit added the same rules, in place (called by the plugin at start and on every dev reload; returns `LateAdoption[]` — per collection what was put). There the rules are combined with the collection's own by `bothAllow` (an access function that allows only when both do; two query constraints are joined with `and`), because in a sanitized config Payload's default cannot be told from a written rule — never by a function's name, which a production build changes. `custom.ipal.accountRules: false` on a late collection keeps its rules as they are. `unknownStaffCollections` lists staff slugs that are not auth collections (Payload does not start on any). | +| `staffCreateAccess`, `staffUpdateAccess(slug)`, `staffReadAccess`, `sameStaffCollectionAccess(slug)`, `rolesByAdminOnly`, `rolesNotOwn(slug)`, `hasPluginRoles(collection)`, `canHoldStaffRole(collection)`, `applyStaffAccountAccess(config, staffSlugs, { create?, write?, read?, pluginRoles? })` | `@intecion/ipal-kit` | `accounts.adminOnlyCreate` / `adminOnlyWrite` / `staffOnlyRead`: the access functions — "an admin, fully signed in" (create, delete, unlock); "an admin, or the account itself" (update; self = an account of THAT collection); "a fully signed-in account of a staff collection" (read); "an account of this staff collection, or a plugin admin of another" (a collection whose roles are not the plugin's); the two field-access functions for a `roles` field (`update`: only an admin / never the account itself); whether a collection carries the plugin's roles (a `roles` select at the top level of the data with only `user` / `editor` / `admin`); whether an account of it can hold `editor` or `admin` whatever else the field offers (a select with one of them among its values, or a `roles` field whose values cannot be listed — text, json) — then the admin rules apply too; the applier — puts the rules on the named staff collections for the operations that have none and closes the `roles` field where the plugin's `update` rule is in force, `pluginRoles` = slugs whose roles field is injected later. Run it before any plugin that wraps access (the 2FA package). | +| `buildFirstUserEndpoint(option?)`, `applyFirstUserRoute(config, option?)`, `adoptLateAuthCollections(config, staffSlugs, { access?, beforeOperation?, firstUserRoute? })`, `bothAllow(first, second)`, `unknownStaffCollections(config, staffSlugs)`, `openSignUpCollections(payload)`, `staffCollectionsOpenToOthers(payload)`, `staffCollectionsOnOwnRoles(payload)`, `staffCollectionsNobodyManages(payload, staffSlugs, except?)` | `@intecion/ipal-kit` | `accounts.firstUserRoute`: the plugin's own `POST /first-register` collection endpoint, matched before Payload's — `403` unless the collection is the panel's login collection (`'panel'`), is in the list, or its own `create` lets an anonymous request through; otherwise it calls Payload's handler (and sets `req.context.ipalFirstRegister`); the applier (every auth collection; `'all'` adds nothing; `endpoints: false` is left alone). For the doctor: slugs of auth collections with open sign-up; `':'` for every staff collection an account of a non-staff collection may create in, read, update, delete from or unlock; slugs of staff collections with role values of their own on the default rules. `adoptLateAuthCollections` takes the LIVE config (`payload.config`) and gives auth collections that a plugin listed after ipalKit added the same rules, in place (called by the plugin at start and on every dev reload; returns `LateAdoption[]` — per collection what was put). There the rules are combined with the collection's own by `bothAllow` (an access function that allows only when both do; two query constraints are joined with `and`), because in a sanitized config Payload's default cannot be told from a written rule — never by a function's name, which a production build changes. `custom.ipal.accountRules: false` on a late collection keeps its rules as they are. `unknownStaffCollections` lists staff slugs that are not auth collections (Payload does not start on any). | `staffCollectionsNobodyManages` (async): staff collections on the admin rules while no staff account is a plugin admin — nobody can create, delete or unlock accounts there (the plugin warns at start). | `checkPassword(password, { email?, minLength? })`, `buildPasswordRuleHook({ minLength? })`, `applyPasswordRule(config, slugs, rule)`, `resolvePasswordRule(option)`, `DEFAULT_PASSWORD_MIN_LENGTH` | `@intecion/ipal-kit` | `accounts.password`: `'short' \| 'email' \| null` for a new password (length in characters); the `beforeOperation` hook for `create` / `update` / `resetPassword` (throws Payload's `ValidationError` on `password`, text in the panel's language; the account's address is looked up by id, reset token or bulk query when the request carries none; a password that is not text is refused; login is never checked); the applier; the option → `{ minLength }` or `null`; `12`. | | `writeOnlySecret(field, options?)`, `writeOnlySecrets(fields, names, optionsByName?)`, `maskSecretAfterRead`, `keepSecretBeforeValidate`, `buildKeepSecret(options?)`, `SECRET_MASK`, `SECRET_CLEAR`, `isSecretMask(value)`, `INTEGRATION_SECRET_FIELDS`, `SMTP_PASSWORD_BOUND_TO` | `@intecion/ipal-kit` | Write-only secret fields (`secrets.writeOnly`): the wrapper for one field and for named fields anywhere in a tree (tabs, rows, groups); the two field hooks (reads through access control get `'********'`, the Local API with access control off gets the value; a save with nothing / empty / the mask keeps the stored value, `'[[clear]]'` removes it); the hook builder with options — `{ boundTo: ['siblingField'], appliesWhen?: (siblingData) => boolean }`: a save through access control that changes a bound sibling field without sending the secret throws a `ValidationError` on the secret (`secrets.reenterOnChange`); the two constants; the plugin's own secret field names (`smtpPassword`, `turnstileSecretKey`); the fields the SMTP password is bound to (`smtpHost`, `smtpPort`, `smtpUser` — not the transport: the mail adapter may fall back to SMTP). | | `maskSecretsOnRestore`, `maskWriteOnlySecrets(data, fields)` | `@intecion/ipal-kit` | Versions and write-only secrets: the `afterRead` hook for a global or a collection (a restore answers with the version document, fields under `version`, where field hooks do not run — it masks them there for reads through access control); the walker it uses (masks every write-only field in `data`, following tabs, rows, groups, arrays and blocks). On Site integrations by default; add the hook to your own entity that has both. | diff --git a/docs/agent/skills/ipal-setup/SKILL.md b/docs/agent/skills/ipal-setup/SKILL.md index 930bf7e..858bc1f 100644 --- a/docs/agent/skills/ipal-setup/SKILL.md +++ b/docs/agent/skills/ipal-setup/SKILL.md @@ -252,7 +252,7 @@ the panel shows Site settings, Site integrations, Cookies, Form messages, the Fo users at least `editor`); only an admin creates staff accounts, and an account is changed by an admin or by itself, nobody changes its own roles, and only staff accounts read staff accounts — also in the project's own staff collection and in one a later plugin adds (`adminOnlyCreate`, `adminOnlyWrite`, `staffOnlyRead`). **A - staff collection with role values of its own** (not `user` / `editor` / `admin`) gets only "an account of that + staff collection with role values of its own that hold neither `editor` nor `admin`** gets only "an account of that collection, or a plugin admin": the plugin cannot rank your roles, so inside it every account may create an account with any role — **write its `create` / `update` / `delete` rules and the field access of its `roles` field yourself** (`ipal-doctor --url` → `staff-own-roles`). Give every staff collection a `roles` field: without diff --git a/docs/agent/skills/ipal-upgrade/SKILL.md b/docs/agent/skills/ipal-upgrade/SKILL.md index 8adba70..dee04a5 100644 --- a/docs/agent/skills/ipal-upgrade/SKILL.md +++ b/docs/agent/skills/ipal-upgrade/SKILL.md @@ -459,7 +459,13 @@ account → "Two-step verification: Set up." and the reset button; delete the ac `editor` / `admin`): create, delete, unlock — an admin; update — an admin or the account itself; its `roles` field — only an admin (when the field has no `access.update` of its own). **Check:** does a non-admin create or edit other accounts, or change roles, there today? Then write the rule you want; - - the collection has **role values of its own** (`superadmin`, …) or no roles: accounts of that collection + - an account of the collection **can hold `editor` or `admin`** although its roles are not just the plugin's + (`user, editor, admin, boss`; `viewer, editor`; a `roles` field that is text or json): the admin rules too, + since the release after 1.16.7 (the value on the account makes a plugin admin or editor). **Check:** do + accounts with one of your own roles (`boss`, `viewer`) manage accounts there? Then write that as the + collection's own rules. Read the start log: `No staff account holds the role "admin", so NOBODY can create, + delete or unlock accounts in "…"` — give one account `admin` with a script, or write the rules; + - the collection has **role values of its own that hold neither** (`superadmin`, …) or no roles: accounts of that collection keep working as before, except that an account no longer changes its **own** roles; accounts of other collections are refused. **Write your own rules** — the plugin does not know your roles, and inside the collection every account can still create an account with any role (`ipal-doctor --url` → diff --git a/docs/dev/PROGRAMISTA.md b/docs/dev/PROGRAMISTA.md index 97e85f5..9f06a24 100644 --- a/docs/dev/PROGRAMISTA.md +++ b/docs/dev/PROGRAMISTA.md @@ -754,7 +754,8 @@ dev is running. pnpm build:starter && pnpm test:int && pnpm starter:gate` before every `npm publish`, so you cannot release a stale dist, a version with red tests or a starter that does not produce a working site (docs/project-starter.md; `pnpm clean && pnpm build` above is only a grep check before the commit). `prepare` (`pnpm build`) builds the package on install from git and on `pnpm install` in the repo. -`typecheck` and `lint` are **not** in `prepublishOnly` — before a commit: `pnpm typecheck && pnpm lint && +`pnpm e2e:built` is **not** in `prepublishOnly` either (it needs the reference site's `.env` and database): it is a +required step of §8.1. `typecheck` and `lint` are **not** in `prepublishOnly` — before a commit: `pnpm typecheck && pnpm lint && pnpm test:int` (CI in `.gitea/workflows/ci.yml` runs typecheck, lint, test:int and build on push and PR). ### 8.1b The reference site (`reference/`) — part of every release @@ -769,7 +770,21 @@ done until the reference site uses it. Before `npm version`: - [ ] Local run green: `pnpm build` (plugin) → `pnpm --dir reference install --ignore-workspace` (refreshes the injected copy) → in `reference/`: `pnpm generate:types && pnpm generate:importmap` (no diff), `pnpm typecheck`, `pnpm seed` on a throwaway MongoDB, `pnpm build`, `ALLOW_LOCAL_MEDIA=1 PORT=3100 pnpm start`, - `pnpm payload run e2e/create-test-admin.ts`, `pnpm test:e2e`. + `pnpm test:e2e` (Playwright's global setup runs `e2e/create-test-admin.ts` first: test admins reset, stored 2FA + attempt counts cleared, so the result does not depend on what ran before; the fresh-site spec on an EMPTY + database: `E2E_SKIP_ADMIN_SETUP=1`). +- [ ] **`pnpm e2e:built` green — required, no release without it.** It builds the reference site with webpack AND with + Turbopack (with the late-staff fixture, `E2E_LATE_STAFF=1`) and runs, on each built site: the account rules of + staff collections the project or a later plugin adds (`e2e/late-staff.spec.ts`), and "no package manifest among + the public files". Unit tests run unminified code and cannot see what a bundle renames or publishes — two + defects of the 1.16.7 review lived only in a built site. Needs `reference/.env` (local seeded MongoDB, `E2E_*` + test admin); port from `E2E_BASE_URL`. Afterwards `git status` is clean (the command puts the reference site's + generated types and import map back, also when it fails); rebuild the reference site without the fixture + (`pnpm build` there) before other checks. +- [ ] `pnpm version ` or `npm version --no-git-tag-version` writes the version into `src/version.ts` + as well (the `version` script; by hand: `node scripts/write-version.mjs`). **Not `pnpm --ignore-workspace + version …`**: that runs the `version` script itself with the arguments and fails. `test/version.test.ts` fails + when the constant differs from package.json. - [ ] `pnpm reference:index` → `docs/agent/reference-site/INDEX.md` committed (`test/referenceIndex.test.ts` fails otherwise; a new file in `reference/` needs its line in `scripts/reference-index.mjs` → `DESCRIPTIONS`). - [ ] CI job `reference` green (`.gitea/workflows/ci.yml`), the starter check included once `ipal-kit create` ships. @@ -790,6 +805,7 @@ The site uses the plugin as `file:..` with `dependenciesMeta.injected`, so the p | package contract | `test/exports.test.ts` | every `@intecion/ipal-kit/…` path from the docs exists in `exports` | | docs ↔ code | `test/docsConsistency.test.ts` | names imported in the docs exist in the entry points / `lib/content`; every public export is described in the docs | | e2e | `pnpm test:e2e` (Playwright) | `pnpm test` = `test:int` + `test:e2e` | +| built site, both bundlers | `pnpm e2e:built` (`scripts/e2e-built.mjs`, the reference site) | what only a production bundle shows: nothing decided by a function's name, nothing private among the public files (§8.1) | Rules: **every fixed bug = a regression test** (check that it fails on the old code); no network (`vi.spyOn(globalThis, 'fetch')`); env through `vi.stubEnv` + `unstubAllEnvs`; diff --git a/docs/doctor.md b/docs/doctor.md index c0a8506..d856fc1 100644 --- a/docs/doctor.md +++ b/docs/doctor.md @@ -102,7 +102,7 @@ Turn off: `ipalKit({ doctor: false })`. Adapt: `ipalKit({ doctor: { tokenVar: 'M | | `access-missing` | warning | `ipalKit` has an `access` option — without it there are no roles and every panel account is an admin | | | `csrf-empty` | warning | the config sets `serverURL` or `csrf` — otherwise Payload accepts the login cookie from any origin | | | `open-signup` | info | (deep) auth collections whose `create` rule lets an anonymous request through: sign-up is open there (intended for a customer zone — silence with a reason) | -| | `staff-own-roles` | warning | (deep) a staff collection with role values of its own (not `user` / `editor` / `admin`) that runs on the plugin's default account rules: the plugin cannot rank those roles, so inside the collection every account may create an account with any role and change or delete another. Write the collection's own rules | +| | `staff-own-roles` | warning | (deep) a staff collection with role values of its own, neither `editor` nor `admin` among them, that runs on the plugin's default account rules: the plugin cannot rank those roles, so inside the collection every account may create an account with any role and change or delete another. Write the collection's own rules | | | `staff-accounts-open` | error (warning for `read`, `readVersions`) | (deep) a staff collection that an account of another, non-staff auth collection may create in, read (also its versions), update, delete from or unlock — it can make itself staff, change a staff password, list the accounts or lift a login lock. The account rules are off (`accounts: false`, `adminOnlyCreate` / `adminOnlyWrite` / `staffOnlyRead: false`) or the project's own rule is wider. Asked with a made-up outside account; a rule that throws counts as closed | | | `turnstile-degraded` | warning / error | (deep) Turnstile is checking forms; while it is not (wrong or missing secret, Cloudflare down) a warning, an error once it has lasted 24 hours (counted from the recorded start to now) | | | `turnstile-env-key` | warning | (deep) the Turnstile secret key is in the panel, not in the deprecated `TURNSTILE_SECRET_KEY` environment variable | diff --git a/reference/.agents/skills/ipal-debug/SKILL.md b/reference/.agents/skills/ipal-debug/SKILL.md index 81483c5..3b68f31 100644 --- a/reference/.agents/skills/ipal-debug/SKILL.md +++ b/reference/.agents/skills/ipal-debug/SKILL.md @@ -103,6 +103,8 @@ through this procedure. Ask only when you are missing something you cannot get y | an account logs in to `/admin` and sees "Unauthorized" (its API calls still work) | `accounts.panelRole`: the panel opens for `editor` and above; the account has only `user`, or no role | give it `editor` (an admin edits the account), or `accounts: { panelRole: 'user' }`; nobody can get in: a script with the Local API sets `roles: ['admin']`, or `accounts: { panelRole: false }` + redeploy | | `POST /api//first-register` answers `403` on an empty collection | `accounts.firstUserRoute`: only the panel's login collection may register its first account that way (the plugin's own endpoint sits in front of Payload's) | an admin creates the account; or the collection's own `create: () => true` (sign-up); or `accounts: { firstUserRoute: [''] }` | | an editor (or a script with its token) gets `403` creating an account in the project's own `users` | `accounts.adminOnlyCreate`: only admins create staff accounts where the roles are the plugin's | create as an admin; or write the collection's `create` rule; or `adminOnlyCreate: false` | +| log at start: `[ipal] No staff account holds the role "admin", so NOBODY can create, delete or unlock accounts in "…"` | a staff collection whose accounts can hold `editor` or `admin` runs on the admin rules, and no staff account is an admin | give one account `admin` with a script (`payload.update`, Local API); or write the collection's own `access.create` / `update` / `delete` | +| an account with a role of the project's own (`boss`, `viewer`) gets `403` creating or editing accounts in its staff collection (it worked on 1.16.7) | the collection's `roles` can hold `editor` or `admin` (a select with one of them, or a text / json field): the admin rules apply | do it as an admin; or write the collection's own rules for that role | | an account gets `403` changing or deleting ANOTHER account of a staff collection (it worked before) | `accounts.adminOnlyWrite`: an admin, or the account itself (update only); on a collection with roles of its own: accounts of that collection | do it as an admin; or write the collection's `update` / `delete` rule; or `adminOnlyWrite: false` | | an account saves its own profile and its `roles` do not change (no error) | `accounts.adminOnlyWrite`: nobody changes its own roles; with the plugin's roles only an admin changes roles | an admin changes the role; or give the `roles` field its own `access.update` | | a logged-in visitor (customer) gets `403` reading a staff collection — an author box went empty | `accounts.staffOnlyRead`: only staff accounts read a staff collection without a `read` rule | write that collection's `read` rule; or `staffOnlyRead: false` | diff --git a/reference/.agents/skills/ipal-reference/resources/api.md b/reference/.agents/skills/ipal-reference/resources/api.md index e61142e..dccc47d 100644 --- a/reference/.agents/skills/ipal-reference/resources/api.md +++ b/reference/.agents/skills/ipal-reference/resources/api.md @@ -67,8 +67,8 @@ Admin panel components from `@intecion/ipal-kit/admin` — the project does NOT | `isAdmin(user, source?)` | `@intecion/ipal-kit`; in client components `@intecion/ipal-kit/client` | Predicate → `boolean`: staff account with the `admin` role (see `hasMinimumRole`). In hooks and endpoints: `isAdmin(req.user, req.payload)`; in a client component: `isAdmin(user, config)` from `/client` — the main entry does not build there with webpack (`'server-only' cannot be imported…`). | | `isEditor(user, source?)` | `@intecion/ipal-kit`; in client components `@intecion/ipal-kit/client` | Predicate → `boolean`: staff account with `editor` or higher. | | `panelAccess(minimum?)`, `applyPanelRole(config, slug, role)`, `resolvePanelRole(option)`, `countBelowPanelRole(payload, slug, role)`, `DEFAULT_PANEL_ROLE` | `@intecion/ipal-kit` | `accounts.panelRole`: an `access.admin` function ("holds at least `minimum`", default `'editor'`; role only, not the second factor); the applier (skips a collection that has its own `access.admin`); the option → role or `null` when off; `{ all, below }` counts for the start-up line; `'editor'`. | -| `staffCreateAccess`, `staffUpdateAccess(slug)`, `staffReadAccess`, `sameStaffCollectionAccess(slug)`, `rolesByAdminOnly`, `rolesNotOwn(slug)`, `hasPluginRoles(collection)`, `applyStaffAccountAccess(config, staffSlugs, { create?, write?, read?, pluginRoles? })` | `@intecion/ipal-kit` | `accounts.adminOnlyCreate` / `adminOnlyWrite` / `staffOnlyRead`: the access functions — "an admin, fully signed in" (create, delete, unlock); "an admin, or the account itself" (update; self = an account of THAT collection); "a fully signed-in account of a staff collection" (read); "an account of this staff collection, or a plugin admin of another" (a collection whose roles are not the plugin's); the two field-access functions for a `roles` field (`update`: only an admin / never the account itself); whether a collection carries the plugin's roles (a `roles` select at the top level of the data with only `user` / `editor` / `admin`); the applier — puts the rules on the named staff collections for the operations that have none and closes the `roles` field where the plugin's `update` rule is in force, `pluginRoles` = slugs whose roles field is injected later. Run it before any plugin that wraps access (the 2FA package). | -| `buildFirstUserEndpoint(option?)`, `applyFirstUserRoute(config, option?)`, `adoptLateAuthCollections(config, staffSlugs, { access?, beforeOperation?, firstUserRoute? })`, `bothAllow(first, second)`, `unknownStaffCollections(config, staffSlugs)`, `openSignUpCollections(payload)`, `staffCollectionsOpenToOthers(payload)`, `staffCollectionsOnOwnRoles(payload)` | `@intecion/ipal-kit` | `accounts.firstUserRoute`: the plugin's own `POST /first-register` collection endpoint, matched before Payload's — `403` unless the collection is the panel's login collection (`'panel'`), is in the list, or its own `create` lets an anonymous request through; otherwise it calls Payload's handler (and sets `req.context.ipalFirstRegister`); the applier (every auth collection; `'all'` adds nothing; `endpoints: false` is left alone). For the doctor: slugs of auth collections with open sign-up; `':'` for every staff collection an account of a non-staff collection may create in, read, update, delete from or unlock; slugs of staff collections with role values of their own on the default rules. `adoptLateAuthCollections` takes the LIVE config (`payload.config`) and gives auth collections that a plugin listed after ipalKit added the same rules, in place (called by the plugin at start and on every dev reload; returns `LateAdoption[]` — per collection what was put). There the rules are combined with the collection's own by `bothAllow` (an access function that allows only when both do; two query constraints are joined with `and`), because in a sanitized config Payload's default cannot be told from a written rule — never by a function's name, which a production build changes. `custom.ipal.accountRules: false` on a late collection keeps its rules as they are. `unknownStaffCollections` lists staff slugs that are not auth collections (Payload does not start on any). | +| `staffCreateAccess`, `staffUpdateAccess(slug)`, `staffReadAccess`, `sameStaffCollectionAccess(slug)`, `rolesByAdminOnly`, `rolesNotOwn(slug)`, `hasPluginRoles(collection)`, `canHoldStaffRole(collection)`, `applyStaffAccountAccess(config, staffSlugs, { create?, write?, read?, pluginRoles? })` | `@intecion/ipal-kit` | `accounts.adminOnlyCreate` / `adminOnlyWrite` / `staffOnlyRead`: the access functions — "an admin, fully signed in" (create, delete, unlock); "an admin, or the account itself" (update; self = an account of THAT collection); "a fully signed-in account of a staff collection" (read); "an account of this staff collection, or a plugin admin of another" (a collection whose roles are not the plugin's); the two field-access functions for a `roles` field (`update`: only an admin / never the account itself); whether a collection carries the plugin's roles (a `roles` select at the top level of the data with only `user` / `editor` / `admin`); whether an account of it can hold `editor` or `admin` whatever else the field offers (a select with one of them among its values, or a `roles` field whose values cannot be listed — text, json) — then the admin rules apply too; the applier — puts the rules on the named staff collections for the operations that have none and closes the `roles` field where the plugin's `update` rule is in force, `pluginRoles` = slugs whose roles field is injected later. Run it before any plugin that wraps access (the 2FA package). | +| `buildFirstUserEndpoint(option?)`, `applyFirstUserRoute(config, option?)`, `adoptLateAuthCollections(config, staffSlugs, { access?, beforeOperation?, firstUserRoute? })`, `bothAllow(first, second)`, `unknownStaffCollections(config, staffSlugs)`, `openSignUpCollections(payload)`, `staffCollectionsOpenToOthers(payload)`, `staffCollectionsOnOwnRoles(payload)`, `staffCollectionsNobodyManages(payload, staffSlugs, except?)` | `@intecion/ipal-kit` | `accounts.firstUserRoute`: the plugin's own `POST /first-register` collection endpoint, matched before Payload's — `403` unless the collection is the panel's login collection (`'panel'`), is in the list, or its own `create` lets an anonymous request through; otherwise it calls Payload's handler (and sets `req.context.ipalFirstRegister`); the applier (every auth collection; `'all'` adds nothing; `endpoints: false` is left alone). For the doctor: slugs of auth collections with open sign-up; `':'` for every staff collection an account of a non-staff collection may create in, read, update, delete from or unlock; slugs of staff collections with role values of their own on the default rules. `adoptLateAuthCollections` takes the LIVE config (`payload.config`) and gives auth collections that a plugin listed after ipalKit added the same rules, in place (called by the plugin at start and on every dev reload; returns `LateAdoption[]` — per collection what was put). There the rules are combined with the collection's own by `bothAllow` (an access function that allows only when both do; two query constraints are joined with `and`), because in a sanitized config Payload's default cannot be told from a written rule — never by a function's name, which a production build changes. `custom.ipal.accountRules: false` on a late collection keeps its rules as they are. `unknownStaffCollections` lists staff slugs that are not auth collections (Payload does not start on any). | `staffCollectionsNobodyManages` (async): staff collections on the admin rules while no staff account is a plugin admin — nobody can create, delete or unlock accounts there (the plugin warns at start). | `checkPassword(password, { email?, minLength? })`, `buildPasswordRuleHook({ minLength? })`, `applyPasswordRule(config, slugs, rule)`, `resolvePasswordRule(option)`, `DEFAULT_PASSWORD_MIN_LENGTH` | `@intecion/ipal-kit` | `accounts.password`: `'short' \| 'email' \| null` for a new password (length in characters); the `beforeOperation` hook for `create` / `update` / `resetPassword` (throws Payload's `ValidationError` on `password`, text in the panel's language; the account's address is looked up by id, reset token or bulk query when the request carries none; a password that is not text is refused; login is never checked); the applier; the option → `{ minLength }` or `null`; `12`. | | `writeOnlySecret(field, options?)`, `writeOnlySecrets(fields, names, optionsByName?)`, `maskSecretAfterRead`, `keepSecretBeforeValidate`, `buildKeepSecret(options?)`, `SECRET_MASK`, `SECRET_CLEAR`, `isSecretMask(value)`, `INTEGRATION_SECRET_FIELDS`, `SMTP_PASSWORD_BOUND_TO` | `@intecion/ipal-kit` | Write-only secret fields (`secrets.writeOnly`): the wrapper for one field and for named fields anywhere in a tree (tabs, rows, groups); the two field hooks (reads through access control get `'********'`, the Local API with access control off gets the value; a save with nothing / empty / the mask keeps the stored value, `'[[clear]]'` removes it); the hook builder with options — `{ boundTo: ['siblingField'], appliesWhen?: (siblingData) => boolean }`: a save through access control that changes a bound sibling field without sending the secret throws a `ValidationError` on the secret (`secrets.reenterOnChange`); the two constants; the plugin's own secret field names (`smtpPassword`, `turnstileSecretKey`); the fields the SMTP password is bound to (`smtpHost`, `smtpPort`, `smtpUser` — not the transport: the mail adapter may fall back to SMTP). | | `maskSecretsOnRestore`, `maskWriteOnlySecrets(data, fields)` | `@intecion/ipal-kit` | Versions and write-only secrets: the `afterRead` hook for a global or a collection (a restore answers with the version document, fields under `version`, where field hooks do not run — it masks them there for reads through access control); the walker it uses (masks every write-only field in `data`, following tabs, rows, groups, arrays and blocks). On Site integrations by default; add the hook to your own entity that has both. | diff --git a/reference/.agents/skills/ipal-setup/SKILL.md b/reference/.agents/skills/ipal-setup/SKILL.md index 930bf7e..858bc1f 100644 --- a/reference/.agents/skills/ipal-setup/SKILL.md +++ b/reference/.agents/skills/ipal-setup/SKILL.md @@ -252,7 +252,7 @@ the panel shows Site settings, Site integrations, Cookies, Form messages, the Fo users at least `editor`); only an admin creates staff accounts, and an account is changed by an admin or by itself, nobody changes its own roles, and only staff accounts read staff accounts — also in the project's own staff collection and in one a later plugin adds (`adminOnlyCreate`, `adminOnlyWrite`, `staffOnlyRead`). **A - staff collection with role values of its own** (not `user` / `editor` / `admin`) gets only "an account of that + staff collection with role values of its own that hold neither `editor` nor `admin`** gets only "an account of that collection, or a plugin admin": the plugin cannot rank your roles, so inside it every account may create an account with any role — **write its `create` / `update` / `delete` rules and the field access of its `roles` field yourself** (`ipal-doctor --url` → `staff-own-roles`). Give every staff collection a `roles` field: without diff --git a/reference/.agents/skills/ipal-upgrade/SKILL.md b/reference/.agents/skills/ipal-upgrade/SKILL.md index 8adba70..dee04a5 100644 --- a/reference/.agents/skills/ipal-upgrade/SKILL.md +++ b/reference/.agents/skills/ipal-upgrade/SKILL.md @@ -459,7 +459,13 @@ account → "Two-step verification: Set up." and the reset button; delete the ac `editor` / `admin`): create, delete, unlock — an admin; update — an admin or the account itself; its `roles` field — only an admin (when the field has no `access.update` of its own). **Check:** does a non-admin create or edit other accounts, or change roles, there today? Then write the rule you want; - - the collection has **role values of its own** (`superadmin`, …) or no roles: accounts of that collection + - an account of the collection **can hold `editor` or `admin`** although its roles are not just the plugin's + (`user, editor, admin, boss`; `viewer, editor`; a `roles` field that is text or json): the admin rules too, + since the release after 1.16.7 (the value on the account makes a plugin admin or editor). **Check:** do + accounts with one of your own roles (`boss`, `viewer`) manage accounts there? Then write that as the + collection's own rules. Read the start log: `No staff account holds the role "admin", so NOBODY can create, + delete or unlock accounts in "…"` — give one account `admin` with a script, or write the rules; + - the collection has **role values of its own that hold neither** (`superadmin`, …) or no roles: accounts of that collection keep working as before, except that an account no longer changes its **own** roles; accounts of other collections are refused. **Write your own rules** — the plugin does not know your roles, and inside the collection every account can still create an account with any role (`ipal-doctor --url` → diff --git a/scripts/reference-index.mjs b/scripts/reference-index.mjs index feb6d5f..fa64395 100644 --- a/scripts/reference-index.mjs +++ b/scripts/reference-index.mjs @@ -60,8 +60,9 @@ export const DESCRIPTIONS = { 'README.md': 'how to run the reference site and what is where', 'docs/DEPLOY.md': 'the Coolify runbook: local check, app settings, MongoDB resource, env, targeted seeds, DNS, rollback', 'e2e/create-test-admin.ts': 'two test admins with a known TOTP secret (the specs share out the five 2FA verify attempts per account), their stored verify counts cleared, and e-mail sending pointed at the tests\' mail sink (local / CI database only)', - 'e2e/late-staff-fixture.ts': 'test fixture, on only with E2E_LATE_STAFF=1: a plugin listed after ipalKit that adds a staff collection without rules and a visitor collection with open sign-up', - 'e2e/late-staff.spec.ts': 'the account rules on a BUILT site for a staff collection a later plugin adds (run after a webpack and a Turbopack build): a visitor account gets nothing, nobody raises its own role', + 'e2e/late-staff-fixture.ts': 'test fixture, on only with E2E_LATE_STAFF=1: one plugin before ipalKit (a staff collection of the config whose roles are the plugin\'s values plus one more) and one after it (a staff collection without rules, one whose roles field is text, a visitor collection with open sign-up)', + 'e2e/late-staff.spec.ts': 'the account rules on a BUILT site (run by `pnpm e2e:built` after a webpack and a Turbopack build): a staff collection a later plugin adds, and staff collections whose accounts can hold `admin` — a visitor account gets nothing, nobody raises its own role or makes an admin', + 'e2e/global-setup.ts': 'Playwright global setup: resets the test admins and clears their stored 2FA attempt counts before every run, so specs do not depend on run order', 'e2e/two-factor-setup.spec.ts': 'browser check of "2FA setup required": the first admin of a fresh site, a new editor, the administrator\'s reset on the account page', 'e2e/smoke.spec.ts': 'the smoke tests every release must pass: pages, showcase, forms (also a file sent by e-mail), sitemap, SEO/GEO, headers, consent, 2FA', 'e2e/smtp-sink.ts': 'a local mail sink for the smoke tests: reads what the site really sent (recipients, attachments)',