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:
co-authored by
Claude Opus 5.5
parent
a416411f01
commit
d2f19095dc
@@ -94,6 +94,22 @@ once there are more than 20.
|
||||
> gate template. **Recommended for projects:** `index: true` on `slugHistory.slug`; the heading font with
|
||||
> `preload: false` (the starter's default now); a placeholder of the 404 content's height.
|
||||
|
||||
### Security audit 2026-12: suites and fixes (docs/security.md)
|
||||
|
||||
> Nothing changes for a running site; nothing to wire. New checks a project can run on its own site:
|
||||
>
|
||||
> - **Static security rules** in the doctor: `iapl-doctor --only security` now also reads the project's own code
|
||||
> (`code-patterns`: unescaped HTML / JSON-LD, `overrideAccess: true` and a Local API `user` without
|
||||
> `overrideAccess: false` where a request reaches, a `where` from the request, `eval`, `NEXT_PUBLIC_` secrets,
|
||||
> redirects and fetches to an address from the request) and its configs (`config-dangerous`). A correct place is
|
||||
> marked `// iapl-security-ok: <why>`. Expect new warnings on an existing site the first time; judge each.
|
||||
> - **Attack probes**: `iapl-doctor --url https://<domain> --only live-probes` (requests that change nothing) and the
|
||||
> Playwright template `iapl-audit/resources/attack-probes.spec.template.ts`. Exported: `ATTACK_PROBES`,
|
||||
> `runAttackProbes`, `createProbeContext`, `scanCode`, `scanConfigs` (`@intecion/ipal-kit/doctor`).
|
||||
> - Known and reported by the probes until fixed (audit findings): the Markdown copy given at an HTML URL to
|
||||
> `Accept: text/markdown` can be cached as the page by a CDN that caches HTML (`markdown-vary`); public REST lists
|
||||
> take any `limit` (`unbounded-list`); an operator name in `?sort=` answers 500 on MongoDB (`sort-operator`).
|
||||
|
||||
## 1.17.2 — version history with readPublished, sign-in and panel actions, staff-only REST submissions and jobs, the cookie button
|
||||
|
||||
> **Read before upgrading.** No schema change, no migration on any database, no import-map change. What changes for
|
||||
|
||||
@@ -1462,6 +1462,9 @@ its own tests). Order from the cheapest:
|
||||
| Site in the browser | `iapl-seo-check`, `iapl-consent-check`, `cookie-scan` | before handover, after deploy |
|
||||
| Closed doors (Playwright) | `iapl-audit/resources/closed-doors.spec.template.ts` → `tests/closed-doors.spec.ts`: every door that must stay closed, asked on a production build as anonymous, customer and editor; add the project's own doors (security.md "Closed doors from outside") | before every release and after every IAPL / Payload update |
|
||||
| Routes judged | `iapl-audit/resources/routes.template.ts` → `tests/routes.ts`; `pnpm payload run tests/routes.ts` against the committed `tests/routes.snapshot.json`, one reason per route; `… update` after an upgrade (security.md "Routes nobody has judged") | in CI, and after every IAPL / Payload / plugin update |
|
||||
| Security, code | `pnpm exec iapl-doctor --only security`: headers, CSP, 2FA, account rules and the static rules over your code (`code-patterns`: unescaped HTML / JSON-LD, `overrideAccess: true` or a Local API `user` without `overrideAccess: false` where a request reaches, a `where` from the request, `eval`, `NEXT_PUBLIC_` secrets, redirects and fetches to an address from the request; `config-dangerous`). A correct place: `// iapl-security-ok: <why>` (security.md "Security suites") | before every "done", in CI |
|
||||
| Attack probes (Playwright / doctor) | `iapl-audit/resources/attack-probes.spec.template.ts` → `tests/attack-probes.spec.ts` on a production build or staging (secret files, bundle secrets, proxy bypass, open redirect, cache poisoning, NoSQL operators, anonymous where / draft / GraphQL reads, error leaks, unbounded lists, `/_next/image`, 8 MB bodies); add a probe per custom endpoint in `EXTRA`. On the live site: `pnpm exec iapl-doctor --url https://<domain> --only live-probes` (changes nothing) | before every release, after every IAPL / Payload / Next update, and after deploy (live) |
|
||||
| Dependencies | `pnpm audit --prod` (the doctor's `deps-audit`): no high or critical; see §4 for the minimum Next / sharp / Payload | before every deploy |
|
||||
| Project logic | vitest for your own functions (mapping company data to JSON-LD, helpers, hooks, migration scripts with `--dry-run`) | when you write logic the plugin does not have |
|
||||
| Panel | the editor test (§11) and the empty-block test (§6.5a) | every new block / global |
|
||||
|
||||
|
||||
@@ -1132,6 +1132,7 @@ Rules: AGENT.md §8a.
|
||||
|
||||
| File | What it shows |
|
||||
|---|---|
|
||||
| `e2e/attack-probes.spec.ts` | attack probes on the built site (run by `pnpm e2e:built` in both bundlers): every probe of the plugin's ATTACK_PROBES (security.md "Security suites") with this site's secret values for the bundle check, plus CSRF with the editor's cookie from another origin and the session cookie's flags; probes tied to an open audit finding are expected to fail (`test.fail`) |
|
||||
| `e2e/closed-doors.spec.ts` | closed doors from outside (run by `pnpm e2e:built` in both bundlers): every door of e2e/closed-doors.ts asked on the production build as an anonymous visitor, a customer (the fixture's `e2e-visitors`) and an editor; doors still open while the owner decides are asserted open (`test.fail`) |
|
||||
| `e2e/closed-doors.ts` | the doors that must stay closed, who each is closed for and how a closed answer looks; a project adds its own (security.md "Closed doors from outside") |
|
||||
| `e2e/create-test-admin.ts` | two test admins with a known TOTP secret (the specs share out the five 2FA verify attempts per account), their stored verify counts cleared, and e-mail sending pointed at the tests' mail sink (local / CI database only) |
|
||||
|
||||
@@ -65,6 +65,13 @@ names, env, admin, AGENTS.md, skills, seeds and — with `--url` / `--deep` —
|
||||
`pnpm payload run tests/routes.ts` fails on a route nobody has judged). A new custom endpoint, collection or
|
||||
route file of the project = a new snapshot entry with its reason, and a door in `DOORS` if it must stay closed.
|
||||
|
||||
- **Attack probes and static security rules** (security.md "Security suites"): `resources/attack-probes.spec.template.ts`
|
||||
→ `tests/attack-probes.spec.ts`, run on a production build or staging (`BASE_URL=… PAGE=/pl pnpm exec playwright test
|
||||
tests/attack-probes.spec.ts`): the plugin's ATTACK_PROBES, plus the project's own in `EXTRA` for every custom
|
||||
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.
|
||||
|
||||
- **Editor test** (AGENT.md §11): every text, image, button, section,
|
||||
menu, footer and SEO field can be changed in the panel, in every language.
|
||||
- **Cookie consent:** in Network, before accepting, there are no requests to
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
/**
|
||||
* Attack probes from outside — the requests attackers send to Payload / Next.js sites, asked on a PRODUCTION build
|
||||
* (`pnpm build && pnpm start`) or a staging copy (IAPL docs/security.md "Security suites"). Copy to
|
||||
* tests/attack-probes.spec.ts and run:
|
||||
*
|
||||
* BASE_URL=http://localhost:3000 PAGE=/pl pnpm exec playwright test tests/attack-probes.spec.ts
|
||||
*
|
||||
* The probes come from the plugin (ATTACK_PROBES, @intecion/ipal-kit/doctor), so an IAPL upgrade brings new ones.
|
||||
* On a LIVE site use `pnpm exec iapl-doctor --url https://<domain> --only live-probes` instead: it runs only the
|
||||
* probes that change nothing (no 8 MB bodies). This spec runs all of them — local or staging only.
|
||||
* The bundle check looks for this site's own secret VALUES: they are read from the environment (.env of the local
|
||||
* build) and never printed. Add the project's own probes to EXTRA.
|
||||
*/
|
||||
import { ATTACK_PROBES, type AttackProbe, createProbeContext } from '@intecion/ipal-kit/doctor'
|
||||
import { expect, test } from '@playwright/test'
|
||||
|
||||
const BASE = (process.env.BASE_URL ?? 'http://localhost:3000').replace(/\/$/, '')
|
||||
const PAGE = process.env.PAGE ?? '/'
|
||||
const secrets = ['PAYLOAD_SECRET', 'CRON_SECRET', 'R2_SECRET_ACCESS_KEY', 'TURNSTILE_SECRET_KEY', 'IAPL_DOCTOR_TOKEN', 'IAPL_COOKIE_SCAN_TOKEN'].map((k) => process.env[k]).filter((v): v is string => !!v && v.length >= 8)
|
||||
|
||||
/** The project's own probes, e.g. a custom endpoint that must refuse an 8 MB body or an operator in its query. */
|
||||
const EXTRA: AttackProbe[] = []
|
||||
|
||||
for (const probe of [...ATTACK_PROBES, ...EXTRA]) {
|
||||
test(`${probe.class}: ${probe.title}`, async () => {
|
||||
const result = await probe.run(createProbeContext(BASE, { page: PAGE, secrets }))
|
||||
test.skip(!!result.skipped, result.skipped)
|
||||
expect(result.ok, result.detail).toBe(true)
|
||||
})
|
||||
}
|
||||
@@ -46,6 +46,16 @@ Full reference: `node_modules/@intecion/ipal-kit/docs/doctor.md`.
|
||||
`--url <url>` · `--staging` (must be noindex) · `--admin-route <path>` · `--deep` · `--env-file <prod export>` (checks
|
||||
`<domain>_prod`) · `--only` / `--skip <ids,groups>` · `--sites '../*-web'` (a read-only rule × site table, exit 0).
|
||||
|
||||
**Security checks only** (security.md "Security suites"): `pnpm exec iapl-doctor --only security` — headers, CSP,
|
||||
2FA, account rules, plus the static rules over the project's own code (`code-patterns`: unescaped HTML / JSON-LD,
|
||||
`overrideAccess: true` or a Local API `user` without `overrideAccess: false` where a request reaches, a `where` from
|
||||
the request, `eval`, `NEXT_PUBLIC_` secrets, redirects and fetches to an address from the request) and its configs
|
||||
(`config-dangerous`). With `--url https://<domain>` also `live-probes`: the plugin's attack probes that change
|
||||
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>`.
|
||||
|
||||
Exit `0` ok · `1` findings at or above `--fail-on` · `2` could not run · `3` a rule crashed.
|
||||
|
||||
## CI of a new site (starter, reference site)
|
||||
|
||||
@@ -896,11 +896,13 @@ Bin: `iapl-doctor` (`pnpm exec iapl-doctor [dir] [--json] [--md] [--strict] [--f
|
||||
| `withJobsRunAccess(config, options \| false)` / `jobsRunNotice(config)` | `@intecion/ipal-kit` | The config with that rule (only when `jobs.access.run` is missing; marks `custom.iapl.jobsRunDefault`); the start-up line when the queue is on and the secret is missing (null otherwise). |
|
||||
| `cronSecretMatches(req, secret)`, `CRON_SECRET_ENV`, `CRON_SECRET_MIN_LENGTH` | `@intecion/ipal-kit` | `Authorization: Bearer <secret>` compared in constant time; an unset or shorter-than-16 secret never matches. Default variable `CRON_SECRET`. |
|
||||
| `runRouteCheck({ config, appDir?, snapshot?, update?, graphql?, cwd?, log? })` | `@intecion/ipal-kit/doctor` | `routes:check`: every public route (REST, GraphQL, Next route files) against the judged snapshot (default `e2e/routes.snapshot.json`); returns 1 on a route nobody judged or an entry without a reason; `update` writes new routes with an empty reason. Template: `iapl-audit/resources/routes.template.ts` (security.md "Routes nobody has judged"). Type `RunRouteCheckOptions`. |
|
||||
| `ATTACK_PROBES`, `runAttackProbes(ctx, probes?)`, `createProbeContext(base, { page?, secrets?, timeoutMs?, userAgent? })` | `@intecion/ipal-kit/doctor` | The HTTP attack probes (secret files, bundle secrets, proxy bypass, open redirect, host-header and negotiation cache poisoning, NoSQL operators in sign-in and sort, anonymous where / draft / GraphQL reads, error leaks, unbounded lists, `/_next/image`, headers, methods, 8 MB bodies). Each `{ id, class, title, live, finding?, run(ctx) → { ok, detail, skipped? } }`; `runAttackProbes` runs the `live` ones by default. The doctor's `live-probes` rule; the Playwright template `iapl-audit/resources/attack-probes.spec.template.ts`; your own probe = an object of the same shape (security.md "Security suites"). Types `AttackProbe`, `ProbeContext`, `ProbeAnswer`, `ProbeResult`. |
|
||||
| `scanCode(path, code)`, `listCodeFiles(root, start)`, `codeFindings(ctx)`, `scanConfigs(next, payload)`, `securityCodeRules`, `SECURITY_OK_MARKER`, `LIVE_PROBE_IDS` | `@intecion/ipal-kit/doctor` | The static security rules behind `code-patterns` and `config-dangerous`: every hit `{ rule, file, line, severity, message, text }` (types `CodeHit`, `CodePatternId`). A correct place is marked `// iapl-security-ok: <why>`. Use `scanCode` in a test of your own to keep a judged allow-list, as the plugin does (`test/security-patterns.allow.json`). |
|
||||
| `listPublicRoutes(config, { graphqlSchema?, routeFiles? })` | `@intecion/ipal-kit` | Stable ids of every door a built config opens: `GET /api/users/me`, `graphql mutation loginUser`, `next GET /sitemap.xml`. From the config only (same on every database). Types `RouteInventoryOptions`, `GraphqlSchemaLike` (`getQueryType` / `getMutationType`). |
|
||||
| `listNextRouteFiles(files, read)` | `@intecion/ipal-kit` | Next route handlers of an app directory (`route.ts` with the methods it exports, `robots.ts`, `sitemap.ts`, `manifest.ts`; route groups left out). |
|
||||
| `compareRouteSnapshot(current, snapshot)` / `updateRouteSnapshot(current, snapshot)` | `@intecion/ipal-kit` | `{ unjudged, unexplained, gone }` against a `RouteSnapshot` (route id → reason); the snapshot after `--update` (new routes with `''`, gone ones dropped). Type `RouteSnapshotDiff`. |
|
||||
|
||||
**Types:** `DoctorRule`, `DoctorFinding`, `RuleFinding`, `DoctorReport`, `DoctorConfig`, `DoctorRuleSetting`, `DoctorSeverity`,
|
||||
**Types:** `AttackProbe`, `ProbeContext`, `ProbeAnswer`, `ProbeResult`, `CodeHit`, `CodePatternId`, `DoctorRule`, `DoctorFinding`, `RuleFinding`, `DoctorReport`, `DoctorConfig`, `DoctorRuleSetting`, `DoctorSeverity`,
|
||||
`DoctorSource`, `DoctorStatus`, `DoctorContext`, `RunDoctorOptions`, `DoctorEndpointOptions`, `FrontendLayout`.
|
||||
|
||||
## Turnstile (`turnstile`) — details: `node_modules/@intecion/ipal-kit/docs/turnstile.md`
|
||||
|
||||
@@ -123,6 +123,9 @@ Turn off: `iapl({ doctor: false })`. Adapt: `iapl({ doctor: { tokenVar: 'MY_TOKE
|
||||
| | `staff-accounts-open` | error (warning for `read`, `readVersions`) | (deep) a staff collection that an account of another, non-staff auth collection may create in, read (also its versions), update, delete from or unlock — it can make itself staff, change a staff password, list the accounts or lift a login lock. The account rules are off (`accounts: false`, `adminOnlyCreate` / `adminOnlyWrite` / `staffOnlyRead: false`) or the project's own rule is wider. Asked with a made-up outside account; a rule that throws counts as closed |
|
||||
| | `turnstile-degraded` | warning / error | (deep) Turnstile is checking forms; while it is not (wrong or missing secret, Cloudflare down) a warning, an error once it has lasted 24 hours (counted from the recorded start to now) |
|
||||
| | `turnstile-env-key` | warning | (deep) the Turnstile secret key is in the panel, not in the deprecated `TURNSTILE_SECRET_KEY` environment variable |
|
||||
| | `code-patterns` | error / warning | the project's own code (`src/`, seeds, migrations, scripts and tests left out where the rule is about requests): `dangerouslySetInnerHTML` / `innerHTML` with a value no sanitizer passed, JSON in a `<script>` without escaping `<` (`code-inner-html`); `eval` / `new Function` / `vm` (`code-eval`); a shell command from a template string (`code-shell`); a `NEXT_PUBLIC_` secret, or a server secret read in a `'use client'` file (`code-public-secret`); `overrideAccess: true` where a request reaches (`code-override-access`); the Local API given a `user` without `overrideAccess: false` — Payload then ignores the user (`code-local-api-user`); a `where` taken from the request (`code-raw-where`); a redirect (`code-open-redirect`) or a server-side `fetch` (`code-ssrf`) to an address from the request. One finding per rule and file. A correct place: `// iapl-security-ok: <why>` on the line or the line above; a file or folder: `iapl-doctor.json` `rules: { "code-override-access": { "files": ["src/lib/admin/**"], "off": true, "reason": "…" } }` (security.md "Security suites") |
|
||||
| | `config-dangerous` | error / warning | `next.config`: `images.dangerouslyAllowSVG` without `images.contentSecurityPolicy` (error), `remotePatterns` hostname `**` / `*`, `serverActions.allowedOrigins` with `*` (error), `productionBrowserSourceMaps: true`; `payload.config`: `cors: '*'`, `debug: true`, GraphQL playground / introspection on in production, `maxDepth` above 20 |
|
||||
| | `live-probes` | error / warning | (live, `--url`) the plugin's attack probes that change nothing: source / env / git files, secrets in the page scripts and public source maps, `x-middleware-subrequest` proxy bypass, open redirects, `X-Forwarded-Host` in redirects and links, Markdown / RSC answers a cache could store as the page, `$ne` operators in a sign-in, anonymous `where` / draft / versions / GraphQL reads, stack traces, unbounded `limit`, `/_next/image` to inner hosts or SVG, headers on every kind of answer, odd methods and an unknown Server Action. Reported as `live-probes:<id>`; the 8 MB-body probe runs only in the Playwright spec (security.md "Security suites") |
|
||||
| | `storage-names` | warning | the visitor cookie the layout sets (`<PageStats visitorCookie>`, default `ipal_vid`) is the one the config makes the cookie scanner declare (`storageNames`, stats.md) |
|
||||
| | `cookie-scanner` | error / warning / info | `cookieScanner` on (with `crawl`, else info); deep: nothing waits for approval (warning) |
|
||||
| mail | `mail-method` | error / info | (deep) the chosen "Sending method" can be used — "Own SMTP server" with server, user name and password, "Microsoft Graph" with the `GRAPH_*` variables; otherwise e-mails are not sent and nothing is sent another way (error). On Postgres / SQLite: the column of `emailMethod` exists — the 1.17.1 migration has run (error). Nobody has chosen yet: the site picks a method from what is filled in until Site integrations is saved (info) |
|
||||
|
||||
@@ -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…`.
|
||||
|
||||
Reference in New Issue
Block a user