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
@@ -71,6 +71,8 @@ names, env, admin, AGENTS.md, skills, seeds and — with `--url` / `--deep` —
endpoint. On the live site: `pnpm exec iapl-doctor --url https://<domain> --only live-probes`. The code side:
`pnpm exec iapl-doctor --only security` (`code-patterns`, `config-dangerous`); a correct place gets
`// iapl-security-ok: <why>`. Dependencies: `pnpm audit --prod` (the doctor's `deps-audit`) — no high or critical.
Every address field rendered into `href` (social profiles, a website) is `buildUrlField()` and rendered through
`safeHref()` (security.md "Addresses rendered into `href`"); the static rules do not flag an `href` from data.
- **Editor test** (AGENT.md §11): every text, image, button, section,
menu, footer and SEO field can be changed in the panel, in every language.
@@ -44,6 +44,12 @@ through this procedure. Ask only when you are missing something you cannot get y
| `isAdmin(user)` / `isEditor(user)` is always `false` in a client component or in `proxy.ts` | the staff collections are not known there (no config in the browser bundle / middleware), and the predicates fail closed | `isAdmin(user, config)` with `useConfig()`, imported from `@intecion/ipal-kit/client`; in middleware `isAdmin(user, { staffCollections: ['users'] })` |
| `next build --webpack`: `'server-only' cannot be imported from a Client Component module … caused by importing '@intecion/ipal-kit/dist/index.js'` | a `'use client'` file imports the main entry (Turbopack lets it pass) | import from `@intecion/ipal-kit/client` (role predicates are there since 1.16.7; types: `import type` from the main entry is fine); data the browser needs → a prop from a server component |
| an account logs in but every page and request answers 403 / the setup screen says "The time to set up two-step verification has passed" | 2FA setup required: the account did not set TOTP up within the window (72 h from its creation, an admin's reset, or the first start after the upgrade) | an administrator opens the account in the panel → Two-step verification → "Reopen setup" (or `POST /api/ipal/two-factor/reset` `{ userId }`); every administrator is blocked: security.md "Every administrator is blocked" — a script with the Local API, `payload.update({ collection: 'users', id, data: { totpSetupFrom: new Date().toISOString() } })` (`pnpm payload run`), then log in and set TOTP up; or `requireSetup: { windowHours: false }`, redeploy, set up, put it back |
| a REST / GraphQL list from the front end returns only 100 documents (`hasNextPage: true`) although `limit` asks for more | `listLimit` (1.18.0, audit F4): callers that are not staff get at most 100 per request; staff and the Local API are not capped | page through (`page=2`), read on the server with the Local API, or `iapl({ listLimit: { max: 500 } })` / `{ exclude: ['slug'] }` / `false` (security.md "Lists and sorting") |
| `GET /api/<collection>?sort=$…` answers `400` "This sort field is not allowed." | `refuseOperatorSort` (1.18.0, audit F5): a sort naming a database operator is refused | sort by a field name; `refuseOperatorSort: false` = Payload's behaviour |
| a visitor account (customer) gets `403` on `/api/payload-locked-documents` | `lockedDocuments` (1.18.0): Payload's document locks are for staff only | intended; your own rule: `lockedDocuments: { access: { read } }`, or `false` |
| `[csp]` log lines show only `blocked=https://host` and `page=/path` (no query), or some reports are missing | `createCspReportRoute` (1.18.0, audit F1): the default line keeps origins and paths, at most 10 violations per request and 60 requests per client a minute | your own `onReport` gets the raw values; `maxReports`, `rateLimit: false` |
| a CDN or Varnish serves Markdown to visitors of an HTML page, or `Accept: text/markdown` answers `public, s-maxage` | a proxy of your own rewrites to `/md/…` without the 1.18.0 headers, or IAPL < 1.18.0 | `createProxy({ markdown: true })`, or copy `MARKDOWN_NEGOTIATED_HEADER` / `appendVary` into your proxy (content.md "content negotiation"); purge the CDN |
| saving a social profile / website address answers "Enter a full address, e.g. https://example.com." | `buildUrlField` (1.18.0, audit F2) accepts `https://` / `http://` and the `schemes` you list | type the full address; `buildUrlField({ schemes: ['mailto', 'tel'] })` for more kinds |
| after typing the code the setup screen says "we sent a link to …" / "the confirmation e-mail could not be sent", and nothing opens | 1.18.0 `twoFactor.confirmByEmail`: the first set-up waits for the link sent to the account's e-mail, opened in the browser that scanned the code | open the link in that browser, then sign in again; no mail: the link is in the server log (`[iapl] 2FA: … Link`), or an admin opens the account → "Confirm the waiting set-up"; fix e-mail (doctor `2fa-enrolment-mail`); "open this link in the browser where you scanned the code" = scan again in the browser you read mail in |
| a new account gets `403` from the API although its role allows the request | 2FA setup required: until TOTP is set up the account reaches only the setup screen | set TOTP up (log in to the panel); an integration: use an API key, or `twoFactor.requireSetup.exempt` |
| after an upgrade EVERY panel login answers `500` (also `/api/users/init`), administrators with 2FA included; log: `[iapl] 2FA: the column for "totpSetupFrom" is missing … NOBODY CAN LOG IN` or `column users.totp_setup_from does not exist` | Postgres/SQLite: the migration that adds the 2FA column has not run (needed whenever 2FA is on) | `pnpm payload migrate:create` if no migration has it, commit, and redeploy with migrations run when the new container starts — `prodMigrations` in the adapter or the start command `pnpm payload migrate && pnpm start` (deployment.md §4.3; not Coolify's Pre-deployment command, which runs in the old container); nothing is lost. `iapl-doctor` reports a project whose migrations lack `totp_setup_from` |
@@ -54,7 +54,10 @@ the request, `eval`, `NEXT_PUBLIC_` secrets, redirects and fetches to an address
nothing, run against the real site (secret files, bundle secrets, proxy bypass, open redirects, cache poisoning,
NoSQL operators, anonymous where / draft / GraphQL reads, error leaks, unbounded lists, `/_next/image`). Verify: on a
fresh starter site the run lists no `code-*` finding; add `eval(x)` to a page and `code-eval` appears. A correct
place is marked `// iapl-security-ok: <why>`.
place is marked `// iapl-security-ok: <why>`. From 1.18.0 a site on IAPL's defaults passes every probe; `markdown-vary`,
`unbounded-list` or `sort-operator` on such a site means a fix was turned off (`markdown: { negotiate }` with a proxy
of its own, `listLimit: false`, `refuseOperatorSort: false`) — security.md "Lists and sorting"; silence the rule with
the reason when that was the decision.
Exit `0` ok · `1` findings at or above `--fail-on` · `2` could not run · `3` a rule crashed.
@@ -46,6 +46,9 @@ description: Complete map of everything @intecion/ipal-kit provides — every ia
| "Sending method" (`emailMethod`; `getMailMethod` / `setMailMethod`) | nobody has chosen: the order of 1.17.0, shown as selected | `relay` (IWSN), `smtp`, `graph` (deprecated): what is chosen is what is used, no fallback; a stored field (Postgres / SQLite: one migration) |
| `secrets.reenterOnChange` | on | a save through access control that changes `smtpHost`, `smtpPort` or `smtpUser` while a password is stored must send the password again or remove it (`400` on the field otherwise), whatever `emailTransport` says — so an admin session cannot send the stored password to a server of its own. A change of the transport alone, and the Local API with access control off, are not asked | `false` = the stored password follows the new server |
| `dashboardAlerts` | `{ integrations: 'admin', cookies: 'editor' }` | who sees the plugin's dashboard alerts: integration details (error text, link) for `integrations` and above, a neutral "ask an administrator" for editors below it, nothing for others; the cookie crawl / approval alert for `cookies` and above. With a role, a session that owes its second factor sees none | `integrations: 'editor' | 'all'`, `cookies: 'all'` (`'all'` = as before: no role and no second factor is checked) |
| `listLimit` | `{ max: 100, staff: false }` (1.18.0, audit F4) | a REST / GraphQL list (`find`, versions, distinct) from a caller that is not staff gets at most `max` documents; `pagination=false` / `limit=0` become one page; staff and the Local API untouched | `false` (Payload's behaviour); `{ max, staff: true, exclude: ['slug'] }`; `buildQueryGuardHook` for a collection added after iapl |
| `refuseOperatorSort` | `true` (1.18.0, audit F5) | a `sort` naming a database operator (`$where`, `-$natural`, `a.$ne`) → `400` for everyone, logged as one `info` line (`RefusedSortError`) | `false`; `loggingLevels: { RefusedSortError: false }` hides the log line |
| `lockedDocuments` | staff only (1.18.0) | Payload's document locks (`payload-locked-documents`) for staff accounts with the second factor; Payload's default was any signed-in account | `false` (Payload's default); `{ access: { read, create, update, delete } }` |
| `adminSameOrigin` | on (1.17.2) | `POST` mail service connect / disconnect, test e-mail, cookie scan / approval / crawl refuse (`403`) a request a browser marks as coming from another origin; own origins: the request's host, `serverURL`, `csrf`, `cors`, `origins` | `{ origins: [...] }` adds origins; `false` = no check; any other value stops the start |
| `adminRoute` | `'/admin'` | `config.routes.admin`; stats link and views, `IntegrationAlerts` | the project moves `app/(payload)/<route>/` itself and adds the route to the proxy matcher (security.md) |
| `twoFactor` | **none = error** | `@clocklimited/payload-2fa` with `forceSetup: true` (TOTP enforced, also checked in the API) | `twoFactor: false` (discouraged); omitting the option throws `[iapl] twoFactor.issuer is required` |
@@ -301,6 +301,7 @@ Opt-in with `iapl({ cookieScanner: true })`; the plugin wires the collection, en
| `MARKDOWN_PREFIX` | `@intecion/ipal-kit` | constant `'/md'` — default prefix of Markdown routes |
| `markdownHref(pathname, prefix?)` | `@intecion/ipal-kit` | page path → Markdown version address (`/pl/o-nas` → `/md/pl/o-nas`), e.g. for `alternates.types` |
| `prefersMarkdown(request \| headers \| accept)` | `@intecion/ipal-kit` | whether the `Accept` header prefers `text/markdown` (q-values); for your own proxy — `createProxy({ markdown: true })` does it itself |
| `MARKDOWN_NEGOTIATED_HEADER`, `NEGOTIATED_CACHE_CONTROL`, `appendVary(headers, token)` | `@intecion/ipal-kit` | 1.18.0 (audit F3): the request marker the proxy sets on a negotiated rewrite (the route then answers `private, no-store` + `Vary: Accept`), that cache-control, and `Vary` with a token added once — for your own proxy (content.md "content negotiation"). `markdownResponse(md, { negotiated: true })` gives the same headers. `createProxy({ markdown: { prefix?, negotiate? } })`: `negotiate: false` = no rewrite. |
| `searchContent({ payload, query, config, locale?, limit?, baseUrl?, collection?, summaryField? })` | `@intecion/ipal-kit` | searches published, indexable pages by title/description → `SearchResult[]`; does not throw |
| `listContent({ payload, config, locale?, limit? })` | `@intecion/ipal-kit` | list of published, indexable pages (no query) — used by MCP `list_pages` |
| `createSearchRoute({ getCachedPayload, config, baseUrl, defaultLimit?, rateLimit?, clientIp?, isPathVisible? })` | `@intecion/ipal-kit` | `GET` handler for the JSON search endpoint (`?q=&locale=&limit=`), with a per-IP rate limit; pass `isPathVisible` from `@/lib/content` so construction mode hides pages here too |
@@ -503,6 +504,7 @@ The editor builds forms in the panel (Forms collection). The project does NOT wr
| `resolveSystemLinks(settings, { locale, config, roles?, … })` | `@intecion/ipal-kit` | Links to system pages from Site settings (privacy/cookies/terms) with the page title as the label → `SystemLink[]`; in a project usually `getSystemLinks` from `lib/content` |
| `homeSlugFrom(settings, field?)` | `@intecion/ipal-kit` | Homepage slug from `SiteSettings.homepage` (populated) or `undefined` |
| `safeHref(url)` | `@intecion/ipal-kit` | The URL when safe (http(s), mailto, tel, sms, #, `/` path), otherwise `null` — blocks `javascript:`/`data:` |
| `buildUrlField({ name?, label?, required?, schemes?, description?, overrides? })`, `isAllowedUrl(value, schemes?)` | `@intecion/ipal-kit` | 1.18.0 (audit F2): a text field for an address rendered into `href` — `https://` / `http://` pass, plus the `schemes` you list (`mailto`, `tel`, `sms`, `hash`, `relative`); `javascript:`, `data:`, `//host` never. Render the value with `safeHref` too. Types `BuildUrlFieldOptions`, `UrlScheme`. |
**Types:** `BuildLinkFieldOptions`, `BuildLinksFieldOptions`, `LinkAppearance`, `LinkAppearanceOption` — link field options and styles; `LinkValue`, `ResolveLinkHrefOptions`, `ResolvedLink`, `NavItem`, `ResolveNavOptions`, `SystemLink` — panel link value, resolver options and results.
@@ -650,7 +652,10 @@ Server only (`pnpm payload run`); never import it from client code, the Payload
| `buildCsp({ mode?, reportUri?, reportGroup?, r2Url?, analytics?, metaPixel?, linkedIn?, tiktok?, clarity?, turnstile?, youtube?, googleMaps?, nonce?, strictDynamic?, dev?, extra?, override? })` | `@intecion/ipal-kit` | Returns `{ key, value }` with a hardened CSP (`base-uri`, `object-src`, `frame-ancestors`, `form-action`) + sources for the enabled integrations. `mode: 'report-only'` → `…-Report-Only` (start here), `'enforce'` later. `extra` adds to any directive, `override` replaces / drops one (`null`). `dev` (default `NODE_ENV === 'development'`) adds `'unsafe-eval'`. `nonce` → `'nonce-…' 'strict-dynamic'`. |
| `buildCspHeaders(args)` | `@intecion/ipal-kit` | `[csp, Reporting-Endpoints]` (the second only with `reportUri`). |
| `buildAdminCsp(args)` / `buildAdminCspHeaders(args)` | `@intecion/ipal-kit` | Looser policy for Payload's admin: Monaco from `cdn.jsdelivr.net`, `blob:` workers, `https:` images, Live Preview `frame-src 'self'`, `frame-ancestors 'self'`. Rule `{ source: '/admin/:path*', headers: buildAdminCspHeaders({ mode, reportUri }) }` AFTER the site-wide rule. |
| `createCspReportRoute({ onReport?, maxBytes? })` | `@intecion/ipal-kit` | `POST` handler for `reportUri` (`src/app/api/csp-report/route.ts`): both report formats, body cap 16 KB, always `204`; default sink = one `[csp] …` `console.warn` line per violation (Coolify logs). |
| `createCspReportRoute({ onReport?, maxBytes?, maxReports?, rateLimit? })` | `@intecion/ipal-kit` | `POST` handler for `reportUri` (`src/app/api/csp-report/route.ts`): both report formats, body cap 16 KB, always `204`; default sink = one `[csp] …` `console.warn` line per violation (Coolify logs) made by `cspLogLine` — origin / path only, no control characters, values ≤ `CSP_LOG_VALUE_MAX` (128) (1.18.0, audit F1); at most `maxReports` (10) per request, `rateLimit` 60 / min per client (`false` = none); your `onReport` gets the raw values. |
| `cspLogLine(violation)`, `CSP_LOG_VALUE_MAX` | `@intecion/ipal-kit` | the default CSP log line (safe to log) for your own sink, and its value cap. |
| `buildQueryGuardHook({ listLimit?, refuseOperatorSort? })`, `applyQueryGuard(config, options)`, `capListLimit(args, max?)`, `isOperatorSort(sort)`, `isStaffRequest(req)`, `RefusedSortError`, `DEFAULT_LIST_LIMIT`, `isQueryGuardHook`, `QUERY_GUARD_MARK` | `@intecion/ipal-kit` | 1.18.0 (audit F4, F5; security.md "Lists and sorting"): the `beforeOperation` hook iapl adds to every collection — lists from a non-staff caller over REST / GraphQL capped at 100 (`pagination=false`, `limit=0` included), a `sort` naming a database operator → `400` (logged as `info`). Options `listLimit: false \| { max, staff, exclude }`, `refuseOperatorSort: false`. Put the hook on a collection a plugin adds after iapl. Type `ListLimitOptions`. |
| `applyLockedDocumentsAccess(config, access?)`, `staffOnlyLocks`, `LOCKED_DOCUMENTS_SLUG` | `@intecion/ipal-kit` | 1.18.0: Payload's document locks (`payload-locked-documents`) for staff accounts only (with the second factor); iapl sets it at start (`lockedDocuments: false` = Payload's default, `{ access }` = your rule per operation). Type `LockedDocumentsAccess`. |
| `parseCspReports(body)` | `@intecion/ipal-kit` | Normalises a report body (`csp-report` object or Reporting API array) to `CspViolation[]` — for your own collector. |
| `buildReportingEndpoints(url, group?)`, `cspHeaderKey(mode?)`, `DEFAULT_CSP_REPORT_GROUP` | `@intecion/ipal-kit` | Building blocks: the `Reporting-Endpoints` header, the header name for a mode, the default `report-to` group (`'csp-endpoint'`). |
| `createCspNonce()`, `CSP_NONCE_HEADER` | `@intecion/ipal-kit/next/middleware`, `@intecion/ipal-kit` | A per-request nonce and the request header (`x-nonce`) `createProxy({ csp })` passes it in — for your own proxy. Nonces make pages dynamic (no ISR). |
+3 -2
View File
@@ -487,7 +487,7 @@ and `rel="alternate" type="text/markdown"`; `/pl/nie-ma-takiej` → 404 with con
| `src/app/robots.ts` | `export { getRobots as default } from '@/lib/content'` + `force-dynamic` (AI crawler policy from Site settings → Search engines; `robots` = code only) |
| `src/app/manifest.ts` | `export { manifest as default } from '@/lib/content'` + `force-dynamic` |
| `src/app/api/health/route.ts` | `export { healthRoute as GET } from '@/lib/content'` + `force-dynamic` |
| `src/app/api/csp-report/route.ts` | `import { createCspReportRoute } from '@intecion/ipal-kit'` + `export const POST = createCspReportRoute()` (CSP violation reports → `[csp]` lines in the logs) |
| `src/app/api/csp-report/route.ts` | `import { createCspReportRoute } from '@intecion/ipal-kit'` + `export const POST = createCspReportRoute()` (CSP violation reports → `[csp]` lines in the logs: origins and paths only, 10 per request, 60 requests per client a minute; security.md "Collecting reports") |
```ts
// next.config.ts
@@ -581,7 +581,8 @@ Already wired and required: `markdown: true` (stage 6 proxy), `markdownAlternate
**Check.** `curl -s localhost:3000/llms.txt` → site name and a list of pages with descriptions (`aiSummary`);
`/llms-full.txt` → page content; `curl -s localhost:3000/md/pl` → Markdown of the home page; `curl -s -H 'Accept:
text/markdown' localhost:3000/pl` → the same Markdown; `curl -s -X POST localhost:3000/api/mcp -H 'content-type:
text/markdown' localhost:3000/pl` → the same Markdown, sent `cache-control: private, no-store` with `Vary: Accept`
(`curl -sD- -o/dev/null -H 'Accept: text/markdown' localhost:3000/pl`; 1.18.0, so no CDN stores it as the page); `curl -s -X POST localhost:3000/api/mcp -H 'content-type:
application/json' -d '{"jsonrpc":"2.0","id":1,"method":"tools/list"}'` → `get_site_info`, `list_pages`,
`search_content`, `get_page`; `/indexnow-key.txt` → `404` until the key is generated in the panel, then the key.
@@ -47,6 +47,22 @@ are not affected. Nothing to wire, no migration, no import-map change. Off: `two
**Check:** `pnpm exec iapl-doctor --deep` shows no `2fa-enrolment-mail` error; a test editor scans the code → the
screen says "we sent a link to …", the link opened in the same browser → "Two-step verification is on".
**→ 1.18.0, security audit fixes (CHANGELOG 1.18.0 "Security audit 2026-12"; security.md "Lists and sorting") — no
migration, no import-map change; check before deploying:** (1) **public lists are capped at 100** for callers that are
not staff (REST / GraphQL; the Local API and the panel are not touched): a client-side script that reads more than
100 documents anonymously gets `hasNextPage: true` — page through, or `listLimit: { max }` / `{ exclude: ['slug'] }`
/ `false`; (2) a `?sort=$…` answers `400` (`refuseOperatorSort: false` = Payload's way); (3) Payload's document locks
are staff only (`lockedDocuments: false` = Payload's default); (4) the negotiated Markdown at a page URL is
`private, no-store` + `Vary: Accept`, and pages under the proxy matcher get `Vary: Accept` — a proxy of your own that
rewrites to `/md/…` copies the headers (content.md); `markdown: { negotiate: false }` turns negotiation off; (5) CSP
report log lines show origins and paths, at most 10 per request and 60 requests per client a minute (a log parser
that read full URLs adapts; `createCspReportRoute({ maxReports, rateLimit })`); (6) a text field of your own whose
value goes into `href` (social profiles, a website): `buildUrlField()` and `safeHref()` at render (no schema change);
(7) the first `iapl-doctor --only security` run shows the new `code-*` / `config-dangerous` rules — judge each, mark a
correct place `// iapl-security-ok: <why>`. **Check:** `curl -s '<site>/api/pages?limit=100000' | jq .limit` → `100`;
`curl -s -o /dev/null -w '%{http_code}' '<site>/api/pages?sort=%24where'` → `400`;
`pnpm exec iapl-doctor --url <site> --only live-probes` → no finding.
**→ 1.17.2, security (CHANGELOG 1.17.2; PROGRAMISTA §6, items 84–87) — nothing required, check:** `readVersions:
readPublished()` now works (a wrapper of your own around it: use `readPublishedVersions()` inside); behind a proxy
that rewrites `Host` without `X-Forwarded-Host`, set `serverURL` or the panel's mail / cookie buttons answer 403