Security review round 2: no exception by name, staff list fails closed, verify limit
R2-1: the sweep skipped every collection whose slug starts with payload-,
so a plugin's payload-... collection added after ipalKit was never guarded.
There is no exception by name or prefix now: every collection and global
is guarded, Payload's own included, and the job queue's run / queue /
cancel rules too.
R2-2: role predicates called without a source fail closed where the staff
collections are not known (browser bundle, middleware, edge): nobody is
staff. They accept req.payload, a config (also the client config) or
{ staffCollections } as the source.
R2-3: the staff list is filed per config / Payload instance; a call without
a source gets only what every config in the process calls staff.
R2-4: payload.config is watched on the instance, so a config swapped in by
a dev reload is guarded before any request or Local API call.
R2-5: verify attempts are limited per account (default 5 in 10 minutes,
twoFactor.verifyLimit), counted in memory, never skipped.
R2-6: a user object without collection owes the second factor; endpoints
the 2FA package may add on collections or globals are guarded too; a
warning names staff collections that 2FA does not cover; docs state what
is not covered, fix the one-argument examples and the doctor example.
HTTP tests for each on payload-2fa beta.7, run on SQLite, Postgres and
MongoDB (test adapter added).
Co-Authored-By: Claude Fable 5.2 <[email protected]>
This commit is contained in:
co-authored by
Claude Fable 5.2
parent
32faaa5e30
commit
c56f0d41b8
+32
-5
@@ -404,13 +404,21 @@ therefore read and changed them over the API.** Since the release after 1.16.3 i
|
||||
|---|---|
|
||||
| every collection and global in the config when ipalKit finishes | `access` wrapped with `requireSecondFactor` |
|
||||
| collections and globals added by plugins listed **after** ipalKit | wrapped in ipalKit's `onInit`; the log line `[ipal] 2FA also enforced on entities added after ipalKit: …` names them |
|
||||
| the same after a dev hot reload, or when Payload runs with `disableOnInit` | an auth strategy that authenticates nobody (`ipal-second-factor-guard` on the 2FA collection) runs at the start of every request and guards the live config once |
|
||||
| the same after a dev hot reload, or when Payload runs with `disableOnInit` | the instance's `config` is watched, so a swapped config is guarded the moment Payload assigns it (before any request or Local API call); as a second line an auth strategy that authenticates nobody (`ipal-second-factor-guard` on the 2FA collection) does the same at the start of every request |
|
||||
| the plugin's endpoints (`/api/ipal/test-email`, `cookie-scan`, `cookie-approval`, `cookie-crawl`, the `access` option of `/api/ipal/doctor`) | `userMeetsRole` and `secondFactorPassed` |
|
||||
| the 2FA package's own endpoints (`/api/setup-totp`, `/api/verify-totp`, `/api/remove-totp`, `/api/admin/reset-user-totp`, `/api/admin/remove-user-totp`, any a later version adds) | accounts of the 2FA collection only; everything except setup and verify also needs the second factor ("The 2FA package's endpoints" below) |
|
||||
|
||||
The order of the project's `plugins` array does not matter. Payload's own collections (`payload-preferences`,
|
||||
`payload-locked-documents`, …) and `access.admin` (may this account open the panel) are left alone: the code is
|
||||
entered inside the panel.
|
||||
The order of the project's `plugins` array does not matter, and **there is no exception by name**: Payload's own
|
||||
collections (in 3.94.1: `payload-preferences`, `payload-locked-documents`, `payload-migrations`,
|
||||
`payload-query-presets`, `payload-folders`, `payload-jobs`, `payload-kv`, the global `payload-jobs-stats`) are
|
||||
guarded like every other, and so is whatever a later Payload version or a plugin adds under any slug
|
||||
(`payload-mcp-api-keys`, …). The job queue's own rules (`jobs.access.run / queue / cancel`) are guarded too.
|
||||
Only `access.admin` (may this account open the panel) is left alone: the code is entered inside the panel, and
|
||||
the verify and setup screens are rendered from the session, not from any collection.
|
||||
|
||||
A session that still owes its code is refused **everything**, also what anonymous visitors may read (Site
|
||||
settings, Notifications, the Cookie banner, forms): for that account the answer is `403` until the code is
|
||||
entered. The public site is not affected — it reads on the server.
|
||||
|
||||
An account of the 2FA collection passes when it logged in with **password and code**, or uses an **API key**
|
||||
(`auth.useAPIKey`), or has **not set TOTP up yet** (the setup screen needs that; the package behaves the same).
|
||||
@@ -425,6 +433,24 @@ the Local API with `overrideAccess: true` (the default) are not affected.
|
||||
> leave an invited account waiting. `ipal-doctor --url` reports the number of accounts without 2FA
|
||||
> (`2fa`, deep check); it must be 0.
|
||||
|
||||
**Verify attempts are limited** (`twoFactor.verifyLimit`). The package checks the code and never counts tries;
|
||||
a six-digit code has about three right answers in a million, so whoever held the password could guess. ipalKit
|
||||
counts attempts per account on `POST /api/verify-totp`: by default the **sixth attempt within 10 minutes** —
|
||||
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).
|
||||
|
||||
**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
|
||||
`access.staffCollections`, and then it is staff **without** a second factor (warning in the log at start).
|
||||
(3) API keys. (4) An account that has not set TOTP up yet. (5) Entities the project opted out (below).
|
||||
(6) `access.admin`. (7) Endpoints that are not the plugin's or the 2FA package's: your own endpoints and other
|
||||
plugins' endpoints check whatever they check — add `secondFactorPassed(req)` to yours. (8) Server code using the
|
||||
Local API with `overrideAccess: true`. Nothing is skipped by slug, name or prefix, and a user object the check
|
||||
cannot read is refused.
|
||||
|
||||
**Per-entity opt-out.** A collection or global that may be reached with the password alone (a project decision,
|
||||
e.g. a health record the panel reads before the code is entered), operation by operation:
|
||||
|
||||
@@ -466,7 +492,7 @@ handler: async (req) => {
|
||||
// or: if (!userMeetsRole(req, 'editor')) … — it includes the second-factor check
|
||||
}
|
||||
// an access function (collections and globals in the config are wrapped for you; this is for the rest)
|
||||
access: { read: requireSecondFactor(({ req }) => isAdmin(req.user)) }
|
||||
access: { read: requireSecondFactor(({ req }) => isAdmin(req.user, req.payload)) }
|
||||
```
|
||||
|
||||
**Fails closed.** At startup ipalKit checks that the injected 2FA plugin added what the check reads (the
|
||||
@@ -630,6 +656,7 @@ size while reading, content signature, container and macro checks, an optional `
|
||||
|
||||
## Turn off, override, extend
|
||||
|
||||
- **Verify limit:** `twoFactor.verifyLimit: { max, windowMinutes }`, or `false`.
|
||||
- **2FA check:** per entity `custom.ipal.secondFactor` / `custom.totp.disableAccessWrapper` (one operation or
|
||||
all); `twoFactor.guard: false` turns ipal-kit's own second-factor check off everywhere (not recommended);
|
||||
`requireSecondFactor` / `secondFactorPassed` are exported for your own access functions and endpoints.
|
||||
|
||||
Reference in New Issue
Block a user