Security suites from the 2026-12 audit: static rules, attack probes, per-class tests, gate

- doctor: code-patterns (unescaped HTML/JSON-LD, eval, shell, NEXT_PUBLIC_ secrets,
  overrideAccess / Local API user, where from the request, redirects and fetches to a
  request address) and config-dangerous; live-probes runs the safe attack probes on --url
- ATTACK_PROBES / runAttackProbes / createProbeContext exported from /doctor; the reference
  site runs all of them in pnpm e2e:built (both bundlers) plus CSRF and cookie flags;
  project template iapl-audit/resources/attack-probes.spec.template.ts
- test/securityPatterns.test.ts gates every hit against test/security-patterns.allow.json;
  test/securityClasses.test.ts covers XSS, redirects, pollution, logs, DoS, cache poisoning
- pnpm security:gate (pnpm audit --prod, the two suites, optional offline ZAP) in prepublishOnly
- audit findings F1, F3, F4, F5 reproduced as expected-to-fail tests/probes; no fix built
- docs: security.md threat list + Security suites, doctor.md, AGENT.md, CHANGELOG, skills

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
Radosław Smoliński
2026-12-01 16:46:42 +01:00
co-authored by Claude Opus 5.5
parent a416411f01
commit d2f19095dc
25 changed files with 1400 additions and 5 deletions
+66
View File
@@ -1350,6 +1350,69 @@ 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.
## Threat list (security audit 2026-12)
What most often hits Payload / Next.js / Node sites, ranked by how often it appeared in the advisories of the last three
years (Dec 2023 – Dec 2026: 71 for `next`, 9 for React Server Components, 58 for `payload` / `@payloadcms/*`, 147 in the
usual transitive dependencies; GitHub Security Advisories, NVD) and by what it costs a client site. OWASP Top 10:2025
and ASVS 5.0 name the categories. Each row says where IAPL covers it and which suite checks it.
| # | 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 |
| 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` |
| 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`) |
| 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 |
| 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` |
## Security suites
Four suites, each runnable by a project on its own site. The plugin repository runs all of them before a release.
| Suite | In a project | In the plugin repository |
|---|---|---|
| **Static rules** over the project's own code and config | `pnpm exec iapl-doctor --only security` (rules `code-patterns`, `config-dangerous`) | `test/securityPatterns.test.ts`: every hit in `src/`, `bin/`, `scripts/` and the reference site must be judged in `test/security-patterns.allow.json` (one reason per file and rule; a new place or a higher count fails) |
| **Per-class tests** of the building blocks | — (the plugin's own) | `test/securityClasses.test.ts`: XSS payloads into JSON-LD, first-paint scripts, links, rich text, sitemap; open redirects; prototype pollution; log injection; body and batch caps; cache poisoning |
| **HTTP attack probes** against a running site | live: `pnpm exec iapl-doctor --url https://<domain> --only live-probes` (changes nothing); local / staging: `.agents/skills/iapl-audit/resources/attack-probes.spec.template.ts` → `tests/attack-probes.spec.ts` | `reference/e2e/attack-probes.spec.ts` in `pnpm e2e:built`, after a webpack and a Turbopack production build, beside the closed-doors spec |
| **Dependency audit** | the doctor's `deps-audit` (`pnpm audit --prod`, error on high / critical) | `pnpm security:gate` (also in `prepublishOnly`): `pnpm audit --prod` with no high / critical, then the two vitest suites; `--zap <url>` adds an OWASP ZAP baseline scan when the image `ghcr.io/zaproxy/zaproxy:stable` is already on the machine (offline; never pulled by the script) |
**Static rules** (`code-*`, one finding per rule and file, seeds / migrations / scripts / tests left out where the
rule is about requests):
| Rule | Severity | Finds |
|---|---|---|
| `code-inner-html` | error | `dangerouslySetInnerHTML` / `innerHTML` / `insertAdjacentHTML` / `document.write` with a value no sanitizer passed; JSON in a `<script>` without `.replace(/</g, '\\u003c')` (use `JsonLdGraph`) |
| `code-eval` | error | `eval`, `new Function`, `vm.run*`, `setTimeout("…")` |
| `code-shell` | error (warning offline) | `exec` / `execSync` with a template string |
| `code-public-secret` | error | a `NEXT_PUBLIC_…SECRET / PASSWORD / TOKEN / PRIVATE / DATABASE…` name; a server secret read in a `'use client'` file |
| `code-override-access` | warning | `overrideAccess: true` in code a request reaches |
| `code-local-api-user` | warning | `payload.find({ user })` without `overrideAccess: false` — Payload then IGNORES the user's rules |
| `code-raw-where` | error | `where:` taken from `req.query`, a body, `searchParams` or `JSON.parse` |
| `code-open-redirect` | warning | `redirect()` / `NextResponse.redirect()` to an address from the request (`?next=`, `?redirect=`) |
| `code-ssrf` | warning | a server-side `fetch()` of an address from the request |
| `config-dangerous` | error / warning | `dangerouslyAllowSVG` without `contentSecurityPolicy`, `remotePatterns` `**`, `serverActions.allowedOrigins` `*`, public source maps; `cors: '*'`, `debug: true`, GraphQL introspection or playground on in production, `maxDepth` above 20 |
A place that is correct on purpose: `// iapl-security-ok: <why>` on the same line or the line above. A whole file or
folder: `iapl-doctor.json` → `"rules": { "code-override-access": { "files": ["src/lib/admin/**"], "off": true, "reason": "…" } }`.
Verify: add `eval(x)` to a page and `pnpm exec iapl-doctor --only code-patterns` reports `code-eval` with the line.
**Attack probes** (`ATTACK_PROBES` in `@intecion/ipal-kit/doctor`; each answers on status codes and headers, a 500 is
never "closed"): `secret-files`, `bundle-secrets` (with the spec: also the site's own secret values), `middleware-subrequest`,
`open-redirect`, `host-header`, `markdown-vary`, `rsc-vary`, `login-operators`, `sort-operator`, `rest-where`, `graphql`,
`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.
## Turn off, override, extend
@@ -1395,6 +1458,9 @@ every answer: `accessAllowed(option, answer)` (exported). The second factor is c
`buildCsp` / `buildCspHeaders` / `buildReportingEndpoints` / `cspHeaderKey` /
`parseCspReports` / `createCspNonce` (`CSP_NONCE_HEADER`, `DEFAULT_CSP_REPORT_GROUP`) for your own proxy
or collector; `buildUploadSecurityHeaders({ collections })` for your own upload collections.
- **Security suites:** `iapl-doctor --skip code-patterns,config-dangerous,live-probes`, or one rule per file / folder in
`iapl-doctor.json`; the building blocks `ATTACK_PROBES`, `runAttackProbes`, `createProbeContext`, `scanCode`,
`scanConfigs` (`@intecion/ipal-kit/doctor`) for your own CI.
- **Check:** `curl -sI https://domain/pl | grep -iE "strict-transport|x-frame|referrer|permissions|cross-origin|content-security|x-powered-by"`
(no `x-powered-by`; `content-security-policy-report-only` while rolling out);
on staging also `x-robots-tag`; startup with a wrong `twoFactor.collectionSlug` fails with `[iapl] twoFactor…`.