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
+69 -2
View File
@@ -546,8 +546,24 @@ counts attempts per account on `POST /api/verify-totp`: by default the **sixth a
right or wrong — is refused with `429` and `Retry-After`, and a line goes to the log. Only a session that already
passed the password reaches the endpoint, so nobody without the password can lock an account's owner out; someone
who has the password can delay the owner's login by ten minutes at a time (and that shows in the log). Counted in
memory per server instance. `verifyLimit: { max: 10, windowMinutes: 5 }` changes it, `verifyLimit: false` turns
it off (a limiter in front of the site).
memory per server instance **and in the database** (Payload's key-value store, `payload.kv` — the `payload-kv`
collection Payload itself adds; no new collection): a restart, a redeploy or a second instance does not hand out
new attempts. The higher of the two counts decides; when the database part fails, the memory count still does
(there is no "allow when the store fails" path). `verifyLimit: { max: 10, windowMinutes: 5 }` changes it,
`{ store: 'memory' }` keeps the count in this instance only, `verifyLimit: false` turns it off (a limiter in
front of the site).
**Verify and setup attempts only from the site's own origin** (`twoFactor.sameOrigin`). The limit counts every
attempt of an account, so a page that can make the browser send the account's login cookie could burn the
owner's attempts and lock them out — no password needed. A sibling subdomain is such a page (`SameSite=Lax` does
not stop it, and Payload's own `csrf` list is empty unless `serverURL` or `csrf` is set). So
`POST /api/verify-totp` and `POST /api/setup-totp` refuse (`403`) a request that the browser marks as coming from
elsewhere — the `Origin` header, else `Sec-Fetch-Site` — **before it is counted**. Own origins: the host the
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
`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
of other auth collections: 2FA is about one collection; such an account is not staff unless its collection is in
@@ -901,8 +917,59 @@ 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`)
`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 —
[turnstile.md](./turnstile.md)). They are **write-only**:
| Who reads | Gets |
|---|---|
| REST (`GET /api/globals/site-integrations`), GraphQL, the panel's form, versions — anything through access control, an admin included | `'********'` when a value is stored (`SECRET_MASK`), the empty value when none is |
| Server code through the Local API with access control off (the default of `payload.findGlobal`) — the mail adapter, the Turnstile check, your own server code | the real value |
| The Local API **with** access control (`overrideAccess: false` and a `user`) | `'********'` |
| A save sends | Result |
|---|---|
| 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 |
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.
- **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
must read it on the server with the Local API instead.
- **Off:** `ipalKit({ secrets: { writeOnly: false } })` — the value is returned to whoever may read the global.
- **Your own secret fields:** `writeOnlySecret({ name: 'apiToken', type: 'text', admin: { components: { Field:
'@intecion/ipal-kit/admin#MaskedField' } } })`, or `writeOnlySecrets(fields, ['apiToken'])` for fields inside
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.
- **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.
## Dashboard alerts by role (`dashboardAlerts`)
The plugin's dashboard alerts read data that only some roles may read (with access control off, on the server),
so each decides who sees it. **Integration alerts** (Site integrations is admin-only): an admin sees what is
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
(`details`, `audience`).
## Turn off, override, extend
- **Stored secrets:** `secrets: { writeOnly: false }`; `writeOnlySecret` / `writeOnlySecrets` 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.
- **Dashboard alerts:** `dashboardAlerts: { integrations, cookies }`.
- **Verify limit:** `twoFactor.verifyLimit: { max, windowMinutes }`, or `false`.
- **`back` link check of the 2FA screens:** `twoFactor.safeBack: false`, or a function as your own rule;
`safeAdminBack`, `wrapTotpViews`, `copyViews`, `changedViewKeys`, `SAFE_TOTP_VIEW`, `SafeTotpView` are exported.