From fd203de326e9f8ebd44beedcb47723bf65e90685 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rados=C5=82aw=20Smoli=C5=84ski?= Date: Tue, 24 Nov 2026 23:33:39 +0100 Subject: [PATCH] M1 review: docs, agent guide, skills and changelog follow the fixes Co-Authored-By: Claude Fable 5.2 --- docs/CHANGELOG.md | 104 +++++++++++++----- docs/access.md | 68 +++++++++--- docs/agent/AGENT.md | 9 +- docs/agent/skills/ipal-debug/SKILL.md | 11 +- docs/agent/skills/ipal-reference/SKILL.md | 12 +- .../skills/ipal-reference/resources/api.md | 12 +- docs/agent/skills/ipal-setup/SKILL.md | 22 +++- docs/agent/skills/ipal-upgrade/SKILL.md | 44 ++++++-- docs/dev/PROGRAMISTA.md | 2 +- docs/doctor.md | 5 +- docs/email.md | 12 +- docs/security.md | 63 +++++++++-- reference/.agents/skills/ipal-debug/SKILL.md | 11 +- .../.agents/skills/ipal-reference/SKILL.md | 12 +- .../skills/ipal-reference/resources/api.md | 12 +- reference/.agents/skills/ipal-setup/SKILL.md | 22 +++- .../.agents/skills/ipal-upgrade/SKILL.md | 44 ++++++-- 17 files changed, 349 insertions(+), 116 deletions(-) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index d2551f9..300ac5a 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -11,8 +11,12 @@ once there are more than 20. ## Unreleased — hardening (M1; version to be set at release) > **Read before upgrading.** Several defaults get stricter. Most sites change nothing, but check -> "Requires project changes": an account with only the role `user` can no longer open the panel, and a form with -> files is refused while Turnstile is misconfigured. No import-map change, no schema change, no migration. +> "Requires project changes". What can stop people: an account with only the role `user` can no longer open the +> panel; a form with files is refused while Turnstile is misconfigured; a script that creates staff accounts +> with a password under 12 characters fails; behind a proxy that hides the site's address and without +> `serverURL` nobody can enter a 2FA code; a project's own staff collection without access rules gets rules; +> changing the SMTP server in the panel asks for the password again. No import-map change. One new field +> (`smtpRequireTls`): **Postgres / SQLite need a migration**, MongoDB nothing. ### Security - **Stored secrets are write-only.** `smtpPassword` and `turnstileSecretKey` (Site integrations) were returned @@ -21,49 +25,78 @@ once there are more than 20. only server code (the Local API with access control off) reads the value. A save that sends nothing, an empty value or the mask keeps the stored value; `'[[clear]]'` removes it. The panel is the source of these secrets ([security.md](./security.md) "Stored secrets"). -- **Nobody creates an account for themselves.** (1) Payload's first-user route +- **The SMTP password stays with the server it was saved for.** Hiding the value was not enough: an admin + session could point the SMTP server at a machine of its own and have a test e-mail deliver the password. A + save in the panel or over the API that changes the server, the port, the user name or "Require encryption" + (or switches the transport to SMTP) while a password is stored must now send the password again, or remove + it (`secrets.reenterOnChange`). Server code with the Local API is not asked. +- **"Require encryption" for SMTP** (`smtpRequireTls` in Site integrations → E-mail sending, off by default): + with it the password is never sent over an unencrypted connection (a server without STARTTLS gets nothing). +- **Restoring a version of Site integrations** (only where a project turned versions on for that global) + answered with the stored secrets; they are masked there too (`maskSecretsOnRestore`). +- **Nobody creates an account for themselves, or takes one over.** (1) Payload's first-user route (`POST /api//first-register`) answers for every empty auth collection. On an empty **second staff collection** (`access.staffCollections`) the first visitor became a staff account — an admin to the plugin. - It now answers only for the collection the panel logs in with. (2) A project's **own** staff collection without - a `create` rule let any signed-in account create accounts (Payload's default); now only an admin does. - Anonymous sign-up into the staff collection was already refused. No known site has a second staff collection + It now answers only for the collection the panel logs in with, in any spelling of the URL (the plugin's own + endpoint sits in front of Payload's). (2) A project's **own** staff collection without `create`, `update` or + `delete` rules had Payload's default, "any logged-in user" — an account of any auth collection: a visitor + account could create a staff account, or change a staff account's password and roles. Such a collection now + gets rules for the operations it has none for: with the plugin's roles — an admin (update: or the account + itself); with role values of its own, or none — an account of that same collection, or a plugin admin. The + rules hold with 2FA on and off. Anonymous sign-up into the staff collection was already refused; the + plugin's injected collection already had these rules. No known site has a second staff collection ([access.md](./access.md) "Account rules"). - **2FA verify and setup attempts only from the site's own origin.** A page on another origin that the browser still sends the login cookie to (a sibling subdomain, when neither `serverURL` nor `csrf` is set) could burn an account's five verify attempts and lock its owner out, without the password. Such requests are refused before - they are counted. **The verify count is also stored in the database**, so a restart or a second instance no - longer resets it. + they are counted. A refusal is logged once per origin with the ways to allow it. **The verify count is also + stored in the database**, so a restart or a second instance no longer resets it. - **Dashboard alerts no longer show integration error texts to every panel role**: details for admins, a neutral - line for editors, nothing for others or for a session that still owes its second factor. + line for editors, nothing for others or for a session that still owes its second factor (`'all'` restores the + old behaviour and checks neither). ### Changed - **The admin panel opens for `editor` and above** (`accounts.panelRole`). An account that holds only `user` - sees "Unauthorized" in the panel; the API is not touched. + sees "Unauthorized" in the panel; the API is not touched. With `access.firstUserAdmin: false` and a default + role below the panel role the first account of a fresh site could not get in: the default panel role is then + not applied (a warning at start), and an explicit `accounts.panelRole` is refused at start with the fix. - **A password set on a staff account has at least 12 characters** and is not the account's e-mail address - (`accounts.password`). Existing passwords are never checked. + (`accounts.password`) — also in a reset by e-mail and a bulk update. Existing passwords are never checked. - **A form with files is refused while Turnstile cannot check** (wrong or missing secret, Cloudflare down); a text form is accepted as before (`forms.turnstileOnConfigError`). - **`TURNSTILE_SECRET_KEY` from the environment is deprecated.** It still works when the panel field is empty and logs a notice once per start. It will be removed in a later release, named here in advance. ### Added -- Options: `accounts` (`panelRole`, `adminOnlyCreate`, `firstUserRoute`, `password`), `secrets.writeOnly`, - `forms.turnstileOnConfigError`, `twoFactor.sameOrigin`, `twoFactor.verifyLimit.store`, `dashboardAlerts`. +- Options: `accounts` (`panelRole`, `adminOnlyCreate`, `adminOnlyWrite`, `firstUserRoute`, `password`), + `secrets.writeOnly`, `secrets.reenterOnChange`, `forms.turnstileOnConfigError`, `twoFactor.sameOrigin`, + `twoFactor.verifyLimit.store`, `dashboardAlerts`. Panel: "Require encryption" (`smtpRequireTls`). - ipal-doctor rules: `access-missing` (no `access` option: every panel account is an admin), `csrf-empty` - (neither `serverURL` nor `csrf`), and with `--url`: `open-signup` (info), `turnstile-degraded` (warning, error - after a day), `turnstile-env-key`. The deep status gained `openSignUp`, `turnstile`, `turnstileSecretFromEnv` - (states and slugs, never a key). + (neither `serverURL` nor `csrf`), and with `--url`: `open-signup` (info), `staff-accounts-open` (error: a staff + collection an account of another collection may write to), `turnstile-degraded` (warning, error after 24 + hours), `turnstile-env-key`. The deep status gained `openSignUp`, `staffOpenToOthers`, `turnstile`, + `turnstileSecretFromEnv` (states and slugs, never a key). - Exports: `writeOnlySecret`, `writeOnlySecrets`, `SECRET_MASK`, `SECRET_CLEAR`, `maskSecretAfterRead`, - `keepSecretBeforeValidate`, `isSecretMask`, `INTEGRATION_SECRET_FIELDS`; `panelAccess`, `applyPanelRole`, - `resolvePanelRole`, `countBelowPanelRole`, `DEFAULT_PANEL_ROLE`; `staffCreateAccess`, `applyAdminOnlyCreate`, - `buildFirstUserGuard`, `applyFirstUserRoute`, `openSignUpCollections`; `checkPassword`, + `keepSecretBeforeValidate`, `buildKeepSecret`, `isSecretMask`, `INTEGRATION_SECRET_FIELDS`, + `SMTP_PASSWORD_BOUND_TO`, `maskSecretsOnRestore`, `maskWriteOnlySecrets`; `panelAccess`, `applyPanelRole`, + `resolvePanelRole`, `countBelowPanelRole`, `DEFAULT_PANEL_ROLE`; `staffCreateAccess`, `staffUpdateAccess`, + `sameStaffCollectionAccess`, `hasPluginRoles`, `applyStaffAccountAccess`, `buildFirstUserEndpoint`, + `applyFirstUserRoute`, `openSignUpCollections`, `staffCollectionsOpenToOthers`; `checkPassword`, `buildPasswordRuleHook`, `applyPasswordRule`, `resolvePasswordRule`, `DEFAULT_PASSWORD_MIN_LENGTH`; - `requestFromOwnOrigin`, `ownOrigins`; `buildVerifyLimit`, `verifyLimitKey`, `clearVerifyLimits`; + `requestFromOwnOrigin`, `ownOrigins`, `reportRefusedOrigin`; `buildVerifyLimit`, `verifyLimitKey`, `clearVerifyLimits`; `turnstileSecretFromEnv`, `TURNSTILE_SECRET_ENV`; from `/server`: `passTurnstile`, `passSubmitGates`, `resolveTurnstileOnConfigError`, `TURNSTILE_ON_CONFIG_ERROR_DEFAULT`. - `MaskedField` says "A value is set" for a write-only field and offers "Remove the stored value". ### Requires project changes +- **Postgres / SQLite: a migration.** Site integrations has a new checkbox, `smtpRequireTls`: + `pnpm payload migrate:create`, commit, deploy it with the code ([deployment.md](./deployment.md) §4.3). Without + it the global cannot be read (no e-mail, no Turnstile check). MongoDB needs nothing. +- **Set `serverURL`** if it is not set. Behind a reverse proxy that rewrites `Host` and sends no + `X-Forwarded-Host` (nginx's plain `proxy_pass`; Coolify / Traefik keep `Host`) the server does not know its + own address, and the 2FA code page is refused as "another origin": **nobody can enter a code**. The log says + `[ipal] 2FA: a code from origin "…" was refused` once per origin, with the fix. Other ways out: + `twoFactor: { …, sameOrigin: { origins: ['https://…'] } }`, or make the proxy send `X-Forwarded-Host`. - **Every site: read the first start's log.** `[ipal] N account(s) of "users" are below the role "editor" and cannot open the admin panel` — give the people who work in the panel `editor`, or set `accounts: { panelRole: 'user' }`. `NOBODY can open the admin panel` (an error): no account has the role — @@ -77,19 +110,39 @@ once there are more than 20. `turnstile-env-key`). - **Forms with a File field:** make sure Turnstile works (`ipal-doctor --url` → no `turnstile-degraded`); while it does not, those forms are refused. To keep accepting them: `forms: { turnstileOnConfigError: { files: 'allow' } }`. -- **A project's own staff collection without a `create` rule:** only admins create accounts now. Write the rule - you want, or `accounts: { adminOnlyCreate: false }`. `first-register` for other auth collections: `403` unless - the collection allows sign-up, or `accounts: { firstUserRoute: 'all' }`. +- **A project's own staff collection without `create` / `update` / `delete` rules** gets them. With the plugin's + roles (`access.authCollection`, or a `roles` select with only `user` / `editor` / `admin`): only an admin + creates and deletes accounts, and an account is changed by an admin or by itself — if non-admins did that on + your site, write the rule you want. With **role values of its own** (`superadmin`, …) or no roles: accounts + of that collection keep working as before, accounts of other collections are refused — nothing to do, but the + plugin does not know your roles, so write your own rules. Off: `accounts: { adminOnlyCreate: false, + adminOnlyWrite: false }`. `first-register` for other auth collections: `403` unless the collection allows + sign-up, or `accounts: { firstUserRoute: 'all' }`. +- **`access.firstUserAdmin: false`** with `access.defaultRole` below `editor`: the panel role is not applied (a + warning at start); with `accounts.panelRole` set the start fails — set `access.defaultRole: 'editor'` or + `accounts: { panelRole: false }`. +- **A script that changes the SMTP server, port or user name over REST / GraphQL** must send the password with + it (`400` "Enter the password again…" otherwise); a seed with the Local API is not asked. In the panel the + person types the password again. `secrets: { reenterOnChange: false }` turns it off. +- **A rolling update:** a Site integrations page opened under the new version and saved against the old one + stores `********` as the password. After the deploy send a test e-mail. - **Scripts that create staff accounts with a password under 12 characters** fail with a validation error. Existing accounts with short passwords keep logging in. - **A panel or front end on another domain that posts to `/api/verify-totp`:** `twoFactor: { …, sameOrigin: { origins: ['https://…'] } }`. +- **Recommended, with the owner:** tick "Require encryption" in Site integrations → E-mail sending where the + mail server supports STARTTLS (type the password again when asked), then send a test e-mail. - `pnpm payload generate:types`, `pnpm ipal:skills`. ### Known limitations - Write-only protects the API and the panel, not the database: the two secrets are stored in plain text there and in backups (encryption at rest is not part of this release). A secret equal to `********` or `[[clear]]` - cannot be stored. + cannot be stored. A session that may send e-mail can still use the mailbox through the site (send, not + read). "Require encryption" is off by default: until it is ticked, a server (or someone in between) that + offers no STARTTLS on a port other than 465 gets the password in clear text, as before. +- The account rules for a staff collection with role values of its own do not enforce those roles: inside the + collection every account may create, change and delete accounts, as before. `read` is not touched: a staff + collection of your own without a `read` rule is readable by any logged-in account (Payload's default). - The panel role and the password rule need `access` (roles) resp. a staff collection with password login; a second staff collection without a `roles` field is not affected by `panelRole`. - The stored verify count uses Payload's `payload.kv`; on a Payload version without it the count is in memory @@ -98,7 +151,8 @@ once there are more than 20. - The own-origin check trusts `Host` / `X-Forwarded-Host` as the proxy sets them, and passes requests without `Origin` and `Sec-Fetch-Site` (non-browser clients). - `access-missing` and `csrf-empty` are text searches of the config file and can miss or misread unusual - spellings; `open-signup` evaluates a `create` rule with an anonymous request and counts a rule that throws as closed. + spellings; `open-signup` and `staff-accounts-open` call the access rules with a made-up request and count a + rule that throws as closed. - **Not run for this release:** see the hand-over; in short, the panel checks ran in Chromium on MongoDB only. ## Unreleased diff --git a/docs/access.md b/docs/access.md index b26966f..cb4c1c3 100644 --- a/docs/access.md +++ b/docs/access.md @@ -23,7 +23,7 @@ ipalKit({ |---|---|---| | `access.authCollection` | — (required) | the auth collection that gets the `roles` field | | `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.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 — then mind the panel role, [Account rules](#account-rules-accounts) | | `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 | @@ -234,6 +234,7 @@ ipalKit({ access: { authCollection: 'users' }, // accounts: { panelRole: 'user' }, // every account may open the panel (as before) // accounts: { adminOnlyCreate: false }, // Payload's default `create` on your own staff collection + // accounts: { adminOnlyWrite: false }, // Payload's default `update` / `delete` there // accounts: { firstUserRoute: 'all' }, // Payload's first-user route for every empty auth collection // accounts: { firstUserRoute: ['users', 'partners'] }, // accounts: { password: { minLength: 16 } }, // or password: false @@ -259,35 +260,69 @@ at the second factor, so the 2FA screens stay reachable. - **Check:** log in to `/admin` as an account with the role `user` → "Unauthorized"; `GET /api/access` for it → `canAccessAdmin: false`; `GET /api/users/me` still answers. -### Nobody creates an account for themselves (`accounts.adminOnlyCreate`, `accounts.firstUserRoute`) +### Nobody creates an account for themselves, or takes one over (`accounts.adminOnlyCreate`, `accounts.adminOnlyWrite`, `accounts.firstUserRoute`) By default only the first account of a site can be registered by a visitor, and it becomes admin -(`access.firstUserAdmin`); every other account is made by an admin. +(`access.firstUserAdmin`); every other account is made by an admin, and an account is changed by an admin or by +its owner. + +Payload's default for a collection without access rules is "any logged-in user" for `create`, `update` and +`delete` — an account of **any** auth collection. On a project's own staff collection a visitor account +(`customers`) could therefore create a staff account, or `PATCH` a staff account's password and roles. | | Before | Now (default) | |---|---|---| | Anonymous `POST /api/users`, GraphQL `createUser` | refused | refused | | The first account: `POST /api/users/first-register` on an empty collection | 200, role `admin` | the same | | A signed-in editor or plain user creates an account in the plugin's injected collection | refused | refused | -| …in **the project's own** staff collection that has no `create` rule | **allowed** (Payload's default: any logged-in user) | refused — an admin, fully signed in (`staffCreateAccess`) | +| …in **the project's own** staff collection that has no `create` rule | **allowed** (Payload's default) | refused — an admin, fully signed in | +| A visitor account (`customers`) changes or deletes an account of the project's own staff collection that has no `update` / `delete` rule | **allowed** (Payload's default) | refused | | `POST /api//first-register` on another empty auth collection (`members`) | **200** | 403 | | …on an empty **second staff collection** (`access.staffCollections`) | **200, and that account was staff** | 403 — an admin of the panel's collection creates its first account | | A collection that allows sign-up (`customers` with `create: () => true`) | allowed | allowed, its first-user route too | -- `adminOnlyCreate` applies to the staff collections (the panel's login collection, `access.authCollection`, - `access.staffCollections`) that have **no** `create` rule; a rule you wrote stays. `false` = Payload's default. +**Which rule a staff collection gets** (the panel's login collection, `access.authCollection`, +`access.staffCollections`) — only for an operation it has **no** rule for; a rule you wrote always stays: + +| The collection | `create` | `update` | `delete` | +|---|---|---|---| +| 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)`) | an admin | +| 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 | the same | + +Always "fully signed in": a session that still owes its second factor passes none of them. In the second row +your own roles are not enforced by the plugin — what was allowed inside the collection stays allowed; what +closes is the door for accounts of **other** collections. Write your own rules to say who inside may do what. + +- `adminOnlyCreate: false` = Payload's default `create`; `adminOnlyWrite: false` = Payload's default `update` + and `delete`. The rules are put on the collections **before** the 2FA package wraps them, so they hold with + 2FA on and off. +- `read` is not touched: a staff collection of your own without a `read` rule is readable by any logged-in + account (Payload's default; the injected collection has "admin or self"). Write a `read` rule + (`adminOrSelfIn(slug)`). - `firstUserRoute`: `'panel'` (default) = the collection the panel logs in with; a list of slugs = those; `'all'` = Payload's behaviour. A collection whose own `create` rule lets an anonymous request through keeps - its route. + its route. The plugin puts its own `POST /first-register` endpoint in front of Payload's on every auth + collection (`buildFirstUserEndpoint`): it refuses, or hands the request to Payload's handler. It does not read + the request path, so the spelling of the URL (`/First-Register`) changes nothing. A collection with + `endpoints: false` is left alone. - **A fresh site:** whoever opens the panel first becomes the admin — create the first account right after the first deploy. -- **What an existing site sees:** nothing, unless its own staff collection relied on Payload's default `create` - (non-admins creating accounts) — then give it a `create` rule or set `adminOnlyCreate: false`. -- `ipal-doctor --url` lists auth collections with open sign-up (`open-signup`, info). -- Building blocks: `staffCreateAccess`, `applyAdminOnlyCreate`, `buildFirstUserGuard`, `applyFirstUserRoute`, - `openSignUpCollections`. +- **`access.firstUserAdmin: false`** gives the first account the default role. If that role is below the panel + role, nobody could open the panel on a fresh site: with the default panel role the plugin then does **not** + apply it and says so at start; with `accounts.panelRole` set by you the config is refused at start. Set + `access.defaultRole: 'editor'`, or `accounts: { panelRole: false }`. +- **What an existing site sees:** nothing, unless its own staff collection relied on Payload's defaults + (non-admins creating accounts in a collection with the plugin's roles; accounts of another collection writing + to it) — then write the rule you want, or set `adminOnlyCreate: false` / `adminOnlyWrite: false`. +- `ipal-doctor --url`: `open-signup` (info) lists auth collections with open sign-up; `staff-accounts-open` + (error) names a staff collection an account of another collection may create in, update or delete from + (the rules are off, or your own rule is wider). +- Building blocks: `staffCreateAccess`, `staffUpdateAccess`, `sameStaffCollectionAccess`, `hasPluginRoles`, + `applyStaffAccountAccess`, `buildFirstUserEndpoint`, `applyFirstUserRoute`, `openSignUpCollections`, + `staffCollectionsOpenToOthers`. - **Check:** `curl -X POST /api/members/first-register -H 'content-type: application/json' -d - '{"email":"x@example.com","password":"a-long-password-1"}'` → `403`; the same for `/api/users` → `403`. + '{"email":"x@example.com","password":"a-long-password-1"}'` → `403`, also as `/First-Register`; the same for + `/api/users` → `403`. Logged in as a visitor account: `PATCH /api/users/` → `403`. ### Passwords (`accounts.password`, default 12 characters) @@ -299,6 +334,9 @@ changed. The message is in the panel's language, English or Polish ("The passwor characters."; texts `passwordTooShort`, `passwordIsEmail` in `i18n.translations..ipal`). - `password: { minLength: 16 }`; `password: false` = Payload's rule. Visitor collections are not touched. +- Checked against the account's address also where the request carries none: a change by id, a reset by e-mail + (the account is found by its token), a bulk update (every account it matches). A password that is not text + (a number, a list) is refused with the same message. - No breached-password lookup (it would send part of a hash of every new password to an outside service); build one on `checkPassword` / `buildPasswordRuleHook` if a project needs it. - A script or seed that creates a staff account with a shorter password now fails with a validation error. @@ -308,8 +346,8 @@ characters."; texts `passwordTooShort`, `passwordIsEmail` in `i18n.translations. ## Turn off, override, extend -- **Account rules:** `accounts: false`, or one by one — `panelRole`, `adminOnlyCreate`, `firstUserRoute`, - `password` (above). +- **Account rules:** `accounts: false`, or one by one — `panelRole`, `adminOnlyCreate`, `adminOnlyWrite`, + `firstUserRoute`, `password` (above). - **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.staffCollections` (who is staff), `access.authAccess` (injected collection), your own auth collection (wins whole), diff --git a/docs/agent/AGENT.md b/docs/agent/AGENT.md index c3ea0e9..84662ef 100644 --- a/docs/agent/AGENT.md +++ b/docs/agent/AGENT.md @@ -1168,13 +1168,14 @@ add missing hosts with flags / `extra`; (3) change `mode` to `'enforce'` in both | 2FA setup required: an account without TOTP reaches only the setup screen; 72 h window from creation / admin reset, then blocked; status and "Reopen setup" on the account page, notice on the dashboard, `POST /api/ipal/two-factor/reset` | `twoFactor.requireSetup: false`; parts: `requireSetup: { dashboardNotice: false, statusField: false, setupNotice: false }` | `requireSetup: { windowHours, exempt }` (`exempt` returns exactly `true`, never `async`), `twoFactor.resetAccess` (default: an admin who entered its own code; the reset ends the account's sessions), texts `twoFactor*`; `twoFactorSetupState(req)`, `buildSetupFields`, `backfillSetupFrom`, `buildTwoFactorResetEndpoint`. **Postgres/SQLite: migration for `totp_setup_from` applied when the new container starts (`prodMigrations` or `pnpm payload migrate && pnpm start`; never a pre-deployment command — deployment.md §4.3), or every login answers 500** | | The second factor on every collection and global, whichever plugin added it, and on the plugin's endpoints; an unrecognised 2FA package = startup error | per entity: `custom.ipal.secondFactor: false` or `{ read: false }` (or the package's `custom.totp.disableAccessWrapper`); everywhere: `twoFactor.guard: false` (not recommended) | `requireSecondFactor` / `secondFactorPassed` in your own access functions and endpoints | | At most 5 verify attempts per account in 10 minutes (`POST /api/verify-totp` → `429`); the count is kept in memory and in the database (`payload.kv`), so a restart or a second instance does not reset it | `twoFactor.verifyLimit: false` | `verifyLimit: { max, windowMinutes, store: 'memory' }` | -| 2FA verify and setup attempts only from the site's own origin: a request a browser marks as coming from elsewhere (`Origin`, `Sec-Fetch-Site`) gets `403` and is not counted | `twoFactor.sameOrigin: false` | `sameOrigin: { origins: ['https://app.example.com'] }`; `requestFromOwnOrigin` | -| 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 | +| 2FA verify and setup attempts only from the site's own origin: a request a browser marks as coming from elsewhere (`Origin`, `Sec-Fetch-Site`) gets `403` and is not counted. **Set `serverURL`**: behind a proxy that rewrites `Host` and sends no `X-Forwarded-Host` the site's own page is refused without it (logged once per origin: `[ipal] 2FA: a code from origin … was refused`) | `twoFactor.sameOrigin: false` | `sameOrigin: { origins: ['https://app.example.com'] }`; `requestFromOwnOrigin`, `reportRefusedOrigin` | +| 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, user name or "Require encryption" (or switches the transport to SMTP) without the password is refused (`400` "Enter the password again…") — otherwise an admin session points the server at its own machine and a test e-mail hands the password over. Seeds and scripts (Local API, access control off) are not asked. Site integrations → E-mail sending has **"Require encryption"** (`smtpRequireTls`, off by default; a new field — Postgres / SQLite need a migration): tick it where the server supports STARTTLS | `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: only an admin creates accounts in a staff collection (also the project's own); Payload's first-user route answers only for the panel's login collection (the first account, which becomes admin) | `accounts: { adminOnlyCreate: false, firstUserRoute: 'all' }` | your own `create` rule wins; `firstUserRoute: ['users', 'partners']`; a collection with open sign-up keeps its routes; `staffCreateAccess`, `buildFirstUserGuard` | +| Nobody creates an account for themselves, or takes one over. A staff collection (also the project's own) without a `create` / `update` / `delete` rule gets one: with the plugin's roles — create and delete: an admin; update: an admin or the account itself. With roles of its own, or none: an account of that same collection, or a plugin admin (accounts of other collections are refused; write your own rules for who inside may do what). 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 | `accounts: { adminOnlyCreate: false, adminOnlyWrite: false, firstUserRoute: 'all' }` | your own rule wins; `firstUserRoute: ['users', 'partners']`; a collection with open sign-up keeps its routes; `staffCreateAccess`, `staffUpdateAccess(slug)`, `sameStaffCollectionAccess(slug)`, `hasPluginRoles`, `applyStaffAccountAccess`, `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 | `dashboardAlerts: { integrations: 'all', cookies: 'all' }` | `integrations: 'editor'`; the components' `details` / `audience` props | +| 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 | | The `back` link of the 2FA setup and verify screens is checked on the server (`SafeTotpView` in front of the package's views): only a path on the site's origin inside the admin route is kept, anything else (`javascript:`, another host) becomes the admin root. Needs `generate:importmap` in the same deploy — with a stale map the 2FA screens have no code form and nobody can sign in (`ipal-doctor`, the start log and a notice above the screen report it; the notice is a hint from the file on disk and never replaces the screen; `twoFactor.importMapCheck: false` turns it off); check: password only → `/admin/verify-totp?back=https%3A%2F%2Fexample.com%2F` → code → lands on `/admin` | `twoFactor.safeBack: false` | `safeBack: (back, { adminRoute, origin }) => string`; `safeAdminBack`, `wrapTotpViews` (`@intecion/ipal-kit`), `SafeTotpView` (`@intecion/ipal-kit/admin`) for own views | | The 2FA package's endpoints (`/api/setup-totp`, `verify-totp`, `remove-totp`, `admin/*`) answer accounts of the 2FA collection only; reset and remove need the second factor | — (always on with 2FA) | `adminManageAccess` through the wrapped factory (security.md "Resetting 2FA") | | Roles count only for accounts of a staff collection, in every predicate and access function | — | `access.staffCollections` | diff --git a/docs/agent/skills/ipal-debug/SKILL.md b/docs/agent/skills/ipal-debug/SKILL.md index 3538251..823af16 100644 --- a/docs/agent/skills/ipal-debug/SKILL.md +++ b/docs/agent/skills/ipal-debug/SKILL.md @@ -101,13 +101,18 @@ through this procedure. Ask only when you are missing something you cannot get y | old email sender | mail client cache | check the raw headers | | form: `unknown_fields` | field outside the definition (honeypot not removed) | `ipal-form` → actions.ts | | 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 | 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 | create as an admin; or write the collection's `create` rule; or `adminOnlyCreate: false` | +| `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` | +| 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` | +| a fresh site with `access.firstUserAdmin: false`: the first account sees "Unauthorized", or the start fails with `leaves a fresh site with nobody who can open the panel` | the first account gets the default role, below the panel role | `access.defaultRole: 'editor'`, or `accounts: { panelRole: false }`, or drop `firstUserAdmin: false` | +| saving Site integrations fails on the password field: "Enter the password again…" | the server, port, user name or "Require encryption" changed (or the transport switched to SMTP) and the stored SMTP password is kept only for the settings it was saved with | type the password again; or "Remove the stored value" for a server without one; a seed with the Local API is not asked; `secrets: { reenterOnChange: false }` | +| e-mail fails with `Error upgrading connection with STARTTLS` | "Require encryption" is ticked and the server offers no STARTTLS on that port | the right port (587, or 465); or untick it (the password then travels unencrypted) | +| SQL site after the upgrade: Site integrations cannot be read, `column "smtp_require_tls" does not exist` | the new checkbox needs a migration | `pnpm payload migrate:create`, commit, deploy (deployment.md §4.3) | | creating an account / changing a password fails with "The password must have at least 12 characters." | `accounts.password` (applies to new passwords of staff accounts, in scripts too) | a longer password; `accounts: { password: { minLength } }` or `false` | | the API returns `"smtpPassword":"********"` / own code "lost" the SMTP password or Turnstile secret | write-only secrets: reads through access control never get the value | read on the server: `payload.findGlobal({ slug: 'site-integrations' })` (access control off); `secrets: { writeOnly: false }` restores the old behaviour | | the SMTP password "disappears" after saving Site integrations | it does not: the field shows "A value is set"; an empty save keeps it | to change it type a new one; to remove it press "Remove the stored value" (API: `'[[clear]]'`) | | a form with a File field answers "verification failed" while text forms work | Turnstile is degraded (wrong / missing secret, Cloudflare down) and forms with files fail closed | fix the keys (Site integrations → Spam protection; dashboard alert; `ipal-doctor --url` → `turnstile-degraded`); or `forms: { turnstileOnConfigError: { files: 'allow' } }` | -| `POST /api/verify-totp` (or `setup-totp`) answers `403` "Not allowed from this origin." | the request's `Origin` is not the site's own (a panel or front end on another domain, a proxy that drops `Host` / `X-Forwarded-Host`) | `twoFactor: { …, sameOrigin: { origins: ['https://'] } }`, or set `serverURL` / `csrf`; `sameOrigin: false` turns the check off | +| `POST /api/verify-totp` (or `setup-totp`) answers `403` "Not allowed from this origin." — **nobody can enter a code** | the request's `Origin` is not one the server knows as its own: a panel or front end on another domain, or a proxy that rewrites `Host` and sends no `X-Forwarded-Host` while `serverURL` is not set. The log names the origin once: `[ipal] 2FA: a code from origin "…" was refused` | set `serverURL` (best); or `twoFactor: { …, sameOrigin: { origins: ['https://'] } }`; or make the proxy send `X-Forwarded-Host`; `sameOrigin: false` turns the check off | | log: `[ipal] Deprecated: the Turnstile secret key comes from the TURNSTILE_SECRET_KEY environment variable` | the panel field is empty and the env variable is used | with the owner: copy the key into Site integrations → Spam protection, test a form, remove the variable; it keeps working meanwhile | | an editor no longer sees why an integration fails on the dashboard | dashboard alerts by role: details are for admins | an admin looks; or `dashboardAlerts: { integrations: 'editor' }` | | Turnstile always rejects | the `[ipal] Turnstile …` log says why: no secret, `invalid-input-secret`, `timeout-or-duplicate` | turnstile.md → table; secret in the panel or `TURNSTILE_SECRET_KEY`; **do not** write the secret in code | diff --git a/docs/agent/skills/ipal-reference/SKILL.md b/docs/agent/skills/ipal-reference/SKILL.md index 04a6141..ff3531e 100644 --- a/docs/agent/skills/ipal-reference/SKILL.md +++ b/docs/agent/skills/ipal-reference/SKILL.md @@ -33,11 +33,13 @@ description: Complete map of everything @intecion/ipal-kit provides — every ip | `access.staffCollections` | `[]` | more auth collections whose accounts are staff, besides the panel's login collection (`admin.user`) and `access.authCollection`; roles count **only** for accounts of a staff collection (every predicate and access function); such accounts are **not** covered by 2FA (one collection only — warning in the log at start); 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 | | `accounts` | on (all rules) | rules for the accounts of the staff collection; each key below | `false` = none of them | | `accounts.panelRole` | `'editor'` | the lowest role that may open the admin panel (Payload's `access.admin` on the collection with the roles): an account with only `user` sees "Unauthorized"; the API is not touched; the role decides, not the second factor. First start logs `N account(s) … cannot open the admin panel` (an error when it is everyone). Needs `access` | `'user'` / `false` = everyone, as before; `'admin'`; your own `access.admin` / `access.authAccess.admin` wins | -| `accounts.adminOnlyCreate` | on | a staff collection (panel login collection, `access.authCollection`, `access.staffCollections`) without a `create` rule gets "an admin, fully signed in" instead of Payload's "any logged-in user" — also the project's own collection | `false` = Payload's default; a `create` rule you wrote always wins | -| `accounts.firstUserRoute` | `'panel'` | which auth collections `POST /api//first-register` answers for while they are empty: only the one the panel logs in with (the first account of a site → admin). Others get `403`, a second staff collection included; a collection whose own `create` allows an anonymous request keeps its route | a list of slugs; `'all'` = Payload's behaviour | +| `accounts.adminOnlyCreate` | on | a staff collection (panel login collection, `access.authCollection`, `access.staffCollections`) without a `create` rule gets one instead of Payload's "any logged-in user" — also the project's own collection. With the plugin's roles (`access.authCollection`, or a `roles` select with only `user` / `editor` / `admin`): an admin, fully signed in. With roles of its own, or none: an account of that same collection, or a plugin admin of another staff collection | `false` = Payload's default; a `create` rule you wrote always wins | +| `accounts.adminOnlyWrite` | on | the same for `update` and `delete`: with the plugin's roles — update: an admin or the account itself, delete: an admin; otherwise an account of that same collection, or a plugin admin. Closes Payload's default, under which a visitor account could change a staff account's password. `read` is not touched | `false` = Payload's default; rules you wrote always win | +| `accounts.firstUserRoute` | `'panel'` | which auth collections `POST /api//first-register` answers for while they are empty: only the one the panel logs in with (the first account of a site → admin). Others get `403`, a second staff collection included, in any spelling of the URL (the plugin's own endpoint sits in front of Payload's); a collection whose own `create` allows an anonymous request keeps its route. With `access.firstUserAdmin: false` and a default role below the panel role, the default `panelRole` is not applied (logged) and an explicit one is refused at start | a list of slugs; `'all'` = Payload's behaviour | | `accounts.password` | `{ minLength: 12 }` | when a password is SET on a staff collection (create, first-user screen, change, reset by e-mail; panel, API and Local API): at least `minLength` characters, not the account's e-mail address. Existing passwords are never checked — a shorter one keeps logging in | `{ minLength }`; `false` = Payload's rule (3 characters) | -| `secrets.writeOnly` | on | `smtpPassword` and `turnstileSecretKey` (Site integrations) are never returned: REST, GraphQL and the panel get `'********'` when a value is stored; a save with nothing / empty / the mask keeps it, a new value replaces it, `'[[clear]]'` removes it; the Local API with access control off reads the real value. The panel is the source of these secrets — no env variable | `false` = returned to whoever may read the global, as before | -| `dashboardAlerts` | `{ integrations: 'admin', cookies: 'editor' }` | who sees the plugin's dashboard alerts: integration details (error text, link) for `integrations` and above, a neutral "ask an administrator" for editors below it, nothing for others; the cookie crawl / approval alert for `cookies` and above. A session that owes its second factor sees none | `integrations: 'editor' | 'all'`, `cookies: 'all'` (`'all'` = as before) | +| `secrets.writeOnly` | on | `smtpPassword` and `turnstileSecretKey` (Site integrations) are never returned: REST, GraphQL and the panel get `'********'` when a value is stored; a save with nothing / empty / the mask keeps it, a new value replaces it, `'[[clear]]'` removes it; the Local API with access control off reads the real value. The panel is the source of these secrets — no env variable. A restore of a version is masked too | `false` = returned to whoever may read the global, as before | +| `secrets.reenterOnChange` | on | a save through access control that changes `smtpHost`, `smtpPort`, `smtpUser`, `smtpRequireTls`, or switches `emailTransport` to SMTP, while a password is stored, must send the password again or remove it (`400` on the field otherwise) — so an admin session cannot send the stored password to a server of its own. The Local API with access control off is not asked | `false` = the stored password follows the new server | +| `dashboardAlerts` | `{ integrations: 'admin', cookies: 'editor' }` | who sees the plugin's dashboard alerts: integration details (error text, link) for `integrations` and above, a neutral "ask an administrator" for editors below it, nothing for others; the cookie crawl / approval alert for `cookies` and above. With a role, a session that owes its second factor sees none | `integrations: 'editor' | 'all'`, `cookies: 'all'` (`'all'` = as before: no role and no second factor is checked) | | `adminRoute` | `'/admin'` | `config.routes.admin`; stats link and views, `IntegrationAlerts` | the project moves `app/(payload)//` 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 | — | @@ -49,7 +51,7 @@ description: Complete map of everything @intecion/ipal-kit provides — every ip | `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..totpPlugin.` (security.md) | | `twoFactor.guard` | on | ipal-kit's own second-factor check on every collection and global (also the plugin's own and those of plugins listed after ipalKit) and in `userMeetsRole`; startup fails with `[ipal] twoFactor: the injected 2FA plugin did not add …` when the 2FA package lacks the `totp` strategy / `hasTotp` / `totpSecret` | per entity: `custom.ipal.secondFactor: false` / `{ read: false }` or the package's `custom.totp.disableAccessWrapper.`; `false` = the package's wrapper only (the plugin's own data then opens to a password without the code; not recommended). The package's endpoints stay limited to accounts of the 2FA collection either way | | `twoFactor.verifyLimit` | `{ max: 5, windowMinutes: 10, store: 'database' }` | attempts per account on `POST /api/verify-totp` (the 2FA package counts none): the sixth in the window, right or wrong, gets `429` + `Retry-After`. Counted in memory and in the database (`payload.kv`, the `payload-kv` collection Payload adds), so a restart or a second instance does not reset it; a failing store never opens the gate | `{ max, windowMinutes }`; `{ store: 'memory' }` = this instance only; `false` = no limit | -| `twoFactor.sameOrigin` | on | `POST /api/verify-totp` and `/api/setup-totp` refuse (`403`, not counted) a request a browser marks as coming from another origin (`Origin`, else `Sec-Fetch-Site`). Own origins: the request's host (`Host`, `X-Forwarded-Host`), `serverURL`, Payload's `csrf` / `cors`. Requests without those headers pass | `{ origins: ['https://app.example.com'] }` adds origins; `false` = off | +| `twoFactor.sameOrigin` | on | `POST /api/verify-totp` and `/api/setup-totp` refuse (`403`, not counted) a request a browser marks as coming from another origin (`Origin`, else `Sec-Fetch-Site`). Own origins: the request's host (`Host`, `X-Forwarded-Host`, a default port written out is ignored), `serverURL`, Payload's `csrf` / `cors`. Requests without those headers pass. A refusal is logged once per origin with how to allow it — behind a proxy that hides the address set `serverURL` | `{ origins: ['https://app.example.com'] }` adds origins; `false` = off | | `twoFactor.requireSetup` | on, `{ windowHours: 72 }` | an account without TOTP reaches nothing but the setup screen and `/api/setup-totp` (REST, GraphQL and the panel's data answer 403); it has `windowHours` from its creation or from an admin's reset, then it is blocked until an admin reopens setup. Adds the field `totpSetupStatus` (panel) to the 2FA collection, a dashboard notice and `POST /api/ipal/two-factor/reset`; the date field `totpSetupFrom` is there whenever 2FA is on (also with `requireSetup: false` / `guard: false`). Existing accounts get their window at the first start after the upgrade, written once. **Postgres/SQLite: the migration must be applied when the new container starts — `prodMigrations` or `pnpm payload migrate && pnpm start`, not a pre-deployment command (deployment.md §4.3) — or every login answers 500**; `generate:importmap`. `exempt` must return exactly `true` at once (an `async` one, or a `windowHours` that is not a number / `false`, stops the start) | `false` = the package's rule (API open until setup); `{ windowHours: 24 }`, `{ windowHours: false }` (no limit), `{ exempt: ({ user }) => … }` (a service account) | | `twoFactor.requireSetup.dashboardNotice` / `.statusField` / `.setupNotice` | on | the administrators' notice on the dashboard; the status and reset control on the account page; the notice on the setup screen | `false` each (the lock and the reset endpoint stay) | | `twoFactor.resetAccess` (the endpoint exists with `twoFactor.guard` on; `guard: false` = no endpoint, 404) | a staff admin whose session entered its own TOTP code (not an API key, not an `exempt` account) | who may reset another account's TOTP / reopen its setup (the button on the account page, `POST /api/ipal/two-factor/reset`). The reset clears the secret and the account's sessions. A session that still owes its code is always refused | `({ req }) => boolean` — replaces the rule, so keep `req.user?._strategy === 'totp' &&` in it unless API-key / exempt admins should reset; only `true` allows; `req.user._strategy` tells `'totp'`, `'api-key'`, `'local-jwt'` apart | diff --git a/docs/agent/skills/ipal-reference/resources/api.md b/docs/agent/skills/ipal-reference/resources/api.md index b89f81a..33cc866 100644 --- a/docs/agent/skills/ipal-reference/resources/api.md +++ b/docs/agent/skills/ipal-reference/resources/api.md @@ -67,10 +67,12 @@ 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`, `applyAdminOnlyCreate(config, staffSlugs)`, `buildFirstUserGuard(option?)`, `applyFirstUserRoute(config, option?)`, `openSignUpCollections(payload)` | `@intecion/ipal-kit` | `accounts.adminOnlyCreate` / `firstUserRoute`: the `create` rule "an admin, fully signed in" and its applier (staff auth collections without a `create` rule); the `beforeOperation` hook that refuses `POST /api//first-register` unless the collection is the panel's login collection (`'panel'`), is in the list, or its own `create` lets an anonymous request through; the applier (`'all'` adds nothing); the slugs of auth collections with open sign-up (for the doctor). | -| `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; login is never checked); the applier; the option → `{ minLength }` or `null`; `12`. | -| `writeOnlySecret(field)`, `writeOnlySecrets(fields, names)`, `maskSecretAfterRead`, `keepSecretBeforeValidate`, `SECRET_MASK`, `SECRET_CLEAR`, `isSecretMask(value)`, `INTEGRATION_SECRET_FIELDS` | `@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 two constants; the plugin's own secret field names (`smtpPassword`, `turnstileSecretKey`). | -| `requestFromOwnOrigin(req, extraOrigins?)`, `ownOrigins(req, extraOrigins?)` | `@intecion/ipal-kit` | `twoFactor.sameOrigin`: `false` when a browser marks the request as coming from another origin (`Origin` not among the request's host, `serverURL`, `csrf`, `cors`, the extras; else `Sec-Fetch-Site` not `same-origin` / `none`); `true` without those headers. `ownOrigins` → `{ hosts, origins }`. For your own state-changing endpoint. | +| `staffCreateAccess`, `staffUpdateAccess(slug)`, `sameStaffCollectionAccess(slug)`, `hasPluginRoles(collection)`, `applyStaffAccountAccess(config, staffSlugs, { create?, write?, pluginRoles? })` | `@intecion/ipal-kit` | `accounts.adminOnlyCreate` / `adminOnlyWrite`: the access functions — "an admin, fully signed in" (create, delete); "an admin, or the account itself" (update; self = an account of THAT collection); "an account of this staff collection, or a plugin admin of another" (a collection whose roles are not the plugin's); whether a collection carries the plugin's roles (a top-level `roles` select with only `user` / `editor` / `admin`); the applier — puts the rules on the named staff collections for the operations that have none, `pluginRoles` = slugs whose roles field is injected later. Run it before any plugin that wraps access (the 2FA package). | +| `buildFirstUserEndpoint(option?)`, `applyFirstUserRoute(config, option?)`, `openSignUpCollections(payload)`, `staffCollectionsOpenToOthers(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, update or delete from. | +| `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 (`emailTransport`, `smtpHost`, `smtpPort`, `smtpUser`, `smtpRequireTls`). | +| `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. | +| `requestFromOwnOrigin(req, extraOrigins?)`, `ownOrigins(req, extraOrigins?)`, `reportRefusedOrigin(req, extraOrigins?)` | `@intecion/ipal-kit` | `twoFactor.sameOrigin`: `false` when a browser marks the request as coming from another origin (`Origin` not among the request's host, `serverURL`, `csrf`, `cors`, the extras; a default port written out on the host is ignored; else `Sec-Fetch-Site` not `same-origin` / `none`); `true` without those headers. `ownOrigins` → `{ hosts, origins }`. `reportRefusedOrigin` writes one log line per refused origin and process (at most 50) with the ways to allow it, and returns whether it wrote. For your own state-changing endpoint. | | `buildVerifyLimit(collection, { max?, windowMinutes?, store? })`, `verifyLimitKey(collection, id)`, `clearVerifyLimits()` | `@intecion/ipal-kit` | `twoFactor.verifyLimit`: `async (req) => Response \| null` — counts an attempt of `req.user` in memory and, unless `store: 'memory'`, in `payload.kv`; a `429` with `Retry-After` past `max`. The kv key of an account's count; emptying the in-memory counts (tests). | | `turnstileSecretFromEnv(integrations)`, `TURNSTILE_SECRET_ENV` | `@intecion/ipal-kit` | `true` when the Turnstile secret in use comes from the environment because the panel field is empty (**deprecated** path; the doctor's `turnstile-env-key`); the variable's name, `'TURNSTILE_SECRET_KEY'`. | | `userMeetsRole(req, minimum)` | `@intecion/ipal-kit` | Predicate → `boolean` with `req` (`{ payload, user }`), in this order: the account belongs to a **staff collection** (`admin.user`, `access.authCollection`, `access.staffCollections`); with 2FA on it has passed the second factor (`secondFactorPassed`); it has a role ≥ `minimum`, **or** its collection has no `roles` field (the project omitted `access`). An account of any other auth collection never passes, whatever fields it has. The plugin's staff features (Site integrations, settings globals, form submissions, consent records, stats, cookie scanner, the e-mail test) use it; use it in your own endpoints. | @@ -79,7 +81,7 @@ Admin panel components from `@intecion/ipal-kit/admin` — the project does NOT | `buildRolesField(defaultRole?, { firstUserAdmin? })` | `@intecion/ipal-kit` | The `roles` select field the plugin injects (only admins set roles; `firstUserAdmin` default `true` = the account made on "Create first user" gets `admin`). The plugin wires it itself — use it only for an auth collection the plugin does not manage. | | `injectRoles(config, accessOption)` | `@intecion/ipal-kit` | Adds `roles` to `accessOption.authCollection` in a config. The plugin calls it itself with `access` — do not call. | -**Types:** `AccountsOptions` (`accounts`: `panelRole`, `adminOnlyCreate`, `firstUserRoute`, `password`), `PasswordRuleOptions` (`{ minLength? }`), `FirstUserRouteOption` (`'panel' \| 'all' \| string[]`), `TurnstileOnConfigError` / `TurnstileOnConfigErrorOption` / `TurnstileFormKind` (`@intecion/ipal-kit/server`), `VerifyLimitOptions` (`twoFactor.verifyLimit`: `{ max?, windowMinutes?, store? }`), `RequireSetupOptions` (`twoFactor.requireSetup`), `TwoFactorResetOptions`, `TwoFactorSetupState`, `SafeBackRule` / `SafeBackContext` (`twoFactor.safeBack` as a function: `(back, { adminRoute, origin? }) => string`), `TotpViewComponent` (a view component as registered: a path or `{ path, exportName?, clientProps?, serverProps? }`), `SafeTotpViewProps` (`@intecion/ipal-kit/admin`), `Role` (`'user' \| 'editor' \| 'admin'`), `AccessOption` (the plugin's `access` option: `authCollection`, `defaultRole`, `authAccess`, `firstUserAdmin`, `staffCollections`). +**Types:** `AccountsOptions` (`accounts`: `panelRole`, `adminOnlyCreate`, `adminOnlyWrite`, `firstUserRoute`, `password`), `WriteOnlySecretOptions` (`{ boundTo?, appliesWhen? }`), `PasswordRuleOptions` (`{ minLength? }`), `FirstUserRouteOption` (`'panel' \| 'all' \| string[]`), `TurnstileOnConfigError` / `TurnstileOnConfigErrorOption` / `TurnstileFormKind` (`@intecion/ipal-kit/server`), `VerifyLimitOptions` (`twoFactor.verifyLimit`: `{ max?, windowMinutes?, store? }`), `RequireSetupOptions` (`twoFactor.requireSetup`), `TwoFactorResetOptions`, `TwoFactorSetupState`, `SafeBackRule` / `SafeBackContext` (`twoFactor.safeBack` as a function: `(back, { adminRoute, origin? }) => string`), `TotpViewComponent` (a view component as registered: a path or `{ path, exportName?, clientProps?, serverProps? }`), `SafeTotpViewProps` (`@intecion/ipal-kit/admin`), `Role` (`'user' \| 'editor' \| 'admin'`), `AccessOption` (the plugin's `access` option: `authCollection`, `defaultRole`, `authAccess`, `firstUserAdmin`, `staffCollections`). ## Accessibility — widget (`accessibility`) — details: `node_modules/@intecion/ipal-kit/docs/accessibility.md` diff --git a/docs/agent/skills/ipal-setup/SKILL.md b/docs/agent/skills/ipal-setup/SKILL.md index 375ac3f..8006ad5 100644 --- a/docs/agent/skills/ipal-setup/SKILL.md +++ b/docs/agent/skills/ipal-setup/SKILL.md @@ -249,15 +249,25 @@ the panel shows Site settings, Site integrations, Cookies, Form messages, the Fo blocked"). One entity reachable without the code: `custom.ipal.secondFactor`. - **Account rules** (`accounts`, on by default; `false` or key by key to change): the panel opens for `editor` and above (`panelRole`; an account with only `user` sees "Unauthorized", the API is not touched — give panel - users at least `editor`); only an admin creates staff accounts, also in the project's own collection - (`adminOnlyCreate`), and Payload's first-user route answers only for the panel's login collection - (`firstUserRoute`) — so **create the first account right after the first deploy**, it becomes the admin; a new - password has at least 12 characters (`password`). A customer collection with sign-up: write its own - `create: () => true`; the rules do not touch it. access.md "Account rules". + users at least `editor`); only an admin creates staff accounts, and an account is changed by an admin or by + itself — also in the project's own staff collection (`adminOnlyCreate`, `adminOnlyWrite`; a staff collection + with role values of its own gets "an account of that collection, or a plugin admin" instead, so write its + `create` / `update` / `delete` / `read` rules yourself); Payload's first-user route answers only for the + panel's login collection (`firstUserRoute`) — so **create the first account right after the first deploy**, it + becomes the admin; a new password has at least 12 characters (`password`). A customer collection with + sign-up: write its own `create: () => true`; the rules do not touch it. Do not combine + `access.firstUserAdmin: false` with a default role below the panel role (the start refuses or drops the panel + role). access.md "Account rules". +- **`serverURL`**: set it in the Payload config. Without it, behind a proxy that rewrites `Host` and sends no + `X-Forwarded-Host`, the 2FA code page is refused as "another origin" (logged once: `[ipal] 2FA: a code from + origin … was refused`). Coolify / Traefik keep `Host`, so it works there either way. - **Stored secrets:** the SMTP password and the Turnstile secret key are entered **in the panel** (Site integrations) and are write-only — the panel and the API show "a value is set". Do not add env variables for them; `TURNSTILE_SECRET_KEY` is deprecated (local test keys in `.env` still work). Read them only on the - server with the Local API. `secrets: { writeOnly: false }` turns it off. + server with the Local API. `secrets: { writeOnly: false }` turns it off. Changing the SMTP server, port or + user name in the panel asks for the password again (`secrets.reenterOnChange`); a seed with the Local API is + not asked. Tick **Require encryption** in Site integrations → E-mail sending where the mail server supports + STARTTLS (off by default; the field `smtpRequireTls` needs a migration on Postgres / SQLite). - **Forms with files** are refused while Turnstile cannot check (wrong keys, Cloudflare down); text forms are still accepted. `forms: { turnstileOnConfigError: … }` changes either. - A second auth collection (`customers`, a client zone): set `admin: { user: 'users' }` in `buildConfig`; its diff --git a/docs/agent/skills/ipal-upgrade/SKILL.md b/docs/agent/skills/ipal-upgrade/SKILL.md index 886f703..fc9572d 100644 --- a/docs/agent/skills/ipal-upgrade/SKILL.md +++ b/docs/agent/skills/ipal-upgrade/SKILL.md @@ -424,8 +424,11 @@ setup screen with "Set up two-step verification by …"; after the code it is in account → "Two-step verification: Set up." and the reset button; delete the account. **→ the release with `accounts` / `secrets` (CHANGELOG "Unreleased — hardening"; PROGRAMISTA §6, item 69) — read every point, most sites change nothing:** -1. Update the package, `pnpm install`, `pnpm ipal:skills`, `pnpm payload generate:types`. No import-map change, no - schema change, no migration (the verify count uses Payload's own `payload-kv` collection). +1. Update the package, `pnpm install`, `pnpm ipal:skills`, `pnpm payload generate:types`. No import-map change. + **One new field**: `smtpRequireTls` (a checkbox) in Site integrations — MongoDB needs nothing; **Postgres / + SQLite: `pnpm payload migrate:create`, commit, deploy the migration with the code** (deployment.md §4.3), or + Site integrations cannot be read (no e-mail, no Turnstile). The verify count uses Payload's own `payload-kv` + collection. 2. **Panel access by role.** After the first start read the log: `[ipal] N account(s) of "users" are below the role "editor" and cannot open the admin panel`. Those accounts (role `user`, or no role) now see "Unauthorized" in the panel. Give the people who work in the panel `editor`, or set @@ -436,7 +439,13 @@ account → "Two-step verification: Set up." and the reset button; delete the ac stored; the panel shows "a value is set". `grep -rn "smtpPassword\|turnstileSecretKey" src` — code that read them over REST / GraphQL as an admin, or with `overrideAccess: false`, now gets `'********'`: read them on the server with `payload.findGlobal({ slug: 'site-integrations' })`. A script that saves the whole global back - keeps the secrets (the mask means "keep"). + keeps the secrets (the mask means "keep"). **New:** a save in the panel or over the API that changes the SMTP + server, port, user name or "Require encryption" must send the password again ("Enter the password again…"); + a script that does that over REST / GraphQL sends the password with it, a seed with the Local API is not + asked. `secrets: { reenterOnChange: false }` turns it off. With the owner, consider ticking **Require + encryption** (Site integrations → E-mail sending) where the server supports STARTTLS, then send a test + e-mail. During a rolling update a page opened under the new version and saved against the OLD one stores + `********` as the password: after the deploy, check that a test e-mail goes out. 4. **`TURNSTILE_SECRET_KEY` is deprecated** (it still works). If the log says `[ipal] Deprecated: the Turnstile secret key comes from the TURNSTILE_SECRET_KEY environment variable` or `ipal-doctor --url` reports `turnstile-env-key`: with the owner, copy the key into Site integrations → Spam protection → Secret key, send a @@ -445,20 +454,35 @@ account → "Two-step verification: Set up." and the reset button; delete the ac 5. **Forms with files and Turnstile.** While Turnstile cannot check (wrong keys, Cloudflare down), a form with a File field is now refused (text forms are accepted as before). Check `ipal-doctor --url` → no `turnstile-degraded`; to keep the old behaviour: `forms: { turnstileOnConfigError: { files: 'allow' } }`. -6. **Account creation.** A project whose **own** staff collection has no `create` rule: only admins create - accounts now (before: any signed-in account). `first-register` on any auth collection other than the panel's - login collection answers `403` unless that collection allows sign-up. Wanted otherwise: write the `create` - rule, or `accounts: { adminOnlyCreate: false, firstUserRoute: 'all' }`. +6. **Account creation and changes.** A project whose **own** staff collection has no `create` / `update` / + `delete` rule gets one (before: any signed-in account of any auth collection — a customer could change a + staff password): + - the collection carries the plugin's roles (`access.authCollection`, or a `roles` select with only `user` / + `editor` / `admin`): create and delete — an admin; update — an admin or the account itself. **Check:** does + a non-admin create or edit other accounts there today? Then write the rule you want; + - the collection has **role values of its own** (`superadmin`, …) or no roles: accounts of that collection + keep working as before; accounts of other collections are refused. Nothing to do, but write your own rules + — the plugin does not know your roles. + `first-register` on any auth collection other than the panel's login collection answers `403` unless that + collection allows sign-up. `access.firstUserAdmin: false` with a default role below `editor`: the panel role + is not applied (a warning at start), or — with `accounts.panelRole` set — the start fails with the fix in the + message. Wanted otherwise: `accounts: { adminOnlyCreate: false, adminOnlyWrite: false, firstUserRoute: 'all' }`. 7. **Passwords.** New passwords of staff accounts need 12 characters; **existing shorter passwords keep working** — nobody is logged out or asked to change. A script that creates staff accounts with a short password fails with a validation error: lengthen it, or `accounts: { password: { minLength: 8 } }`. 8. **2FA attempts from another origin** get `403`. A panel or front end on **another domain** than the API that posts to `/api/verify-totp`: add it — `twoFactor: { …, sameOrigin: { origins: ['https://panel.example.com'] } }` - (or set Payload's `csrf` / `cors`). Same-domain sites change nothing. + (or set Payload's `csrf` / `cors`). A same-domain site changes nothing **when the server knows its own + address**: `serverURL` is set, or the proxy passes `Host` (Coolify / Traefik do) or `X-Forwarded-Host`. + **Check before the deploy:** is `serverURL` set? If not and the proxy rewrites `Host` (nginx's plain + `proxy_pass`), nobody can enter a 2FA code after the upgrade — set `serverURL`. After the deploy log in with + a code; if it answers "Not allowed from this origin.", the log has `[ipal] 2FA: a code from origin "…" was + refused` with the fix. 9. **Dashboard alerts.** Editors now see "An integration needs attention. Ask an administrator." instead of the - error text; accounts with only `user` see no alerts. `dashboardAlerts: { integrations: 'all' }` restores it. + error text; accounts with only `user` see no alerts. `dashboardAlerts: { integrations: 'all' }` restores it + (`'all'` checks no role and no second factor). **Check:** `pnpm exec ipal-doctor --url ` (new rules: `access-missing`, `csrf-empty`, `open-signup`, -`turnstile-degraded`, `turnstile-env-key`); as an admin `GET /api/globals/site-integrations` shows +`staff-accounts-open`, `turnstile-degraded`, `turnstile-env-key`); as an admin `GET /api/globals/site-integrations` shows `"smtpPassword":"********"`; a test e-mail and a test form still work; an editor and an admin still log in. ## 2. Inventory (no code changes) diff --git a/docs/dev/PROGRAMISTA.md b/docs/dev/PROGRAMISTA.md index 8db0e2d..489bc35 100644 --- a/docs/dev/PROGRAMISTA.md +++ b/docs/dev/PROGRAMISTA.md @@ -676,7 +676,7 @@ Do one item at a time, build, check. Order by importance: | 66 | **1.16.4** — production `PAYLOAD_SECRET` shorter than 32 characters (the site would stop at `assertEnv`) | Before deploying 1.16.4, check the length in Coolify (`node -e 'console.log(process.env.PAYLOAD_SECRET.length)'`). Shorter: a random 32+ character secret (logs everyone out, asks for 2FA again, breaks stored API keys), or `ipalEnvRules({ secretMinLength: 0 })` for now | CHANGELOG 1.16.4, deployment.md "PAYLOAD_SECRET — length and changing it" | | 67 | **1.16.5 — security** — with 2FA on, `/admin/verify-totp?back=https%3A%2F%2Fexample.com%2F` sends the user to example.com after the code (and `back=javascript:…` runs script in the panel) | Upgrade and, **in ONE deploy**, `pnpm payload generate:importmap` (adds `@intecion/ipal-kit/admin#SafeTotpView`), commit `importMap.js`, `rm -rf .next`, redeploy on Coolify — with the old map the 2FA screens have no code form and nobody can sign in (run `pnpm exec ipal-doctor` before deploying; the start log says so too); check: the link above ends on `/admin`. `pnpm ipal:skills`. No option, env or migration; off / own rule: `twoFactor.safeBack` | CHANGELOG 1.16.5, security.md "The `back` link of the 2FA screens" | | 68 | **1.16.6 — 2FA setup required** (not a routine patch: a new default that can lock accounts out) — an account that has not set 2FA up still reads data over the API with its password; or after the upgrade an account "can do nothing" / is blocked | Before upgrading: `ipal-doctor --url` → accounts without 2FA set it up or are removed; one admin (better two) must have 2FA; deploy day agreed with the owner. Then, in ONE deploy: update, `generate:types`, `generate:importmap` (`TwoFactorStatusField`, `TwoFactorAlert`), **Postgres/SQLite: `migrate:create` and the migration applied in the same deploy when the new container starts — `prodMigrations` or `pnpm payload migrate && pnpm start`, never a pre-deployment command (deployment.md §4.3) — (column `totp_setup_from`); without it every login answers 500**, build, redeploy. Existing accounts get 72 h from the first start; blocked later → admin: account page → "Reopen setup". Password-login integrations: API key or `requireSetup.exempt`. `pnpm ipal:skills` | CHANGELOG 1.16.6, security.md "Setup required" | -| 69 | **Unreleased — hardening (M1)** — an account with only the role `user` sees "Unauthorized" in the panel; or the API returns `"smtpPassword":"********"`; or a form with a File field is refused while Turnstile is misconfigured; or "The password must have at least 12 characters." | Update, `generate:types`, redeploy; no import map, schema or migration. Read the start log (`N account(s) … cannot open the admin panel`) and give panel users `editor`. Own code that read the two secrets over the API → Local API on the server. `TURNSTILE_SECRET_KEY` is deprecated: with the owner move the key into the panel. Own staff collection without a `create` rule: admins only now. Existing short passwords keep working. Switches: `accounts`, `secrets`, `forms.turnstileOnConfigError`, `twoFactor.sameOrigin`, `dashboardAlerts`. `pnpm ipal:skills` | CHANGELOG "Unreleased — hardening", access.md "Account rules", security.md "Stored secrets", turnstile.md | +| 69 | **Unreleased — hardening (M1)** — an account with only the role `user` sees "Unauthorized" in the panel; or the API returns `"smtpPassword":"********"`; or a form with a File field is refused while Turnstile is misconfigured; or "The password must have at least 12 characters."; or "Enter the password again…" on the SMTP password; or `403` "Not allowed from this origin." on the 2FA code | Update, `generate:types`, redeploy; no import map change. One new field (`smtpRequireTls`): Postgres / SQLite need a migration, MongoDB nothing. Set `serverURL` (a proxy that rewrites `Host` otherwise blocks the 2FA code; the log names the origin). Read the start log (`N account(s) … cannot open the admin panel`) and give panel users `editor`. Own code that read the two secrets over the API → Local API on the server. `TURNSTILE_SECRET_KEY` is deprecated: with the owner move the key into the panel. Own staff collection without `create` / `update` / `delete` rules: an admin (update: or the account itself) where the roles are the plugin's, accounts of that collection where they are the project's own. Existing short passwords keep working. Switches: `accounts`, `secrets`, `forms.turnstileOnConfigError`, `twoFactor.sameOrigin`, `dashboardAlerts`. `pnpm ipal:skills` | CHANGELOG "Unreleased — hardening", access.md "Account rules", security.md "Stored secrets", turnstile.md | 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`. diff --git a/docs/doctor.md b/docs/doctor.md index 92795d1..87a99cb 100644 --- a/docs/doctor.md +++ b/docs/doctor.md @@ -66,7 +66,7 @@ Added by `ipalKit` and **off until the site has `IPAL_DOCTOR_TOKEN`** (at least returns counts only — never names, e-mails or values: ```json -{ "node": "v22.20.0", "openSignUp": [], "pendingCookies": 0, "plugin": "1.15.0", "turnstile": null, "turnstileSecretFromEnv": false, "usersSetupClosed": 0, "usersWithout2fa": 0 } +{ "node": "v22.20.0", "openSignUp": [], "pendingCookies": 0, "plugin": "1.15.0", "staffOpenToOthers": [], "turnstile": null, "turnstileSecretFromEnv": false, "usersSetupClosed": 0, "usersWithout2fa": 0 } ``` Turn off: `ipalKit({ doctor: false })`. Adapt: `ipalKit({ doctor: { tokenVar: 'MY_TOKEN', access: ({ req }) => isAdmin(req.user, req.payload) } })` (a logged-in staff admin may read it too; the second factor is checked for you — never test `req.user.roles` by hand, an account of another collection can carry the same value) @@ -102,7 +102,8 @@ 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) | -| | `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 a day | +| | `staff-accounts-open` | error | (deep) a staff collection that an account of another, non-staff auth collection may create in, update or delete from — it can make itself staff or change a staff password. The account rules are off (`accounts: false`, `adminOnlyCreate` / `adminOnlyWrite: 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 | | | `cookie-scanner` | error / warning / info | `cookieScanner` on (with `crawl`, else info); deep: nothing waits for approval (warning) | | admin | `admin-meta` | warning | ipal-kit ≥ 1.14.5, no `adminMeta: false` / `agency: false`; live: the admin `og:image` is `/api/ipal/admin-og` | diff --git a/docs/email.md b/docs/email.md index 912100a..60d97d9 100644 --- a/docs/email.md +++ b/docs/email.md @@ -22,9 +22,17 @@ install it (nodemailer 10 ships its own types, so `@types/nodemailer` is not nee ## Config -No plugin options — SMTP (`smtpHost`, `smtpPort` (default 587), `smtpUser`, +No plugin options — SMTP (`smtpHost`, `smtpPort` (default 587), `smtpRequireTls`, `smtpUser`, `smtpPassword`, `smtpFromAddress`, `smtpFromName`) and `emailTransport` live in -SiteIntegrations (E-mail sending tab). The editor configures them in the panel. The plugin does **not** set +SiteIntegrations (E-mail sending tab). The editor configures them in the panel. + +- **Require encryption** (`smtpRequireTls`, off by default): the password is sent only over an encrypted + connection — TLS on port 465, STARTTLS elsewhere. Without it, a server that offers no STARTTLS gets the + password in clear text; with it, such a server gets nothing and the send fails ("Error upgrading connection + with STARTTLS"). Tick it wherever the server supports it. A new field: Postgres / SQLite need a migration. +- **The password is write-only and stays with its server**: the panel shows "A value is set"; changing the + server, port, user name or "Require encryption" asks for the password again + ([security.md](./security.md) "Stored secrets"). The plugin does **not** set `config.email` — you wire the adapter yourself (below). ## Front — sendEmail (server) diff --git a/docs/security.md b/docs/security.md index 934a931..3d996ac 100644 --- a/docs/security.md +++ b/docs/security.md @@ -562,7 +562,16 @@ elsewhere — the `Origin` header, else `Sec-Fetch-Site` — **before it is coun request came in on (`Host`, `X-Forwarded-Host`), `serverURL`, Payload's `csrf` and `cors` lists, and `twoFactor: { …, sameOrigin: { origins: ['https://app.example.com'] } }` for a front end on another domain. A request with neither header (a script, `curl`, a server) passes: it cannot ride on somebody's cookie. -`sameOrigin: false` turns it off. `ipal-doctor` warns (`csrf-empty`) when the config sets neither `serverURL` nor +A default port written out (`X-Forwarded-Host: site.example:443`) is the same host. +`sameOrigin: false` turns it off. + +**Behind a reverse proxy that hides the site's address** — it rewrites `Host` and sends no `X-Forwarded-Host` +(nginx's plain `proxy_pass`; Traefik and Coolify keep `Host`) — and without `serverURL`, the server cannot know +its own address: the site's own verify page is refused, and **nobody can enter a code**. It is not silent: the +first refusal of every origin is logged, `[ipal] 2FA: a code from origin "https://…" was refused and not counted +— it is not one of this site's own origins (…)`, with the three ways out: set `serverURL` (the right fix, it +also fills Payload's `csrf` list), or `twoFactor: { sameOrigin: { origins: ['https://…'] } }`, or make the proxy +send `X-Forwarded-Host` (`proxy_set_header Host $host;` in nginx). `reportRefusedOrigin` is the building block. `ipal-doctor` warns (`csrf-empty`) when the config sets neither `serverURL` nor `csrf` — Payload then accepts the login cookie from any origin. **What is NOT covered — the complete list.** (1) Anonymous requests: the access function decides. (2) Accounts @@ -917,7 +926,7 @@ size while reading, content signature, container and macro checks, an optional ` Emails tab (recipients, BCC) is readable only by `editor+`. - Full table: [access.md](./access.md#what-the-plugin-locks-down-by-itself). -## Stored secrets (`secrets.writeOnly`) +## Stored secrets (`secrets.writeOnly`, `secrets.reenterOnChange`) `smtpPassword` and `turnstileSecretKey` live in the Site integrations global: **the panel is their source** (there is no env variable for the SMTP password, and the env fallback for the Turnstile secret is deprecated — @@ -934,12 +943,39 @@ size while reading, content signature, container and macro checks, an optional ` | nothing for the field, an empty value, `null`, or `'********'` back | the stored value is kept | | a new value | replaces it (the answer shows `'********'`) | | `'[[clear]]'` (`SECRET_CLEAR`) | removes it | +| the server, the port, the user name, "Require encryption" **changed**, or the transport switched to SMTP, and **no** new password | **refused** (`400`, on the password field): "Enter the password again…" | In the panel the field says "A value is set. It is not shown; type a new one to replace it." and offers "Remove -the stored value". A stolen admin session, or any way past the global's read rule, no longer yields a working -mailbox password. What it does **not** protect: the database and its backups hold the value in plain text -(encryption at rest is a separate, open question), and whoever can change the config or run server code can -read it. +the stored value". + +**The SMTP password stays with the server it was saved for** (`secrets.reenterOnChange`). Hiding the value is +not enough on its own: an admin session could point `smtpHost` / `smtpPort` at a machine of its own, press +"Send test e-mail", and read the password off the connection. So a save **through access control** (the panel, +REST, GraphQL) that changes `smtpHost`, `smtpPort`, `smtpUser`, `smtpRequireTls`, or `emailTransport` to SMTP, +while a password is stored, must send the password again — or remove it (`'[[clear]]'`, "Remove the stored +value") for a server without one. Values are compared as trimmed, lower-case text, and a value never saved +counts as the field's default, so saving the form unchanged asks for nothing. Switching to Microsoft Graph asks +for nothing either (the password is not used there). Server code — a seed, a script with the Local API and +access control off — is not asked. `ipalKit({ secrets: { reenterOnChange: false } })` = the stored password +follows the new server, as before. + +**"Require encryption"** (`smtpRequireTls`, Site integrations → E-mail sending, off by default). On port 465 the +connection is TLS from the start. On any other port the mail library upgrades with STARTTLS **when the server +offers it** — a server (or someone in between) that does not offer it gets the user name and password in clear +text. With the box ticked nothing is sent without encryption: no login, no e-mail, and the test e-mail says +"Error upgrading connection with STARTTLS". Tick it on every site whose server supports it (all the usual +providers on 587 do). It is a new field: **Postgres / SQLite need a migration** ([deployment.md](./deployment.md)). + +A stolen admin session, or any way past the global's read rule, no longer yields a working mailbox password. +What it does **not** protect: the database and its backups hold the value in plain text (encryption at rest is +a separate, open question); whoever can change the config or run server code can read it; and a session that +knows nothing but may send e-mail can still **use** the mailbox through the site (send, not read). + +**Versions.** The global has no versions by default. A project that turns them on +(`globalOverrides: { 'site-integrations': { versions: … } }`) stores the secret in every version — as in the +document itself — and reads of versions are masked like any read. A **restore** answers with the version +document, the fields under `version`, where field hooks do not run: the global's `afterRead` hook +`maskSecretsOnRestore` masks them there too. A restore brings back the password of that version. - **What an existing site sees after the upgrade:** nothing to do. The stored values stay; the panel shows "a value is set"; the API returns the mask. Code of your own that read the secret over REST / GraphQL as an admin @@ -950,8 +986,15 @@ read it. tabs / rows / groups; the hooks `maskSecretAfterRead` / `keepSecretBeforeValidate`, `SECRET_MASK`, `SECRET_CLEAR`, `isSecretMask`, `INTEGRATION_SECRET_FIELDS` are exported. A real secret equal to `********` or `[[clear]]` cannot be stored. + - Bound to other fields, like the SMTP password: `writeOnlySecret(field, { boundTo: ['apiUrl'] })`, or + `writeOnlySecrets(fields, ['apiToken'], { apiToken: { boundTo: ['apiUrl'], appliesWhen: (data) => … } })` + (`WriteOnlySecretOptions`; `buildKeepSecret(options)` is the hook; `SMTP_PASSWORD_BOUND_TO` is the plugin's + list). The fields must be siblings of the secret. + - With versions on your entity: add `hooks: { afterRead: [maskSecretsOnRestore] }` to the global or the + collection (`maskWriteOnlySecrets(data, fields)` is the walker it uses). - **Check:** as a fully signed-in admin, `GET /api/globals/site-integrations` → `"smtpPassword":"********"`; save - the form without touching the field → a test e-mail still goes out. + the form without touching the field → a test e-mail still goes out; change the server without typing the + password → the save is refused with "Enter the password again…". ## Dashboard alerts by role (`dashboardAlerts`) @@ -960,12 +1003,14 @@ so each decides who sees it. **Integration alerts** (Site integrations is admin- failing and the link; an editor sees "An integration needs attention. Ask an administrator to look at it."; anyone else sees nothing. **Cookie alerts** (crawl result, cookies waiting): editors and above. A session that still owes its second factor sees none of them. `ipalKit({ dashboardAlerts: { integrations: 'editor' | 'all', cookies: 'all' } })` -loosens it (`'all'` = everyone who opens the dashboard, as before); the components take the same as props +loosens it. **`'all'` checks nothing** — no role and no second factor: whoever the dashboard is drawn for sees +the full text, as before. The components take the same as props (`details`, `audience`). ## Turn off, override, extend -- **Stored secrets:** `secrets: { writeOnly: false }`; `writeOnlySecret` / `writeOnlySecrets` for your own fields. +- **Stored secrets:** `secrets: { writeOnly: false }`, `secrets: { reenterOnChange: false }`; `writeOnlySecret` / + `writeOnlySecrets` (with `boundTo`), `maskSecretsOnRestore` for your own fields. - **2FA attempts from another origin:** `twoFactor.sameOrigin: false`, or `{ origins: [...] }`; `requestFromOwnOrigin`, `ownOrigins` are exported. **Verify count:** `verifyLimit: { store: 'memory' }`; `buildVerifyLimit`, `verifyLimitKey`, `clearVerifyLimits` (tests) are exported. diff --git a/reference/.agents/skills/ipal-debug/SKILL.md b/reference/.agents/skills/ipal-debug/SKILL.md index 3538251..823af16 100644 --- a/reference/.agents/skills/ipal-debug/SKILL.md +++ b/reference/.agents/skills/ipal-debug/SKILL.md @@ -101,13 +101,18 @@ through this procedure. Ask only when you are missing something you cannot get y | old email sender | mail client cache | check the raw headers | | form: `unknown_fields` | field outside the definition (honeypot not removed) | `ipal-form` → actions.ts | | 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 | 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 | create as an admin; or write the collection's `create` rule; or `adminOnlyCreate: false` | +| `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` | +| 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` | +| a fresh site with `access.firstUserAdmin: false`: the first account sees "Unauthorized", or the start fails with `leaves a fresh site with nobody who can open the panel` | the first account gets the default role, below the panel role | `access.defaultRole: 'editor'`, or `accounts: { panelRole: false }`, or drop `firstUserAdmin: false` | +| saving Site integrations fails on the password field: "Enter the password again…" | the server, port, user name or "Require encryption" changed (or the transport switched to SMTP) and the stored SMTP password is kept only for the settings it was saved with | type the password again; or "Remove the stored value" for a server without one; a seed with the Local API is not asked; `secrets: { reenterOnChange: false }` | +| e-mail fails with `Error upgrading connection with STARTTLS` | "Require encryption" is ticked and the server offers no STARTTLS on that port | the right port (587, or 465); or untick it (the password then travels unencrypted) | +| SQL site after the upgrade: Site integrations cannot be read, `column "smtp_require_tls" does not exist` | the new checkbox needs a migration | `pnpm payload migrate:create`, commit, deploy (deployment.md §4.3) | | creating an account / changing a password fails with "The password must have at least 12 characters." | `accounts.password` (applies to new passwords of staff accounts, in scripts too) | a longer password; `accounts: { password: { minLength } }` or `false` | | the API returns `"smtpPassword":"********"` / own code "lost" the SMTP password or Turnstile secret | write-only secrets: reads through access control never get the value | read on the server: `payload.findGlobal({ slug: 'site-integrations' })` (access control off); `secrets: { writeOnly: false }` restores the old behaviour | | the SMTP password "disappears" after saving Site integrations | it does not: the field shows "A value is set"; an empty save keeps it | to change it type a new one; to remove it press "Remove the stored value" (API: `'[[clear]]'`) | | a form with a File field answers "verification failed" while text forms work | Turnstile is degraded (wrong / missing secret, Cloudflare down) and forms with files fail closed | fix the keys (Site integrations → Spam protection; dashboard alert; `ipal-doctor --url` → `turnstile-degraded`); or `forms: { turnstileOnConfigError: { files: 'allow' } }` | -| `POST /api/verify-totp` (or `setup-totp`) answers `403` "Not allowed from this origin." | the request's `Origin` is not the site's own (a panel or front end on another domain, a proxy that drops `Host` / `X-Forwarded-Host`) | `twoFactor: { …, sameOrigin: { origins: ['https://'] } }`, or set `serverURL` / `csrf`; `sameOrigin: false` turns the check off | +| `POST /api/verify-totp` (or `setup-totp`) answers `403` "Not allowed from this origin." — **nobody can enter a code** | the request's `Origin` is not one the server knows as its own: a panel or front end on another domain, or a proxy that rewrites `Host` and sends no `X-Forwarded-Host` while `serverURL` is not set. The log names the origin once: `[ipal] 2FA: a code from origin "…" was refused` | set `serverURL` (best); or `twoFactor: { …, sameOrigin: { origins: ['https://'] } }`; or make the proxy send `X-Forwarded-Host`; `sameOrigin: false` turns the check off | | log: `[ipal] Deprecated: the Turnstile secret key comes from the TURNSTILE_SECRET_KEY environment variable` | the panel field is empty and the env variable is used | with the owner: copy the key into Site integrations → Spam protection, test a form, remove the variable; it keeps working meanwhile | | an editor no longer sees why an integration fails on the dashboard | dashboard alerts by role: details are for admins | an admin looks; or `dashboardAlerts: { integrations: 'editor' }` | | Turnstile always rejects | the `[ipal] Turnstile …` log says why: no secret, `invalid-input-secret`, `timeout-or-duplicate` | turnstile.md → table; secret in the panel or `TURNSTILE_SECRET_KEY`; **do not** write the secret in code | diff --git a/reference/.agents/skills/ipal-reference/SKILL.md b/reference/.agents/skills/ipal-reference/SKILL.md index 04a6141..ff3531e 100644 --- a/reference/.agents/skills/ipal-reference/SKILL.md +++ b/reference/.agents/skills/ipal-reference/SKILL.md @@ -33,11 +33,13 @@ description: Complete map of everything @intecion/ipal-kit provides — every ip | `access.staffCollections` | `[]` | more auth collections whose accounts are staff, besides the panel's login collection (`admin.user`) and `access.authCollection`; roles count **only** for accounts of a staff collection (every predicate and access function); such accounts are **not** covered by 2FA (one collection only — warning in the log at start); 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 | | `accounts` | on (all rules) | rules for the accounts of the staff collection; each key below | `false` = none of them | | `accounts.panelRole` | `'editor'` | the lowest role that may open the admin panel (Payload's `access.admin` on the collection with the roles): an account with only `user` sees "Unauthorized"; the API is not touched; the role decides, not the second factor. First start logs `N account(s) … cannot open the admin panel` (an error when it is everyone). Needs `access` | `'user'` / `false` = everyone, as before; `'admin'`; your own `access.admin` / `access.authAccess.admin` wins | -| `accounts.adminOnlyCreate` | on | a staff collection (panel login collection, `access.authCollection`, `access.staffCollections`) without a `create` rule gets "an admin, fully signed in" instead of Payload's "any logged-in user" — also the project's own collection | `false` = Payload's default; a `create` rule you wrote always wins | -| `accounts.firstUserRoute` | `'panel'` | which auth collections `POST /api//first-register` answers for while they are empty: only the one the panel logs in with (the first account of a site → admin). Others get `403`, a second staff collection included; a collection whose own `create` allows an anonymous request keeps its route | a list of slugs; `'all'` = Payload's behaviour | +| `accounts.adminOnlyCreate` | on | a staff collection (panel login collection, `access.authCollection`, `access.staffCollections`) without a `create` rule gets one instead of Payload's "any logged-in user" — also the project's own collection. With the plugin's roles (`access.authCollection`, or a `roles` select with only `user` / `editor` / `admin`): an admin, fully signed in. With roles of its own, or none: an account of that same collection, or a plugin admin of another staff collection | `false` = Payload's default; a `create` rule you wrote always wins | +| `accounts.adminOnlyWrite` | on | the same for `update` and `delete`: with the plugin's roles — update: an admin or the account itself, delete: an admin; otherwise an account of that same collection, or a plugin admin. Closes Payload's default, under which a visitor account could change a staff account's password. `read` is not touched | `false` = Payload's default; rules you wrote always win | +| `accounts.firstUserRoute` | `'panel'` | which auth collections `POST /api//first-register` answers for while they are empty: only the one the panel logs in with (the first account of a site → admin). Others get `403`, a second staff collection included, in any spelling of the URL (the plugin's own endpoint sits in front of Payload's); a collection whose own `create` allows an anonymous request keeps its route. With `access.firstUserAdmin: false` and a default role below the panel role, the default `panelRole` is not applied (logged) and an explicit one is refused at start | a list of slugs; `'all'` = Payload's behaviour | | `accounts.password` | `{ minLength: 12 }` | when a password is SET on a staff collection (create, first-user screen, change, reset by e-mail; panel, API and Local API): at least `minLength` characters, not the account's e-mail address. Existing passwords are never checked — a shorter one keeps logging in | `{ minLength }`; `false` = Payload's rule (3 characters) | -| `secrets.writeOnly` | on | `smtpPassword` and `turnstileSecretKey` (Site integrations) are never returned: REST, GraphQL and the panel get `'********'` when a value is stored; a save with nothing / empty / the mask keeps it, a new value replaces it, `'[[clear]]'` removes it; the Local API with access control off reads the real value. The panel is the source of these secrets — no env variable | `false` = returned to whoever may read the global, as before | -| `dashboardAlerts` | `{ integrations: 'admin', cookies: 'editor' }` | who sees the plugin's dashboard alerts: integration details (error text, link) for `integrations` and above, a neutral "ask an administrator" for editors below it, nothing for others; the cookie crawl / approval alert for `cookies` and above. A session that owes its second factor sees none | `integrations: 'editor' | 'all'`, `cookies: 'all'` (`'all'` = as before) | +| `secrets.writeOnly` | on | `smtpPassword` and `turnstileSecretKey` (Site integrations) are never returned: REST, GraphQL and the panel get `'********'` when a value is stored; a save with nothing / empty / the mask keeps it, a new value replaces it, `'[[clear]]'` removes it; the Local API with access control off reads the real value. The panel is the source of these secrets — no env variable. A restore of a version is masked too | `false` = returned to whoever may read the global, as before | +| `secrets.reenterOnChange` | on | a save through access control that changes `smtpHost`, `smtpPort`, `smtpUser`, `smtpRequireTls`, or switches `emailTransport` to SMTP, while a password is stored, must send the password again or remove it (`400` on the field otherwise) — so an admin session cannot send the stored password to a server of its own. The Local API with access control off is not asked | `false` = the stored password follows the new server | +| `dashboardAlerts` | `{ integrations: 'admin', cookies: 'editor' }` | who sees the plugin's dashboard alerts: integration details (error text, link) for `integrations` and above, a neutral "ask an administrator" for editors below it, nothing for others; the cookie crawl / approval alert for `cookies` and above. With a role, a session that owes its second factor sees none | `integrations: 'editor' | 'all'`, `cookies: 'all'` (`'all'` = as before: no role and no second factor is checked) | | `adminRoute` | `'/admin'` | `config.routes.admin`; stats link and views, `IntegrationAlerts` | the project moves `app/(payload)//` 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 | — | @@ -49,7 +51,7 @@ description: Complete map of everything @intecion/ipal-kit provides — every ip | `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..totpPlugin.` (security.md) | | `twoFactor.guard` | on | ipal-kit's own second-factor check on every collection and global (also the plugin's own and those of plugins listed after ipalKit) and in `userMeetsRole`; startup fails with `[ipal] twoFactor: the injected 2FA plugin did not add …` when the 2FA package lacks the `totp` strategy / `hasTotp` / `totpSecret` | per entity: `custom.ipal.secondFactor: false` / `{ read: false }` or the package's `custom.totp.disableAccessWrapper.`; `false` = the package's wrapper only (the plugin's own data then opens to a password without the code; not recommended). The package's endpoints stay limited to accounts of the 2FA collection either way | | `twoFactor.verifyLimit` | `{ max: 5, windowMinutes: 10, store: 'database' }` | attempts per account on `POST /api/verify-totp` (the 2FA package counts none): the sixth in the window, right or wrong, gets `429` + `Retry-After`. Counted in memory and in the database (`payload.kv`, the `payload-kv` collection Payload adds), so a restart or a second instance does not reset it; a failing store never opens the gate | `{ max, windowMinutes }`; `{ store: 'memory' }` = this instance only; `false` = no limit | -| `twoFactor.sameOrigin` | on | `POST /api/verify-totp` and `/api/setup-totp` refuse (`403`, not counted) a request a browser marks as coming from another origin (`Origin`, else `Sec-Fetch-Site`). Own origins: the request's host (`Host`, `X-Forwarded-Host`), `serverURL`, Payload's `csrf` / `cors`. Requests without those headers pass | `{ origins: ['https://app.example.com'] }` adds origins; `false` = off | +| `twoFactor.sameOrigin` | on | `POST /api/verify-totp` and `/api/setup-totp` refuse (`403`, not counted) a request a browser marks as coming from another origin (`Origin`, else `Sec-Fetch-Site`). Own origins: the request's host (`Host`, `X-Forwarded-Host`, a default port written out is ignored), `serverURL`, Payload's `csrf` / `cors`. Requests without those headers pass. A refusal is logged once per origin with how to allow it — behind a proxy that hides the address set `serverURL` | `{ origins: ['https://app.example.com'] }` adds origins; `false` = off | | `twoFactor.requireSetup` | on, `{ windowHours: 72 }` | an account without TOTP reaches nothing but the setup screen and `/api/setup-totp` (REST, GraphQL and the panel's data answer 403); it has `windowHours` from its creation or from an admin's reset, then it is blocked until an admin reopens setup. Adds the field `totpSetupStatus` (panel) to the 2FA collection, a dashboard notice and `POST /api/ipal/two-factor/reset`; the date field `totpSetupFrom` is there whenever 2FA is on (also with `requireSetup: false` / `guard: false`). Existing accounts get their window at the first start after the upgrade, written once. **Postgres/SQLite: the migration must be applied when the new container starts — `prodMigrations` or `pnpm payload migrate && pnpm start`, not a pre-deployment command (deployment.md §4.3) — or every login answers 500**; `generate:importmap`. `exempt` must return exactly `true` at once (an `async` one, or a `windowHours` that is not a number / `false`, stops the start) | `false` = the package's rule (API open until setup); `{ windowHours: 24 }`, `{ windowHours: false }` (no limit), `{ exempt: ({ user }) => … }` (a service account) | | `twoFactor.requireSetup.dashboardNotice` / `.statusField` / `.setupNotice` | on | the administrators' notice on the dashboard; the status and reset control on the account page; the notice on the setup screen | `false` each (the lock and the reset endpoint stay) | | `twoFactor.resetAccess` (the endpoint exists with `twoFactor.guard` on; `guard: false` = no endpoint, 404) | a staff admin whose session entered its own TOTP code (not an API key, not an `exempt` account) | who may reset another account's TOTP / reopen its setup (the button on the account page, `POST /api/ipal/two-factor/reset`). The reset clears the secret and the account's sessions. A session that still owes its code is always refused | `({ req }) => boolean` — replaces the rule, so keep `req.user?._strategy === 'totp' &&` in it unless API-key / exempt admins should reset; only `true` allows; `req.user._strategy` tells `'totp'`, `'api-key'`, `'local-jwt'` apart | diff --git a/reference/.agents/skills/ipal-reference/resources/api.md b/reference/.agents/skills/ipal-reference/resources/api.md index b89f81a..33cc866 100644 --- a/reference/.agents/skills/ipal-reference/resources/api.md +++ b/reference/.agents/skills/ipal-reference/resources/api.md @@ -67,10 +67,12 @@ 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`, `applyAdminOnlyCreate(config, staffSlugs)`, `buildFirstUserGuard(option?)`, `applyFirstUserRoute(config, option?)`, `openSignUpCollections(payload)` | `@intecion/ipal-kit` | `accounts.adminOnlyCreate` / `firstUserRoute`: the `create` rule "an admin, fully signed in" and its applier (staff auth collections without a `create` rule); the `beforeOperation` hook that refuses `POST /api//first-register` unless the collection is the panel's login collection (`'panel'`), is in the list, or its own `create` lets an anonymous request through; the applier (`'all'` adds nothing); the slugs of auth collections with open sign-up (for the doctor). | -| `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; login is never checked); the applier; the option → `{ minLength }` or `null`; `12`. | -| `writeOnlySecret(field)`, `writeOnlySecrets(fields, names)`, `maskSecretAfterRead`, `keepSecretBeforeValidate`, `SECRET_MASK`, `SECRET_CLEAR`, `isSecretMask(value)`, `INTEGRATION_SECRET_FIELDS` | `@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 two constants; the plugin's own secret field names (`smtpPassword`, `turnstileSecretKey`). | -| `requestFromOwnOrigin(req, extraOrigins?)`, `ownOrigins(req, extraOrigins?)` | `@intecion/ipal-kit` | `twoFactor.sameOrigin`: `false` when a browser marks the request as coming from another origin (`Origin` not among the request's host, `serverURL`, `csrf`, `cors`, the extras; else `Sec-Fetch-Site` not `same-origin` / `none`); `true` without those headers. `ownOrigins` → `{ hosts, origins }`. For your own state-changing endpoint. | +| `staffCreateAccess`, `staffUpdateAccess(slug)`, `sameStaffCollectionAccess(slug)`, `hasPluginRoles(collection)`, `applyStaffAccountAccess(config, staffSlugs, { create?, write?, pluginRoles? })` | `@intecion/ipal-kit` | `accounts.adminOnlyCreate` / `adminOnlyWrite`: the access functions — "an admin, fully signed in" (create, delete); "an admin, or the account itself" (update; self = an account of THAT collection); "an account of this staff collection, or a plugin admin of another" (a collection whose roles are not the plugin's); whether a collection carries the plugin's roles (a top-level `roles` select with only `user` / `editor` / `admin`); the applier — puts the rules on the named staff collections for the operations that have none, `pluginRoles` = slugs whose roles field is injected later. Run it before any plugin that wraps access (the 2FA package). | +| `buildFirstUserEndpoint(option?)`, `applyFirstUserRoute(config, option?)`, `openSignUpCollections(payload)`, `staffCollectionsOpenToOthers(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, update or delete from. | +| `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 (`emailTransport`, `smtpHost`, `smtpPort`, `smtpUser`, `smtpRequireTls`). | +| `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. | +| `requestFromOwnOrigin(req, extraOrigins?)`, `ownOrigins(req, extraOrigins?)`, `reportRefusedOrigin(req, extraOrigins?)` | `@intecion/ipal-kit` | `twoFactor.sameOrigin`: `false` when a browser marks the request as coming from another origin (`Origin` not among the request's host, `serverURL`, `csrf`, `cors`, the extras; a default port written out on the host is ignored; else `Sec-Fetch-Site` not `same-origin` / `none`); `true` without those headers. `ownOrigins` → `{ hosts, origins }`. `reportRefusedOrigin` writes one log line per refused origin and process (at most 50) with the ways to allow it, and returns whether it wrote. For your own state-changing endpoint. | | `buildVerifyLimit(collection, { max?, windowMinutes?, store? })`, `verifyLimitKey(collection, id)`, `clearVerifyLimits()` | `@intecion/ipal-kit` | `twoFactor.verifyLimit`: `async (req) => Response \| null` — counts an attempt of `req.user` in memory and, unless `store: 'memory'`, in `payload.kv`; a `429` with `Retry-After` past `max`. The kv key of an account's count; emptying the in-memory counts (tests). | | `turnstileSecretFromEnv(integrations)`, `TURNSTILE_SECRET_ENV` | `@intecion/ipal-kit` | `true` when the Turnstile secret in use comes from the environment because the panel field is empty (**deprecated** path; the doctor's `turnstile-env-key`); the variable's name, `'TURNSTILE_SECRET_KEY'`. | | `userMeetsRole(req, minimum)` | `@intecion/ipal-kit` | Predicate → `boolean` with `req` (`{ payload, user }`), in this order: the account belongs to a **staff collection** (`admin.user`, `access.authCollection`, `access.staffCollections`); with 2FA on it has passed the second factor (`secondFactorPassed`); it has a role ≥ `minimum`, **or** its collection has no `roles` field (the project omitted `access`). An account of any other auth collection never passes, whatever fields it has. The plugin's staff features (Site integrations, settings globals, form submissions, consent records, stats, cookie scanner, the e-mail test) use it; use it in your own endpoints. | @@ -79,7 +81,7 @@ Admin panel components from `@intecion/ipal-kit/admin` — the project does NOT | `buildRolesField(defaultRole?, { firstUserAdmin? })` | `@intecion/ipal-kit` | The `roles` select field the plugin injects (only admins set roles; `firstUserAdmin` default `true` = the account made on "Create first user" gets `admin`). The plugin wires it itself — use it only for an auth collection the plugin does not manage. | | `injectRoles(config, accessOption)` | `@intecion/ipal-kit` | Adds `roles` to `accessOption.authCollection` in a config. The plugin calls it itself with `access` — do not call. | -**Types:** `AccountsOptions` (`accounts`: `panelRole`, `adminOnlyCreate`, `firstUserRoute`, `password`), `PasswordRuleOptions` (`{ minLength? }`), `FirstUserRouteOption` (`'panel' \| 'all' \| string[]`), `TurnstileOnConfigError` / `TurnstileOnConfigErrorOption` / `TurnstileFormKind` (`@intecion/ipal-kit/server`), `VerifyLimitOptions` (`twoFactor.verifyLimit`: `{ max?, windowMinutes?, store? }`), `RequireSetupOptions` (`twoFactor.requireSetup`), `TwoFactorResetOptions`, `TwoFactorSetupState`, `SafeBackRule` / `SafeBackContext` (`twoFactor.safeBack` as a function: `(back, { adminRoute, origin? }) => string`), `TotpViewComponent` (a view component as registered: a path or `{ path, exportName?, clientProps?, serverProps? }`), `SafeTotpViewProps` (`@intecion/ipal-kit/admin`), `Role` (`'user' \| 'editor' \| 'admin'`), `AccessOption` (the plugin's `access` option: `authCollection`, `defaultRole`, `authAccess`, `firstUserAdmin`, `staffCollections`). +**Types:** `AccountsOptions` (`accounts`: `panelRole`, `adminOnlyCreate`, `adminOnlyWrite`, `firstUserRoute`, `password`), `WriteOnlySecretOptions` (`{ boundTo?, appliesWhen? }`), `PasswordRuleOptions` (`{ minLength? }`), `FirstUserRouteOption` (`'panel' \| 'all' \| string[]`), `TurnstileOnConfigError` / `TurnstileOnConfigErrorOption` / `TurnstileFormKind` (`@intecion/ipal-kit/server`), `VerifyLimitOptions` (`twoFactor.verifyLimit`: `{ max?, windowMinutes?, store? }`), `RequireSetupOptions` (`twoFactor.requireSetup`), `TwoFactorResetOptions`, `TwoFactorSetupState`, `SafeBackRule` / `SafeBackContext` (`twoFactor.safeBack` as a function: `(back, { adminRoute, origin? }) => string`), `TotpViewComponent` (a view component as registered: a path or `{ path, exportName?, clientProps?, serverProps? }`), `SafeTotpViewProps` (`@intecion/ipal-kit/admin`), `Role` (`'user' \| 'editor' \| 'admin'`), `AccessOption` (the plugin's `access` option: `authCollection`, `defaultRole`, `authAccess`, `firstUserAdmin`, `staffCollections`). ## Accessibility — widget (`accessibility`) — details: `node_modules/@intecion/ipal-kit/docs/accessibility.md` diff --git a/reference/.agents/skills/ipal-setup/SKILL.md b/reference/.agents/skills/ipal-setup/SKILL.md index 375ac3f..8006ad5 100644 --- a/reference/.agents/skills/ipal-setup/SKILL.md +++ b/reference/.agents/skills/ipal-setup/SKILL.md @@ -249,15 +249,25 @@ the panel shows Site settings, Site integrations, Cookies, Form messages, the Fo blocked"). One entity reachable without the code: `custom.ipal.secondFactor`. - **Account rules** (`accounts`, on by default; `false` or key by key to change): the panel opens for `editor` and above (`panelRole`; an account with only `user` sees "Unauthorized", the API is not touched — give panel - users at least `editor`); only an admin creates staff accounts, also in the project's own collection - (`adminOnlyCreate`), and Payload's first-user route answers only for the panel's login collection - (`firstUserRoute`) — so **create the first account right after the first deploy**, it becomes the admin; a new - password has at least 12 characters (`password`). A customer collection with sign-up: write its own - `create: () => true`; the rules do not touch it. access.md "Account rules". + users at least `editor`); only an admin creates staff accounts, and an account is changed by an admin or by + itself — also in the project's own staff collection (`adminOnlyCreate`, `adminOnlyWrite`; a staff collection + with role values of its own gets "an account of that collection, or a plugin admin" instead, so write its + `create` / `update` / `delete` / `read` rules yourself); Payload's first-user route answers only for the + panel's login collection (`firstUserRoute`) — so **create the first account right after the first deploy**, it + becomes the admin; a new password has at least 12 characters (`password`). A customer collection with + sign-up: write its own `create: () => true`; the rules do not touch it. Do not combine + `access.firstUserAdmin: false` with a default role below the panel role (the start refuses or drops the panel + role). access.md "Account rules". +- **`serverURL`**: set it in the Payload config. Without it, behind a proxy that rewrites `Host` and sends no + `X-Forwarded-Host`, the 2FA code page is refused as "another origin" (logged once: `[ipal] 2FA: a code from + origin … was refused`). Coolify / Traefik keep `Host`, so it works there either way. - **Stored secrets:** the SMTP password and the Turnstile secret key are entered **in the panel** (Site integrations) and are write-only — the panel and the API show "a value is set". Do not add env variables for them; `TURNSTILE_SECRET_KEY` is deprecated (local test keys in `.env` still work). Read them only on the - server with the Local API. `secrets: { writeOnly: false }` turns it off. + server with the Local API. `secrets: { writeOnly: false }` turns it off. Changing the SMTP server, port or + user name in the panel asks for the password again (`secrets.reenterOnChange`); a seed with the Local API is + not asked. Tick **Require encryption** in Site integrations → E-mail sending where the mail server supports + STARTTLS (off by default; the field `smtpRequireTls` needs a migration on Postgres / SQLite). - **Forms with files** are refused while Turnstile cannot check (wrong keys, Cloudflare down); text forms are still accepted. `forms: { turnstileOnConfigError: … }` changes either. - A second auth collection (`customers`, a client zone): set `admin: { user: 'users' }` in `buildConfig`; its diff --git a/reference/.agents/skills/ipal-upgrade/SKILL.md b/reference/.agents/skills/ipal-upgrade/SKILL.md index 886f703..fc9572d 100644 --- a/reference/.agents/skills/ipal-upgrade/SKILL.md +++ b/reference/.agents/skills/ipal-upgrade/SKILL.md @@ -424,8 +424,11 @@ setup screen with "Set up two-step verification by …"; after the code it is in account → "Two-step verification: Set up." and the reset button; delete the account. **→ the release with `accounts` / `secrets` (CHANGELOG "Unreleased — hardening"; PROGRAMISTA §6, item 69) — read every point, most sites change nothing:** -1. Update the package, `pnpm install`, `pnpm ipal:skills`, `pnpm payload generate:types`. No import-map change, no - schema change, no migration (the verify count uses Payload's own `payload-kv` collection). +1. Update the package, `pnpm install`, `pnpm ipal:skills`, `pnpm payload generate:types`. No import-map change. + **One new field**: `smtpRequireTls` (a checkbox) in Site integrations — MongoDB needs nothing; **Postgres / + SQLite: `pnpm payload migrate:create`, commit, deploy the migration with the code** (deployment.md §4.3), or + Site integrations cannot be read (no e-mail, no Turnstile). The verify count uses Payload's own `payload-kv` + collection. 2. **Panel access by role.** After the first start read the log: `[ipal] N account(s) of "users" are below the role "editor" and cannot open the admin panel`. Those accounts (role `user`, or no role) now see "Unauthorized" in the panel. Give the people who work in the panel `editor`, or set @@ -436,7 +439,13 @@ account → "Two-step verification: Set up." and the reset button; delete the ac stored; the panel shows "a value is set". `grep -rn "smtpPassword\|turnstileSecretKey" src` — code that read them over REST / GraphQL as an admin, or with `overrideAccess: false`, now gets `'********'`: read them on the server with `payload.findGlobal({ slug: 'site-integrations' })`. A script that saves the whole global back - keeps the secrets (the mask means "keep"). + keeps the secrets (the mask means "keep"). **New:** a save in the panel or over the API that changes the SMTP + server, port, user name or "Require encryption" must send the password again ("Enter the password again…"); + a script that does that over REST / GraphQL sends the password with it, a seed with the Local API is not + asked. `secrets: { reenterOnChange: false }` turns it off. With the owner, consider ticking **Require + encryption** (Site integrations → E-mail sending) where the server supports STARTTLS, then send a test + e-mail. During a rolling update a page opened under the new version and saved against the OLD one stores + `********` as the password: after the deploy, check that a test e-mail goes out. 4. **`TURNSTILE_SECRET_KEY` is deprecated** (it still works). If the log says `[ipal] Deprecated: the Turnstile secret key comes from the TURNSTILE_SECRET_KEY environment variable` or `ipal-doctor --url` reports `turnstile-env-key`: with the owner, copy the key into Site integrations → Spam protection → Secret key, send a @@ -445,20 +454,35 @@ account → "Two-step verification: Set up." and the reset button; delete the ac 5. **Forms with files and Turnstile.** While Turnstile cannot check (wrong keys, Cloudflare down), a form with a File field is now refused (text forms are accepted as before). Check `ipal-doctor --url` → no `turnstile-degraded`; to keep the old behaviour: `forms: { turnstileOnConfigError: { files: 'allow' } }`. -6. **Account creation.** A project whose **own** staff collection has no `create` rule: only admins create - accounts now (before: any signed-in account). `first-register` on any auth collection other than the panel's - login collection answers `403` unless that collection allows sign-up. Wanted otherwise: write the `create` - rule, or `accounts: { adminOnlyCreate: false, firstUserRoute: 'all' }`. +6. **Account creation and changes.** A project whose **own** staff collection has no `create` / `update` / + `delete` rule gets one (before: any signed-in account of any auth collection — a customer could change a + staff password): + - the collection carries the plugin's roles (`access.authCollection`, or a `roles` select with only `user` / + `editor` / `admin`): create and delete — an admin; update — an admin or the account itself. **Check:** does + a non-admin create or edit other accounts there today? Then write the rule you want; + - the collection has **role values of its own** (`superadmin`, …) or no roles: accounts of that collection + keep working as before; accounts of other collections are refused. Nothing to do, but write your own rules + — the plugin does not know your roles. + `first-register` on any auth collection other than the panel's login collection answers `403` unless that + collection allows sign-up. `access.firstUserAdmin: false` with a default role below `editor`: the panel role + is not applied (a warning at start), or — with `accounts.panelRole` set — the start fails with the fix in the + message. Wanted otherwise: `accounts: { adminOnlyCreate: false, adminOnlyWrite: false, firstUserRoute: 'all' }`. 7. **Passwords.** New passwords of staff accounts need 12 characters; **existing shorter passwords keep working** — nobody is logged out or asked to change. A script that creates staff accounts with a short password fails with a validation error: lengthen it, or `accounts: { password: { minLength: 8 } }`. 8. **2FA attempts from another origin** get `403`. A panel or front end on **another domain** than the API that posts to `/api/verify-totp`: add it — `twoFactor: { …, sameOrigin: { origins: ['https://panel.example.com'] } }` - (or set Payload's `csrf` / `cors`). Same-domain sites change nothing. + (or set Payload's `csrf` / `cors`). A same-domain site changes nothing **when the server knows its own + address**: `serverURL` is set, or the proxy passes `Host` (Coolify / Traefik do) or `X-Forwarded-Host`. + **Check before the deploy:** is `serverURL` set? If not and the proxy rewrites `Host` (nginx's plain + `proxy_pass`), nobody can enter a 2FA code after the upgrade — set `serverURL`. After the deploy log in with + a code; if it answers "Not allowed from this origin.", the log has `[ipal] 2FA: a code from origin "…" was + refused` with the fix. 9. **Dashboard alerts.** Editors now see "An integration needs attention. Ask an administrator." instead of the - error text; accounts with only `user` see no alerts. `dashboardAlerts: { integrations: 'all' }` restores it. + error text; accounts with only `user` see no alerts. `dashboardAlerts: { integrations: 'all' }` restores it + (`'all'` checks no role and no second factor). **Check:** `pnpm exec ipal-doctor --url ` (new rules: `access-missing`, `csrf-empty`, `open-signup`, -`turnstile-degraded`, `turnstile-env-key`); as an admin `GET /api/globals/site-integrations` shows +`staff-accounts-open`, `turnstile-degraded`, `turnstile-env-key`); as an admin `GET /api/globals/site-integrations` shows `"smtpPassword":"********"`; a test e-mail and a test form still work; an editor and an admin still log in. ## 2. Inventory (no code changes)