Security audit fixes: docs (security.md, content.md, i18n.md, AGENT.md, skills), changelog, static-rule judgments for the merged doctor and 2FA code, hook mark for the account-rule tests

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
Radosław Smoliński
2026-12-01 17:02:20 +01:00
co-authored by Claude Opus 5.5
parent e9f9947eb7
commit e5964d4e05
23 changed files with 283 additions and 47 deletions
+89 -17
View File
@@ -287,12 +287,23 @@ With a custom `adminRoute` (e.g. `/its`), use that path in `source`.
### Collecting reports
`createCspReportRoute({ onReport?, maxBytes = 16384 })` — a `POST` handler for `reportUri`. It accepts
both formats (`application/csp-report` from `report-uri`, `application/reports+json` from `report-to`),
caps the body (a larger one → `413`; since 1.17.1 the stream is read only up to `maxBytes`, also when the browser
sends no `content-length`), always answers `204`, and by default logs one `console.warn` line per violation:
`[csp] report script-src-elem blocked=https://x.example/a.js page=https://site/pl`. Read them in the
Coolify app's **Logs**. Plug `onReport` into `payload.logger`, Sentry or a database for more.
`createCspReportRoute({ onReport?, maxBytes = 16384, maxReports = 10, rateLimit })` — a `POST` handler for
`reportUri`. It accepts both formats (`application/csp-report` from `report-uri`, `application/reports+json` from
`report-to`), caps the body (a larger one → `413`; since 1.17.1 the stream is read only up to `maxBytes`, also when
the browser sends no `content-length`), always answers `204`, and by default logs one `console.warn` line per
violation: `[csp] report script-src-elem blocked=https://x.example page=/pl src=https://site/_next/a.js:3`. Read them
in the Coolify app's **Logs**. Plug `onReport` into `payload.logger`, Sentry or a database for more.
**What the default line holds (1.18.0, security audit F1).** Anyone can post a report, so its strings never reach the
log as sent: the blocked resource is reduced to its origin (`inline`, `eval` stay), the page to its path (no query — it
may hold an e-mail address), the script to origin and path; control characters and line separators are removed and
every value is cut at `CSP_LOG_VALUE_MAX` (128) — a report cannot write a forged line of its own. One request handles
at most `maxReports` (10) violations, and one client (`clientIp`, IPv6 per /64) at most 60 requests a minute
(`rateLimit: { max, windowMs }`; `false` = no limit); over it the route answers `204` and handles nothing. A project's
own `onReport` still gets every value exactly as the browser sent it — escape it before you log it, or call
`cspLogLine(violation)` for the plugin's line. **What changes for an existing site:** the log lines show origins and
paths instead of full URLs (a log parser that read full URLs must adapt), and at most 10 violations per request reach
`onReport` (was 50: `maxReports: 50` keeps it).
```ts
// app/api/csp-report/route.ts (a fixed route wins over Payload's /api/[...slug])
@@ -1336,9 +1347,60 @@ globals are yours to rule. On a site that has (or may get) a visitor login colle
`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.
own `payload-locked-documents` (who edits which document) is for staff accounts only since 1.18.0 (`lockedDocuments`,
"Lists and sorting" below). Verify: the doctor shows no `visitor-writes` finding, and the closed-doors spec's customer
gets 403 on every write door.
## Lists and sorting (`listLimit`, `refuseOperatorSort`, `lockedDocuments`, 1.18.0)
Three defaults for what a caller from outside (REST, GraphQL) may ask of a collection. The Local API — the frontend,
seeds, the project's own code (`req.payloadAPI === 'local'`) — is never touched.
- **`listLimit` (security audit F4).** A list (`find`, versions, distinct values) asked by a caller that is not staff
gets at most **100** documents per request; `pagination=false` and `limit=0` become one page of 100. Before, one
anonymous `GET /api/posts?limit=100000&depth=10` read a whole collection with its relations. Staff accounts (any
role) are not capped — the panel asks for at most 100 per page itself. Adapt: `listLimit: { max: 250 }`,
`{ exclude: ['products'] }` (that collection as Payload has it), `{ staff: true }` (staff capped too);
`listLimit: false` = Payload's behaviour. **What changes for an existing site:** a client-side script that reads more
than 100 documents anonymously over REST or GraphQL now gets the first 100 and `hasNextPage: true` — page through
(`page=2`) or raise `max`.
- **`refuseOperatorSort` (security audit F5).** A `sort` that names a database operator (`?sort=$where`, `-$natural`,
`title.$ne`) answers **400** "This sort field is not allowed." for everyone, staff too — before, MongoDB got it and
the request ended in a 500 with a stack trace in the log. The refusal is logged as one `info` line
(`RefusedSortError`; `loggingLevels: { RefusedSortError: false }` in the Payload config hides it). A field name sorts
as before. `refuseOperatorSort: false` = Payload's behaviour. Reported upstream to Payload (the MongoDB adapter).
- **`lockedDocuments`.** Payload's document locks ("who edits what", `payload-locked-documents`) run on Payload's
default — any signed-in account — so a visitor account (a shop's customer) could read who edits which document and
write or delete locks. Since 1.18.0 they are for staff accounts only, with the second factor when 2FA is on
(`staffOnlyLocks`). The panel works as before. Payload adds this collection after every plugin has run, so the
rule is set on the live config (at start and after a dev reload). Your own rule per operation:
`lockedDocuments: { access: { read: myRule } }` (the others stay staff only); `lockedDocuments: false` = Payload's
default.
Both hooks are added to every collection in the config when iapl runs — the project's, the plugin's and those of
plugins listed before iapl. A collection a plugin listed **after** iapl adds has neither: put
`buildQueryGuardHook({ listLimit, refuseOperatorSort })` into its `hooks.beforeOperation`, or list iapl last.
Exported: `buildQueryGuardHook`, `applyQueryGuard`, `capListLimit`, `isOperatorSort`, `isStaffRequest`,
`isQueryGuardHook` / `QUERY_GUARD_MARK` (to tell the hook apart when you count a collection's hooks),
`RefusedSortError`, `DEFAULT_LIST_LIMIT`, `applyLockedDocumentsAccess`, `staffOnlyLocks`, `LOCKED_DOCUMENTS_SLUG`.
Verify: `curl -s 'https://<domain>/api/pages?limit=100000' | jq .limit` → `100`;
`curl -s -o /dev/null -w '%{http_code}' 'https://<domain>/api/pages?sort=%24where'` → `400`; the closed-doors spec's
customer gets 403 on `/api/payload-locked-documents`; `iapl-doctor --url … --only live-probes` passes
`unbounded-list` and `sort-operator`.
## Addresses rendered into `href` (`buildUrlField`, 1.18.0)
A text field whose value goes into `<a href>` (a social profile, a website, a map link) must refuse `javascript:`,
`data:` and `vbscript:` — an editor's link would otherwise run script as whoever clicks it on the public site, an
admin included (security audit F2: the reference site's Company → Profiles was a plain text field).
`buildUrlField({ name?, label?, required?, schemes?, description?, overrides? })` is that field: `https://` and
`http://` pass, plus the kinds you list in `schemes` (`mailto`, `tel`, `sms`, `hash`, `relative`); protocol-relative
`//host` never passes. `isAllowedUrl(value, schemes)` is the same check for your own code. Render the stored value
through `safeHref()` as well — an import, a seed or an older version may hold anything. The reference site and every
new site from `iapl create` use both (`src/globals/Company.ts`, `Footer.tsx`, the `sameAs` of the JSON-LD).
**For an existing site:** nothing changes by itself; replace `{ name: 'url', type: 'text' }` in your own globals with
`buildUrlField()` (no schema change: still a text column) and wrap the render in `safeHref`. Verify: entering
`javascript:alert(1)` in the field shows "Enter a full address" and nothing is saved.
## Access callbacks (`cookieScanner.access`, the doctor's `access`)
@@ -1359,16 +1421,16 @@ and ASVS 5.0 name the categories. Each row says where IAPL covers it and which s
| # | Class | Seen in | IAPL covers it with | Checked by |
|---|---|---|---|---|
| 1 | Denial of service (body size, ReDoS, Server Actions, image optimizer, unbounded lists, GraphQL) | 27 core + 46 deps; Next GHSA-p3m5-59mp-jv5r (Server Actions, Oct 2026) | body caps on every public plugin route (`readCappedBody`), MCP batch cap, rate limits; Payload `maxDepth`. **Lists are not capped** (audit F4) | probes `body-size`, `unbounded-list`; per-class tests |
| 1 | Denial of service (body size, ReDoS, Server Actions, image optimizer, unbounded lists, GraphQL) | 27 core + 46 deps; Next GHSA-p3m5-59mp-jv5r (Server Actions, Oct 2026) | body caps on every public plugin route (`readCappedBody`), MCP batch cap, rate limits; Payload `maxDepth`; public lists capped at 100 (`listLimit`, audit F4, 1.18.0) | probes `body-size`, `unbounded-list`; per-class tests |
| 2 | Access control (REST / GraphQL / Local API `overrideAccess`, drafts, versions, field access) | 17 Payload (A01) | account rules, `readPublished`, 2FA wrapper, jobs rule, `visitor-writes` | closed-doors spec, `routes:check`, probes `rest-where`, `graphql`; rules `code-override-access`, `code-local-api-user` |
| 3 | Cache poisoning and cross-user leaks (ISR, RSC, CDN, host headers) | 18 Next (CVE-2024-46982 …) | no host header read for URLs (`NEXT_PUBLIC_SERVER_URL`), `no-store` on personal answers. **Markdown negotiation at the HTML URL** (audit F3) | probes `host-header`, `markdown-vary`, `rsc-vary` |
| 3 | Cache poisoning and cross-user leaks (ISR, RSC, CDN, host headers) | 18 Next (CVE-2024-46982 …) | no host header read for URLs (`NEXT_PUBLIC_SERVER_URL`), `no-store` on personal answers; the negotiated Markdown at an HTML URL is `private, no-store` + `Vary: Accept` (audit F3, 1.18.0) | probes `host-header`, `markdown-vary`, `rsc-vary` |
| 4 | Remote code execution (RSC Flight, `use cache`, image optimizer + libvips/librsvg) | 10 core (React2Shell CVE-2025-55182, GHSA-2464-fhr4-w9xw, GHSA-673q-mjm6-r5xr, GHSA-xqc2-xf4c-x3h3) | minimum Next / sharp in AGENT.md §4; no `eval` | `deps-audit`, `code-eval` |
| 5 | Information disclosure (errors, source maps, secrets in bundles and files) | 14 core | no stack traces in plugin answers, write-only secrets, no manifest in `.next/static` | probes `error-leak`, `bundle-secrets`, `secret-files`; rule `code-public-secret` |
| 6 | SSRF (Server Actions Host header, middleware redirects, image optimizer, URL uploads) | 9 core (CVE-2024-34351, CVE-2025-57822) | `buildImagesConfig` (listed hosts only), `safeFetch` for brand images, the crawl only of the site's own URL | probe `image-optimizer`; rule `code-ssrf` |
| 7 | Authentication and session (JWT after logout, fixation, 2FA bypass, enumeration, CSRF) | 8 + 3 (CVE-2025-4643, CVE-2025-4644) | 2FA enforced and wrapped around plugin entities, own-origin checks, `serverURL` for Payload's CSRF list, verify limit | spec "attack probes with a session" (CSRF, cookie flags), 2FA specs |
| 8 | XSS (rich text, links, JSON-LD, SVG uploads, `dangerouslySetInnerHTML`) | 7 core + 39 deps (dompurify, sanitize-html) | `RenderRichText` / `safeHref` drop `javascript:`, `JsonLdGraph` escapes `<`, upload CSP `sandbox`, CSP | per-class tests; rule `code-inner-html`; `config-dangerous` (`dangerouslyAllowSVG`) |
| 8 | XSS (rich text, links, JSON-LD, SVG uploads, `dangerouslySetInnerHTML`) | 7 core + 39 deps (dompurify, sanitize-html) | `RenderRichText` / `safeHref` drop `javascript:`, `buildUrlField` refuses it on save (audit F2), `JsonLdGraph` escapes `<`, upload CSP `sandbox`, CSP | per-class tests; rule `code-inner-html`; `config-dangerous` (`dangerouslyAllowSVG`) |
| 9 | Middleware / proxy bypass (`x-middleware-subrequest`, path normalisation) | 7 Next (CVE-2025-29927) | the plugin makes NO access decision in the proxy (locale and CSP nonce only); matcher ends at `/` | probe `middleware-subrequest`; doctor `proxy-matcher` |
| 10 | Injection (NoSQL operators, `$where`, SQL in raw queries, CRLF, logs) | 5 Payload + 16 deps (mongoose CVE-2024-53900, CVE-2025-23061) | no `where` from request input in plugin routes; typed values in queries. **Operator names in `sort`** reach MongoDB (audit F5); **CSP reports write raw text into the log** (audit F1) | probes `login-operators`, `sort-operator`; rule `code-raw-where`; per-class tests |
| 10 | Injection (NoSQL operators, `$where`, SQL in raw queries, CRLF, logs) | 5 Payload + 16 deps (mongoose CVE-2024-53900, CVE-2025-23061) | no `where` from request input in plugin routes; typed values in queries; operator names in `sort` refused (`refuseOperatorSort`, audit F5); CSP report log lines normalised and capped (audit F1); both 1.18.0 | probes `login-operators`, `sort-operator`; rule `code-raw-where`; per-class tests |
| 11 | Supply chain (npm worms: Shai-Hulud 2025, chalk/debug 2025, Mini Shai-Hulud 2026) | 13 incidents | exact pins of the plugin's own deps, lockfile, `pnpm.overrides` advice (AGENT.md §4 item 12) | `deps-audit` (doctor), `pnpm security:gate` |
| 12 | Open redirect | 1 Payload | `safeAdminBack`, `adminPathFromReferer`, locale redirect keeps the host | probe `open-redirect`; rule `code-open-redirect` |
| 13 | Security headers and CSP | — (misconfiguration, A02) | `buildSecurityHeaders`, `buildCsp`, `withSecurityConfig` | probe `headers-everywhere`; doctor `security-headers`, `csp`, `config-dangerous` |
@@ -1410,9 +1472,12 @@ never "closed"): `secret-files`, `bundle-secrets` (with the spec: also the site'
`error-leak`, `unbounded-list`, `image-optimizer`, `headers-everywhere`, `methods`, `body-size` (spec only: 8 MB
bodies). The spec adds, with a signed-in editor: the session cookie is `HttpOnly` and `SameSite`, and from another
origin the same cookie neither reads `/api/users/me`, writes a global, nor runs a GraphQL mutation. A probe tied to an
open audit finding carries `finding` and is expected to fail (`test.fail`) until the fix lands. Your own probe: an
object `{ id, class, title, live, run(ctx) }` in the template's `EXTRA`. Verify: run the doctor with `--url` against
`pnpm start` of a fresh starter site — no `live-probes` finding except the open audit findings.
open audit finding carries `finding` and is expected to fail (`test.fail`) until the fix lands; every finding of the
2026-12 audit is fixed in 1.18.0, so none carries it now. Your own probe: an object `{ id, class, title, live, run(ctx) }`
in the template's `EXTRA`. Verify: run the doctor with `--url` against `pnpm start` of a fresh starter site — no
`live-probes` finding. A site that turned a fix off (`listLimit: false`, `refuseOperatorSort: false`,
`markdown: { negotiate }` with a proxy of its own) gets that probe's finding back: silence it in `iapl-doctor.json`
with the reason.
## Turn off, override, extend
@@ -1432,6 +1497,13 @@ object `{ id, class, title, live, run(ctx) }` in the template's `EXTRA`. Verify:
`safeAdminBack`, `wrapTotpViews`, `copyViews`, `changedViewKeys`, `SAFE_TOTP_VIEW`, `SafeTotpView` are exported.
The stale import-map notice that comes with it: `twoFactor.importMapCheck: false`; its parts
(`findImportMapFile`, `missingImportMapEntries`) are exported too.
- **Lists and sorting:** `listLimit: false` or `{ max, staff, exclude }`; `refuseOperatorSort: false`;
`lockedDocuments: false` or `{ access }`; the hooks and rules above for collections added after iapl.
- **Markdown negotiation:** `createProxy(…, { markdown: { negotiate: false } })` (Markdown only at `/md/…`);
`MARKDOWN_NEGOTIATED_HEADER`, `NEGOTIATED_CACHE_CONTROL`, `appendVary` for your own proxy ([content.md](./content.md)).
- **CSP report log:** `createCspReportRoute({ maxReports, rateLimit: false | { max, windowMs }, onReport })`;
`cspLogLine` for the plugin's line in your own sink.
- **Addresses in `href`:** `buildUrlField({ schemes, overrides })`, `isAllowedUrl`, `safeHref`.
- **Set-up confirmed by e-mail:** `twoFactor.confirmByEmail: false` (off), or `{ linkMinutes, sameBrowser, adminConfirm,
logLinkWhenMailFails, notices, maxMailsPerHour }`; the building blocks above.
- **Setup required:** `twoFactor.requireSetup: false` (off), `{ windowHours }` (another window, `false` / `0` = none),
@@ -1450,7 +1522,7 @@ object `{ id, class, title, live, run(ctx) }` in the template's `EXTRA`. Verify:
2FA — `twoFactor: false` (discouraged).
- **Override:** `additional` (the same key overrides the plugin's header and the `csp` ones),
`buildCsp({ extra, override, mode, strictDynamic })`, `buildAdminCsp({ extra, override })`,
`createCspReportRoute({ onReport, maxBytes })`;
`createCspReportRoute({ onReport, maxBytes, maxReports, rateLimit })`;
2FA — `collectionSlug`, `allowCollectionMismatch`, your own TOTP options by wrapping `plugin`,
`provider` (your own redirect component, or `false` for the package's);
access — `access.authAccess`, `access.firstUserAdmin`, `globalOverrides` ([access.md](./access.md)).