Merge local main (1.17.2) into security-a-118
Conflicts resolved by keeping both sides: lockedAnswer + sign-in rules in plugin.ts and switches.ts, IPv6 grouping in the mail service's new per-visitor address count, both built-site specs in e2e:built, docs and skills (reference copies synced). The lockedAnswer suite and the sign-in-answers spec now reach Payload's lock the 1.18.0 way: a spray from 50 IPs, one failure each (one IP alone gets 429 after five). Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
@@ -421,6 +421,40 @@ Real panel protection:
|
||||
`/admin → /its` is a layer (it filters out dumb bots), not a lock. Treat it as an
|
||||
addition to real safeguards, not a replacement for them.
|
||||
|
||||
## Panel actions only from the site's own origin (`adminSameOrigin`, 1.17.2)
|
||||
|
||||
The plugin's panel actions act with the panel's login cookie and read their body whatever its `Content-Type`
|
||||
says: `POST /api/iapl/mail-relay/connect` and `/disconnect` (the mail service), `/api/ipal/test-email`,
|
||||
`/api/ipal/cookie-scan`, `/api/ipal/cookie-approval`, `/api/ipal/cookie-crawl`. A `text/plain` POST needs no CORS
|
||||
preflight, a page on a sibling subdomain is "same site" (the browser sends the `SameSite=Lax` cookie), and
|
||||
Payload's own CSRF list is empty unless `serverURL` or `csrf` is set. So before 1.17.2 such a page could make a
|
||||
signed-in administrator disconnect the mail service, send test mails, run scans and crawls, or approve every
|
||||
waiting cookie. Now each of them refuses (`403`, before anything is read) a request a browser marks as coming
|
||||
from elsewhere — the same rule as the 2FA endpoints: the `Origin` header, else `Sec-Fetch-Site`. Own origins: the
|
||||
host the request came in on (`Host`, `X-Forwarded-Host`), `serverURL`, Payload's `csrf` and `cors` lists, and
|
||||
`adminSameOrigin.origins`. A request with neither header (a script, `curl`, a server) passes: it rides on nobody's
|
||||
cookie. The panel's own buttons are on the site's origin and are not affected. A project's own endpoint on one of
|
||||
these paths is left as it is. The 2FA endpoints keep their own switch (`twoFactor.sameOrigin`).
|
||||
|
||||
```ts
|
||||
iapl({
|
||||
// adminSameOrigin: { origins: ['https://panel.example.com'] }, // the panel served from another origin
|
||||
// adminSameOrigin: false, // no check (as before 1.17.2)
|
||||
})
|
||||
```
|
||||
|
||||
- **Behind a proxy that rewrites `Host`** and sends no `X-Forwarded-Host`, without `serverURL`, the site's own
|
||||
panel buttons are refused. It is not silent: the first refusal of each origin is logged
|
||||
(`[iapl] a panel action from origin "…" was refused … pass iapl({ adminSameOrigin: { origins: [...] } })`), and
|
||||
`iapl-doctor` warns when the running config has neither `serverURL` nor `csrf` (`csrf-empty`). Set
|
||||
`serverURL: process.env.NEXT_PUBLIC_SERVER_URL`.
|
||||
- **Any other value** than `true`, `false` or an object with `origins` (a list of strings) stops the start.
|
||||
- **Building blocks:** `requireOwnOrigin(endpoint, origins?)` for an endpoint of your own,
|
||||
`guardAdminEndpoints(config, projectEndpoints, option)`, `ADMIN_POST_ENDPOINTS` (the list), and the 2FA ones:
|
||||
`requestFromOwnOrigin`, `ownOrigins`, `reportRefusedOrigin(req, origins?, { what, option, docs }?)`.
|
||||
- **Check:** `curl -X POST <site>/api/ipal/test-email -H 'Origin: https://other.example' -H 'Content-Type: text/plain'
|
||||
-b <admin cookies> -d '{"to":"a@example.com"}'` → `403`; "Send test e-mail" in the panel still works.
|
||||
|
||||
## 2FA (TOTP) — ENFORCED for every user
|
||||
|
||||
The plugin enforces two-factor authentication (TOTP) for ALL panel users —
|
||||
@@ -1199,6 +1233,51 @@ a root endpoint to the config and the check names it as "not judged".
|
||||
**In the plugin repository:** `pnpm routes:check` (`--update` after a Payload upgrade) on the reference site, also
|
||||
the first step of `pnpm e2e:built`; the test fixtures are switched off for it.
|
||||
|
||||
## Payload's job queue (`jobsRunAccess`, 1.17.2)
|
||||
|
||||
Payload runs its queue over HTTP at `GET /api/payload-jobs/run` and `/api/payload-jobs/handle-schedules`, checked by
|
||||
`jobs.access.run`. Payload's default is **any signed-in account of any auth collection** — a shop's customer could
|
||||
run the queue whenever they like. Since 1.17.2, when the project writes **no** `jobs.access.run`, iapl sets: an
|
||||
**admin signed in with the second factor** (an admin's API key counts), or **`Authorization: Bearer <CRON_SECRET>`**
|
||||
(16+ characters, compared in constant time). It is set even when the config has no `jobs` (Payload turns the queue on
|
||||
by itself for scheduled publishing). A route that does not exist (no tasks, no workflows) stays 404.
|
||||
|
||||
**A project with jobs keeps its cron working** — check which of these it uses:
|
||||
- jobs run **in-process** (`jobs.autoRun`, `pnpm payload jobs:run`, `payload.jobs.run()` in code): nothing changes;
|
||||
- a **Coolify scheduled task** (or any cron) that calls the run route: set `CRON_SECRET` in the app's environment and
|
||||
in the task, and send the header —
|
||||
`curl -fsS -H "Authorization: Bearer $CRON_SECRET" "$NEXT_PUBLIC_SERVER_URL/api/payload-jobs/run"`;
|
||||
- a cron that signs in with an **admin's API key**: works as before; with a **non-admin** account's key: switch to
|
||||
`CRON_SECRET`, or write your own rule;
|
||||
- the project's **own** `jobs.access.run`: always wins, nothing changes.
|
||||
At start, when the queue is on, the rule is iapl's and `CRON_SECRET` is missing or short, the log says so in one
|
||||
line. Overrides: `iapl({ jobsRunAccess: false })` keeps Payload's default; `{ secretVar: 'MY_VAR' }` reads another
|
||||
variable; `jobsRunAccess()` is exported to reuse in a rule of your own. Verify: without the header
|
||||
`/api/payload-jobs/run` answers 401, with it 200 (the closed-doors spec does both on the built reference site).
|
||||
|
||||
## Visitor accounts (customers, members) and Payload's default write rules
|
||||
|
||||
Payload fills every missing access rule with **"any signed-in account"** — an account of a visitor login collection
|
||||
included. The plugin narrows its own collections and globals and the staff accounts; **your** collections and
|
||||
globals are yours to rule. On a site that has (or may get) a visitor login collection, give every collection
|
||||
`create` / `update` / `delete` and every global `update` a rule of its own — the reference site and every new site
|
||||
from `iapl create` do (`adminOrEditor`, since 1.17.2). `iapl-doctor --url` (deep) lists what such an account may
|
||||
write (`visitor-writes`, warning), checked by behaviour: it asks every rule with a stand-in visitor account. Payload's
|
||||
own `payload-locked-documents` (who edits which document) also runs on Payload's default and is listed there; a
|
||||
plugin-wide default for it is planned for 2.0. Verify: the doctor shows no `visitor-writes` finding, and the
|
||||
closed-doors spec's customer gets 403 on every write door.
|
||||
|
||||
## Access callbacks (`cookieScanner.access`, the doctor's `access`)
|
||||
|
||||
A project's callback says who may use the cookie scanner's endpoints or read the doctor's status. Today any truthy
|
||||
answer lets the request in: `({ req }) => req.user` returns an account object and passes, and so does a function
|
||||
that returns `'no'` or `{}`. **From the next minor version (1.19.0) only `true` allows** — like
|
||||
`twoFactor.requireSetup.resetAccess` already does. Since 1.18.0 the first answer that is not a boolean is reported
|
||||
once per option in the server log:
|
||||
`[iapl] cookieScanner.access returned an object, not true or false. It is still read as allowed; …`.
|
||||
Return a boolean: `({ req }) => Boolean(req.user)`, `({ req }) => isAdmin(req.user, req.payload)`. One function reads
|
||||
every answer: `accessAllowed(option, answer)` (exported). The second factor is checked before the callback, as before.
|
||||
|
||||
## Turn off, override, extend
|
||||
|
||||
- **Stored secrets:** `secrets: { writeOnly: false }`, `secrets: { reenterOnChange: false }`; `writeOnlySecret` /
|
||||
|
||||
Reference in New Issue
Block a user