M1: docs, agent guide, skills and changelog for the hardening items

security.md (stored secrets, own-origin 2FA attempts, stored verify count,
dashboard alerts by role), access.md (account rules: panel role, no
self-registration, passwords), turnstile.md (the deprecated env secret,
forms.turnstileOnConfigError), doctor.md (five new rules, the deep status),
AGENT.md, ipal-setup, ipal-upgrade, ipal-debug, ipal-reference (+ api.md),
ipal-doctor and their mirrors, PROGRAMISTA row 69, CHANGELOG under an unreleased
heading with "Requires project changes".

Co-Authored-By: Claude Fable 5.2 <[email protected]>
This commit is contained in:
Radosław Smoliński
2026-11-25 00:39:23 +01:00
co-authored by Claude Fable 5.2
parent f7296edc71
commit 83356ab4ed
22 changed files with 479 additions and 33 deletions
+84
View File
@@ -224,8 +224,92 @@ applyGlobalOverrides(globals, { notifications: { … } }) // the same logic as
Types: `AccessOption`, `Role`, `GlobalOverride`, `GlobalOverrides`, `IpalGlobalSlug`.
## Account rules (`accounts`)
Rules for the accounts of the staff collection. All on by default; each has its own switch, and
`ipalKit({ accounts: false })` turns them all off.
```ts
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: { firstUserRoute: 'all' }, // Payload's first-user route for every empty auth collection
// accounts: { firstUserRoute: ['users', 'partners'] },
// accounts: { password: { minLength: 16 } }, // or password: false
// accounts: false, // none of the rules
})
```
### Who may open the panel (`accounts.panelRole`, default `'editor'`)
The lowest role, `user`, is what a new account gets (`access.defaultRole`) and has no business in the panel. The
panel opens for `editor` and above: it is Payload's `access.admin` on the collection that carries the roles. An
account that holds only `user` (or no role) logs in and sees Payload's "Unauthorized" screen. **The API is not
touched** — such an account still gets over REST / GraphQL what its role allows. The rule looks at the role, not
at the second factor, so the 2FA screens stay reachable.
- **What an existing site sees on the first start:** the log line `[ipal] N account(s) of "users" are below the
role "editor" and cannot open the admin panel` — give those people `editor`, or set `panelRole: 'user'`. When
**no** account has the role it is an error (`NOBODY can open the admin panel`): give one account the role with
a script (`payload.update`, Local API) or set `accounts: { panelRole: false }` and redeploy.
- `'admin'` = admins only; `'user'` or `false` = everyone, as before. Needs `access` (the roles). Your own
`access.admin` on the collection, or `access.authAccess.admin`, wins. Building blocks: `panelAccess(role)`,
`applyPanelRole`, `resolvePanelRole`, `countBelowPanelRole`, `DEFAULT_PANEL_ROLE`.
- **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`)
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.
| | 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`) |
| `POST /api/<slug>/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.
- `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.
- **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`.
- **Check:** `curl -X POST <site>/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`.
### Passwords (`accounts.password`, default 12 characters)
When a password is **set** on a staff collection — a new account, the first-user screen, a change, a reset by
e-mail; in the panel, over the API and through the Local API — it must have at least 12 characters and must not
be the account's own e-mail address (Payload's own rule is 3 characters). **Existing passwords are never
checked:** an account with a shorter one keeps logging in, and meets the rule the next time its password is
changed. The message is in the panel's language, English or Polish ("The password must have at least 12
characters."; texts `passwordTooShort`, `passwordIsEmail` in `i18n.translations.<lang>.ipal`).
- `password: { minLength: 16 }`; `password: false` = Payload's rule. Visitor collections are not touched.
- 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.
- Building blocks: `checkPassword`, `buildPasswordRuleHook`, `applyPasswordRule`, `resolvePasswordRule`,
`DEFAULT_PASSWORD_MIN_LENGTH`.
- **Check:** create an account with an 11-character password → "The password must have at least 12 characters.".
## Turn off, override, extend
- **Account rules:** `accounts: false`, or one by one — `panelRole`, `adminOnlyCreate`, `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),