- 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]>
298 lines
31 KiB
Markdown
298 lines
31 KiB
Markdown
# iapl-doctor — one check for the whole site
|
||
|
||
`iapl-doctor` checks a site against the team's rules and lists every gap with a fix hint and a doc link. It covers
|
||
what drifts between sites: versions, Node, the folder layout, database names, env rules, security headers, 2FA, the
|
||
cookie scanner, the admin preview, the agent guide, seeds, the block library, speed (images, fonts, embeds,
|
||
render-blocking resources, animations, budgets), and the running site.
|
||
|
||
Related: [AGENT.md §11](./agent/AGENT.md), the `iapl-doctor` skill, [deployment.md](./deployment.md),
|
||
[seeding.md](./seeding.md), [security.md](./security.md), [blocks.md](./blocks.md).
|
||
|
||
## Run it
|
||
|
||
```bash
|
||
pnpm exec iapl-doctor # this project, human-readable
|
||
pnpm exec iapl-doctor --strict --offline # CI on a new site: any finding fails
|
||
pnpm exec iapl-doctor --deep --url http://localhost:3000 # + database (read-only) and the running site
|
||
pnpm exec iapl-doctor --json > doctor.json # machine-readable
|
||
pnpm dlx --package=@intecion/ipal-kit@latest iapl-doctor # the newest rules, before an upgrade
|
||
```
|
||
|
||
`iapl-doctor` is a bin of the package (`bin/iapl-doctor.mjs`), like `iapl-skills`. `pnpm exec` uses the rules of
|
||
the version the site has installed — reproducible in CI. The report header names both: the rules version and the
|
||
site's IAPL.
|
||
|
||
| Option | What it does |
|
||
|---|---|
|
||
| `[dir]` | the project folder (default: the current one) |
|
||
| `--json` | the report as JSON (schema 1, below) |
|
||
| `--md` | a Markdown table |
|
||
| `--strict` | any finding that is not silenced fails (= `--fail-on info`) |
|
||
| `--fail-on error\|warning\|info` | the lowest severity that fails (default `error`) |
|
||
| `--offline` | skips the two rules that need the registry: `plugin-latest` (`pnpm view`) and `deps-audit` (`pnpm audit --prod`) |
|
||
| `--url <url>` | also checks the running site: headers, X-Powered-By, CSP, `/api/health`, admin noindex and link preview, production noindex, and `iapl-seo-check` (robots, sitemap, canonical, hreflang, JSON-LD, llms, MCP) |
|
||
| `--staging` | with `--url`: the site is a staging copy, so it must be noindex |
|
||
| `--admin-route <path>` | with `--url`: the panel path (default `/admin`) |
|
||
| `--deep` | read-only database checks through `pnpm exec payload run` (below) |
|
||
| `--env-file <file>` | a production env export (e.g. copied from Coolify): its `DATABASE_URI` must name `<domain>_prod` |
|
||
| `--only <ids,groups>`, `--skip <ids,groups>` | run or leave out rules or whole groups |
|
||
| `--sites <glob>` | many projects at once, e.g. `'../*-web'`: a rule × site table (always exit 0 — a report, never a gate) |
|
||
|
||
**Exit codes:** `0` nothing at or above `--fail-on` · `1` findings at or above it · `2` the doctor could not run (not
|
||
a project root, a broken `iapl-doctor.json`, a bad option) · `3` a rule crashed (the others still report).
|
||
|
||
**Severities:** `error` breaks a team rule or is a security or data risk; `warning` is drift to fix; `info` is
|
||
worth knowing. Without `--strict`, only errors fail.
|
||
|
||
## Static, live, deep
|
||
|
||
- **Static** (default): reads files only — `package.json`, the installed versions in `node_modules`, the config
|
||
files, `.env` / `.env.example` (only variable names and the database name ever reach the report, never values),
|
||
the import map, `AGENTS.md`, the skills folder. It also runs `iapl-audit --quick` from the installed package. No
|
||
build, no database, no server. It writes nothing, except one date in `iapl-doctor.json` (below) outside CI.
|
||
- **Live** (`--url`): GET requests only, no login, a doctor user agent, each path once per run. `localhost` is exempt
|
||
from the HSTS check (plain http).
|
||
- **Deep** (`--deep`): `pnpm exec payload run node_modules/@intecion/ipal-kit/dist/modules/doctor/probe.js` in the
|
||
project, with the project's `DATABASE_URI` and `PAYLOAD_SECRET`. Read-only counts: panel users without TOTP, cookies
|
||
waiting for approval; the project's own env rules (`register()` from `instrumentation.ts`); the committed import map
|
||
against a freshly generated one (written to a temporary file next to it and removed). Run it locally against the dev
|
||
database, or in the Coolify app container's terminal against the MongoDB container.
|
||
- **Deep through the site**: with `--url` (and no `--deep`), when `IAPL_DOCTOR_TOKEN` is set in the doctor's
|
||
environment, the doctor reads the same counts from `GET /api/ipal/doctor` of the running site.
|
||
|
||
### The status endpoint — `GET /api/ipal/doctor`
|
||
|
||
Added by `iapl` and **off until the site has `IAPL_DOCTOR_TOKEN`** (at least 32 characters): before that it answers
|
||
404. With the token set it needs `Authorization: Bearer <token>`, is rate-limited (10 a minute per client IP) and
|
||
returns counts only — never names, e-mails or values:
|
||
|
||
```json
|
||
{ "mail": { "graphEnv": false, "relay": { "connected": true, "disconnected": false, "nameReplaced": false, "state": "active" }, "replyAddress": true, "status": null, "transport": "relay" }, "media": { "images": 42, "oversized": 0, "tooWide": 0 }, "node": "v22.20.0", "openSignUp": [], "pendingCookies": 0, "plugin": "1.15.0", "staffOnOwnRoles": [], "staffOpenToOthers": [], "turnstile": null, "turnstileSecretFromEnv": false, "usersSetupClosed": 0, "usersWithout2fa": 0 }
|
||
```
|
||
|
||
`growth` (since 1.18.0): per collection its documents, its size with indexes (MongoDB; `null` elsewhere) and the date
|
||
of its oldest record; versions per versioned collection and global with their limit; `payload-kv` entries and how
|
||
many have expired; media no document points at (`checked` documents read, at most 5000); the retention in days of
|
||
each plugin log — counts, sizes and dates only.
|
||
|
||
`media` (since 1.18.0): how many images the upload collections hold and how many are over the plugin's limits
|
||
(1.5 MB, 2560 px) — counts only, `null` without an upload collection.
|
||
|
||
`mail` (since 1.17.0): the e-mail transport in effect, the recorded state of sending and the site's state with the
|
||
Intecion mail service — states and codes only, never a token, a password or an address; `relay` is `null` when the
|
||
mail service is switched off.
|
||
|
||
Turn off: `iapl({ doctor: false })`. Adapt: `iapl({ doctor: { tokenVar: 'MY_TOKEN', access: ({ req }) => isAdmin(req.user, req.payload) } })` (a logged-in staff admin may read it too; the second factor is checked for you — never test `req.user.roles` by hand, an account of another collection can carry the same value)
|
||
(`access` lets a logged-in admin read it without the token). Building blocks: `buildDoctorEndpoint`,
|
||
`collectDoctorStatus` from `@intecion/ipal-kit/doctor`.
|
||
|
||
## The rules
|
||
|
||
| Group | Rule | Severity | Checks |
|
||
|---|---|---|---|
|
||
| versions | `plugin-installed` | error | `node_modules` has `@intecion/ipal-kit` and it satisfies `package.json` |
|
||
| | `plugin-latest` | warning; error two or more minors behind | the installed plugin is the newest on the team registry (registry) |
|
||
| | `next-min` | error | `next` ≥ 16.4.5 (below 16.4.1: RCE/DoS advisories; 16.3.0–16.4.4: GHSA-mfr8-8qww-v76h); `eslint-config-next` on the same minor (warning) |
|
||
| | `sharp-min` | error | `sharp` ≥ 0.35.5 |
|
||
| | `transitive-min` | error (`mongoose`), warning (`happy-dom`) | packages Payload pins below a security fix, in any depth of the tree (read from `pnpm-lock.yaml`, else `node_modules/.pnpm`): `mongoose` 8.x ≥ 8.24.7 (GHSA-pcrw-h46h-c93h and four more; Payload 3.90–3.93 pin 8.24.1, 3.94.0+ ship 8.24.7 — the fix it prints names the Payload upgrade first), `happy-dom` ≥ 21.0.4 (GHSA-c8p4-j97h-3vg8, GHSA-834v-8h66-3h79). The fix it prints is the `pnpm.overrides` line from AGENT.md §4 item 12 |
|
||
| | `node-22` | warning | `engines.node` only 22 (`">=22 <23"`), `.nvmrc` / `.node-version` = 22; with `--deep`, the running Node |
|
||
| | `pnpm-pinned` | info | `packageManager` is set |
|
||
| | `deps-audit` | error on critical/high, info on moderate/low | `pnpm audit --prod` (registry) |
|
||
| layout | `layout-required` | error | the AGENT.md §3 files (proxy, i18n config, instrumentation, `lib/content`, every route, the frontend files — `layout`, `actions`, `not-found`, `notFoundView` (`.ts` or `.tsx`), the catch-all page — in the route group found by structure: any `app/(<group>)` (or `app` itself) holding `[locale]/[[...slug]]/page.tsx` or `[[...slug]]/page.tsx`, a localized one first, `(frontend)` on a tie (two matches → a warning naming both); `layout.frontend` sets it, `blocks/registry.ts`, `collections/{Pages,Media}.ts`, `components/layout`, `components/forms/formClasses.ts`); an `iapl-audit-skip` key (`llms`, `llms-full`, `markdown`, `mcp`, `indexnow`) drops its file |
|
||
| | `layout-forbidden` | error | no `middleware.ts`, no `lib/{pages,locales,navigation}.ts`, `fields/{link,sectionHeader,sectionSettings}.ts` |
|
||
| | `layout-extra` | info | `src/` entries outside the allow list (AGENT.md §3 + `seed/`, `design/`, `db.ts`, `env.rules.ts`, `content.config.ts`; extend with `layout.allow`) |
|
||
| | `naming` | warning | block folders, collection and global files PascalCase, `scripts/*` kebab-case, no `index.ts` barrels |
|
||
| | `importmap` | error | the import map exists, holds the entries for what the config turns on (2FA incl. `SafeTotpView`, `TwoFactorStatusField`, `TwoFactorAlert`; R2, cookie scanner, `adminMeta`), names no export the plugin no longer has; with `--deep`, equals a fresh one. Warning: the config uses the 2FA package's own setup / verify view as a view's `Component` (outside the `back` link check — security.md); not for that path as `ipalTotpView` of `SafeTotpView` or in `admin.dependencies` |
|
||
| | `tsconfig-skills` | error | `tsconfig.json` excludes the skills folder |
|
||
| env | `db-name` | error | `DATABASE_URI` in `.env` and `.env.example` names `<domain without dots>_dev`; a local `.env` on `_prod` is an error; `--env-file` checks `_prod` (`databaseNamesFor`) |
|
||
| | `env-rules` | error / warning | `instrumentation.ts` calls `assertEnv(iaplEnvRules(…))` from `/env`, with `storage` (R2), `cookieCrawl` (crawl), `ipHeader`; `databaseName` suggested (info) |
|
||
| | `env-example` | warning / error | `.env.example` lists the variables those rules name; no credentials or secret values in it |
|
||
| | `env-live` | error | (deep) the project's env rules pass in the real environment |
|
||
| security | `security-headers` | error | `buildSecurityHeaders`; live: HSTS, nosniff, Referrer-Policy, Permissions-Policy, frame protection |
|
||
| | `powered-by` | error | `withSecurityConfig`; live: no `X-Powered-By` on `/` and the admin |
|
||
| | `visitor-writes` | warning | (deep) on a site with a visitor login collection (an auth collection that is not staff): every collection whose `create` / `update` / `delete`, or global whose `update`, lets such an account in — Payload's default "any signed-in account" included. Give it its own rule (`adminOrEditor`, …); asked by behaviour, never by a rule's name (1.17.2) |
|
||
| | `proxy-matcher` | warning | `src/proxy.ts`: a matcher that skips `api`, `admin` or `_next` without ending them at "/" (`(?!api|admin|…)`) also skips every page whose first segment only starts with them (`/administracja`): no locale redirect, no proxy CSP. Fix: the literal in i18n.md (1.17.1) |
|
||
| | `client-hints` | info | `withSecurityConfig` is the outer wrapper (`withSecurityConfig(withPayload(…))`), so Payload's colour-scheme client hints go to the admin only; live: `/` sends no `Critical-CH: Sec-CH-Prefers-Color-Scheme`. Not reported with `adminClientHints: false` |
|
||
| | `csp` | warning / info | CSP on the site and the admin; report-only is info, a warning after 4 weeks (`seen`) |
|
||
| | `2fa` | error | `twoFactor: { plugin: payloadTotp }` + the package; deep: 0 users without TOTP (the message says how many of them are blocked because their setup window has passed); error: a Postgres / SQLite project whose migrations do not mention the 2FA column `totp_setup_from` (every login would answer 500; a warning when there is no migrations folder — the doctor cannot see a schema that gets there another way); warning: `twoFactor.requireSetup: false`; info: no setup window (`windowHours: false`) |
|
||
| | `2fa-enrolment-mail` | error / info | (deep) `twoFactor.confirmByEmail` is on (the default since 1.18.0) and e-mail does not work (no transport, no method chosen, SMTP incomplete): nobody finishes setting up two-step verification alone — the link is only in the server log, or an admin confirms each set-up (error); set-ups waiting for their link (info; error while mail does not work) |
|
||
| | `access-missing` | warning | `iapl` has an `access` option — without it there are no roles and every panel account is an admin |
|
||
| | `csrf-empty` | warning | the config sets `serverURL` or `csrf` — otherwise Payload accepts the login cookie from any origin, and behind a proxy that rewrites `Host` the plugin's own-origin checks (2FA, panel actions) refuse the site's own panel. With `--url` (deep) the running config decides (`originKnown` in the status), not the file |
|
||
| | `open-signup` | info | (deep) auth collections whose `create` rule lets an anonymous request through: sign-up is open there (intended for a customer zone — silence with a reason) |
|
||
| | `staff-own-roles` | warning | (deep) a staff collection with role values of its own, neither `editor` nor `admin` among them, that runs on the plugin's default account rules: the plugin cannot rank those roles, so inside the collection every account may create an account with any role and change or delete another. Write the collection's own rules |
|
||
| | `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) |
|
||
| | `mail-transport` | error / warning | (deep) an e-mail transport is in effect (not: the mail service switched off and no SMTP server); the last sends worked — failing: warning, error once it has lasted 24 hours |
|
||
| | `mail-non-public` | info | (deep) on the mail service: says which signal makes the site a non-public copy — its host matches a development pattern (`developmentHosts`, named in the finding) or `IAPL_NOINDEX` is set — and what to change if the site is in fact the public one |
|
||
| | `mail-relay-state` | error / warning / info | (deep) on the Intecion mail service: not disconnected and not stopped (error), not waiting for approval, not refused at enrolment, not a non-public copy of another site's database that waits for "Connect again" (`client-other-host`), the sender name not replaced (warning); not enrolled yet, and a public site whose database also holds another host's connection — its own past after a launch or a move, or a copy that forgot `IAPL_NOINDEX=1` (info) |
|
||
| | `mail-reply-address` | warning | (deep) on the mail service, "Sender address" is filled in: replies go there |
|
||
| | `mail-graph-deprecated` | warning | Microsoft Graph is not in use: no `GRAPH_*` variables on the site (deep), no `graphAdapter` / `emailGraph: true` in the config — deprecated, removed in 2.0 |
|
||
| | `mail-relay-route` | warning | nothing keeps the mail service from confirming the site: no `trailingSlash: true`, `routes.api` is `/api` (else Intecion sets the site's confirm address); live, on the mail service: `/api/iapl/mail-relay/confirm` answers without a redirect, a block or a server error. Skipped with `relay: false` |
|
||
| admin | `admin-meta` | warning | IAPL ≥ 1.14.5, no `adminMeta: false` / `agency: false`; live: the admin `og:image` is `/api/ipal/admin-og` |
|
||
| | `admin-noindex` | error | (live) the admin login page is noindex |
|
||
| agents | `agents-md` | error / warning | `AGENTS.md` with a non-empty `## Project decisions`, the `iapl:start…end` pointer for the installed version, `CLAUDE.md` with `@AGENTS.md` |
|
||
| | `legacy-names` | info / warning | names from before the rename to IAPL (1.17.0) the project still uses: `ipal-doctor.json`, `ipalKit` / `ipalEnvRules` and the other old exports in the config and `instrumentation.ts`, old commands in `package.json` scripts, `IPAL_*` in env files, the old pointer block, `ipal-audit-skip`, `ipal-*` skill folders. All of them work, so this is information; a **warning** only for two doctor files side by side, or one variable set as `IAPL_…` and `IPAL_…` with different values |
|
||
| | `skills-current` | warning | `.agents/skills/iapl-*` equal the installed plugin's (`planSkills`, what `iapl-skills` would change) |
|
||
| seeds | `seed-named` | error / warning | every `seed*` script uses `createSeeder` (`only` / `SEED_ONLY`, the full-seed guard), deletes nothing, has no `fresh`/`reset` script, does not switch the guard off (`guard: false`, `allowFull: true`, `IAPL_SEED_ALLOW_FULL=1` in a script or committed env file); after launch a seed without an `only` list is a warning |
|
||
| blocks | `blocks-registry` | error | `blocks/registry.ts` uses `createBlockRegistry` or `RenderBlocks` (no `switch (blockType)`) |
|
||
| | `blocks-ui-required` | error | without `createBlockRegistry`, `components/ui/` has Section, SectionHeader, Media, CMSLink, Button |
|
||
| | `blocks-ui-override` | warning | a `components/ui/` file named like a library primitive is passed through `createBlockRegistry({ ui })` |
|
||
| | `blocks-duplicate` | warning | a project block whose `slug` (or `interfaceName`) matches a library block — also a slug renamed through the block's `slug` option — unless it is an override in `createBlockRegistry({ components })` |
|
||
| | `blocks-helper-copy` | warning | no local copy of a plugin field builder (`blockLibraryManifest.fieldBuilders`), `ctaHref`, `buildActionButtonsField` |
|
||
| | `blocks-tokens` | error / warning | from `iapl-audit`: hex colours, the token standard not wired, `iapl-tokens --check` |
|
||
| performance | `perf-images-config` | error | `next.config` uses `buildImagesConfig()` (AVIF / WebP, R2, long cache) — [performance.md](./performance.md) |
|
||
| | `perf-fonts` | error | no font from Google / Typekit hosts, no `font-display: block`, every `@font-face` has `font-display`, at most two `next/font` families |
|
||
| | `perf-render-blocking` | error | no `<script src>` without `async` / `defer`, no stylesheet `<link>` or CSS `@import` from another host |
|
||
| | `perf-embeds` | error | no `<iframe>` (map, widget) that loads with the page — a click-to-load facade, or `loading="lazy"`; YouTube is `iapl-audit`'s |
|
||
| | `perf-animations` | error | no transition of a layout property or `transition-all`, no `scroll` listener, something honours `prefers-reduced-motion` when the site animates |
|
||
| | `perf-budgets` | error | a project that runs Playwright has a performance budget test in `e2e/` (the `iapl-performance` skill's template) |
|
||
| | `perf-live` | error | (live) the home HTML is compressed, has no blocking `<script>` in `<head>`, preloads at most four fonts, its first image in `<main>` is not lazy, and is at most 150 KB |
|
||
| | `perf-images` | error | (deep) no stored image over 1.5 MB or 2560 px wide (`IMAGE_RULES`) |
|
||
| growth | `growth-size` | warning | (deep) no collection over `growth.maxDocs` (200 000) documents or `growth.maxMB` (512, data + indexes, MongoDB) — [performance.md](./performance.md) §6 |
|
||
| | `growth-versions` | warning | (deep) no collection or global keeps versions without a limit (`maxPerDoc` / `max`: 0), none over `growth.maxVersions` (50 000) |
|
||
| | `growth-retention` | warning | (deep) a log with a retention (consent log, statistics, form submissions with `submissionRetentionDays`) holds no record older than it — its purge runs |
|
||
| | `growth-submissions` | info / warning | (deep) form submissions kept without a retention; a warning when the oldest is over `growth.submissionDays` (730) |
|
||
| | `growth-kv` | warning | (deep) at most `growth.expiredKv` (1000) expired entries in `payload-kv` |
|
||
| | `growth-media` | info / warning | (deep) media no document or global points at; a warning over `growth.orphanedMedia` (25). From the first 5000 documents |
|
||
| | `growth-versions-config` | info | a collection or global in `src/collections` / `src/globals` turns versions on without `maxPerDoc` / `max` (Payload keeps 100) — the hint names the limit to add |
|
||
| | `growth-disk` | info | `.next/cache/images` over `growth.imageCacheMB` (1024), the local `media/` over `growth.uploadsMB` (2048), on the machine the doctor runs on |
|
||
| audit | `i18n-literals` | error / warning | from `iapl-audit`: hardcoded text in blocks (error) and components (warning), Polish literals in code (not the panel's `adminText()` / `{ en, pl }` labels in a schema file — the `iapl-audit` skill) |
|
||
| | `audit:<title>` | as reported | every other `iapl-audit --quick` finding, one per file |
|
||
| live | `live-reachable`, `live-health`, `live-noindex`, `live-seo` | error / warning | the URL answers; `/api/health` 200; production not noindex (staging must be); every `iapl-seo-check` error and warning |
|
||
| deep | `deep-status` | error | the deep check could not finish |
|
||
| — | `doctor-config` | error / warning | `iapl-doctor.json` problems: invalid JSON, an entry without a reason, an expired `until` |
|
||
| — | `doctor-crash` | error (exit 3) | a rule threw |
|
||
|
||
The block rules read `blockLibraryManifest` (`@intecion/ipal-kit/blocks`), so a new library block needs no doctor
|
||
change.
|
||
|
||
### The performance rules are errors (1.18.0)
|
||
|
||
`iapl-doctor` (and `--strict`) fails on every `perf-*` finding. None of them measures time — each reads the
|
||
project's files, the home page's HTML or stored counts — so the same site gives the same answer every run. A project
|
||
that accepts one for a reason lowers or silences it in `iapl-doctor.json`, per rule:
|
||
|
||
```json
|
||
{ "rules": {
|
||
"perf-fonts": { "severity": "warning", "reason": "the client's brand font, replaced in Q1" },
|
||
"perf-embeds": { "off": true, "reason": "the map is the page's content (client decision)", "files": ["src/components/Map.tsx"] },
|
||
"perf-budgets": { "off": true, "reason": "no e2e on this site yet", "until": "2027-03-01" }
|
||
} }
|
||
```
|
||
The `growth` group stays warnings and infos.
|
||
|
||
## Adapt it — `iapl-doctor.json`
|
||
|
||
Every rule can be silenced, lowered or raised — **with a reason** — in `iapl-doctor.json` in the project root
|
||
(a project that has `ipal-doctor.json`, the name before 1.17.0, keeps it: the doctor reads and writes whichever
|
||
of the two exists, `iapl-doctor.json` when both do):
|
||
|
||
```json
|
||
{
|
||
"domain": "example-studio.pl",
|
||
"launched": false,
|
||
"layout": { "allow": ["scripts"], "frontend": "src/app/(site)" },
|
||
"rules": {
|
||
"csp": { "off": true, "reason": "new site: report-only until the reports are clean", "until": "2026-12-01" },
|
||
"i18n-literals": { "off": true, "files": ["src/components/design/**"], "reason": "approved exception: the styleguide labels" },
|
||
"node-22": { "severity": "error", "reason": "we pin Node strictly" }
|
||
},
|
||
"seen": { "csp-report-only": "2026-10-29" },
|
||
"extraRules": ["./scripts/doctor-rules.mjs"]
|
||
}
|
||
```
|
||
|
||
| Key | Meaning |
|
||
|---|---|
|
||
| `domain` | the production domain (dots allowed) — the base of the database names. Without it: a non-local `NEXT_PUBLIC_SERVER_URL`, else the folder name minus `-web` |
|
||
| `launched` | the site is live: seeds must then name their records. Also true when "Project decisions" has a line with "launch" and a date |
|
||
| `growth` | thresholds of the `growth` rules: `maxDocs`, `maxMB`, `maxVersions`, `submissionDays`, `expiredKv`, `orphanedMedia`, `imageCacheMB`, `uploadsMB` ([performance.md](./performance.md) §6) |
|
||
| `layout.allow` | more top-level `src/` entries the convention allows |
|
||
| `layout.frontend` | the folder that holds the site's pages, e.g. `src/app/(site)` — only for a layout the doctor cannot tell (two route groups with pages); the route group's name is otherwise free |
|
||
| `rules.<id>` | `off` (silence), `severity` (`error` / `warning` / `info`), `reason` (**required** — an entry without one is ignored and reported), `until` (ISO date; after it the entry stops applying and the report says so), `files` (globs: only findings in those files). The id is the rule (`csp`) or an audit finding (`audit:collections-present`); `audit` covers all audit findings |
|
||
| `seen` | first-seen dates the doctor stores itself (`csp-report-only`, for the 4-week CSP rule). It writes this key only outside CI (`CI` unset), not with `--json`, and only when the file exists |
|
||
| `extraRules` | your own rule modules (paths relative to the project), each exporting `rules: DoctorRule[]` |
|
||
|
||
Silenced findings stay in the report: in JSON with `"silenced": true` and the reason, in the human output under
|
||
"Silenced", in the summary count. `--strict` does not fail on them.
|
||
|
||
`iapl-audit-skip: <keys> — <reason>` lines in `AGENTS.md` (a client decision, AGENT.md §0b) count too: the audit honours
|
||
its keys, and the doctor maps `twofactor` → `2fa`, `csp` → `csp`, and drops the files of `llms`, `llms-full`, `markdown`,
|
||
`mcp`, `indexnow` from `layout-required`.
|
||
|
||
## JSON (schema 1)
|
||
|
||
```json
|
||
{
|
||
"schema": 1,
|
||
"rulesVersion": "1.15.0",
|
||
"site": { "path": "/…/examplepl-web", "domain": "example.pl", "plugin": "1.15.0" },
|
||
"findings": [
|
||
{ "rule": "db-name", "severity": "error", "source": "static", "message": "…", "file": ".env", "fix": "…", "docs": "docs/deployment.md" }
|
||
],
|
||
"skipped": ["plugin-latest", "deps-audit", "live-health"],
|
||
"summary": { "error": 1, "warning": 0, "info": 0, "silenced": 0 }
|
||
}
|
||
```
|
||
|
||
`source` is `static`, `registry`, `live` or `deep`; `skipped` lists rules that did not run (offline, no `--url`, no
|
||
`--deep`); `reason` and `silenced` appear on silenced findings. With `--sites --json` the output is an array of reports.
|
||
|
||
## In CI
|
||
|
||
New sites only (the starter's and the reference site) gate on the doctor; existing client sites are not changed for it.
|
||
|
||
```yaml
|
||
- run: pnpm install --frozen-lockfile
|
||
- run: pnpm exec iapl-doctor --strict --offline # static, right after install
|
||
# … build, start the app on :3000 with the CI database …
|
||
- run: pnpm exec iapl-doctor --strict --offline --deep --url http://localhost:3000
|
||
```
|
||
|
||
The plugin's own CI does the same for `reference/` (`.gitea/workflows/ci.yml`).
|
||
|
||
## Building blocks — `@intecion/ipal-kit/doctor`
|
||
|
||
Node only. For a project that wraps, filters or extends the checks:
|
||
|
||
```ts
|
||
import { doctorRules, formatReport, runDoctor } from '@intecion/ipal-kit/doctor'
|
||
|
||
const report = await runDoctor({ root: process.cwd(), packageRoot: 'node_modules/@intecion/ipal-kit', offline: true })
|
||
console.log(formatReport(report))
|
||
```
|
||
|
||
`runDoctor`, `runDoctorCli`, `doctorRules`, `applySettings`, `runDeepProbe`, `createDoctorContext`, `loadDoctorConfig`,
|
||
`formatReport`, `formatDriftTable`, `planSkills`, `parseToolOutput`, `AUDIT_RULE_MAP`, `AUDIT_SKIP_RULES`,
|
||
`DEFAULT_SRC_ALLOW`, `findFrontend`, `createLiveFetcher`, `buildDoctorEndpoint`, `collectDoctorStatus`, `globToRegExp`, `parseEnvFile`,
|
||
`readAuditSkips`, `bareHost`, `expandSites`, `parseDoctorArgs`, `DOCTOR_USAGE`; types `DoctorRule`, `DoctorFinding`,
|
||
`DoctorReport`, `DoctorConfig`, `DoctorRuleSetting`, `DoctorSeverity`, `DoctorSource`, `DoctorStatus`, `DoctorContext`,
|
||
`RuleFinding`, `RunDoctorOptions`, `DoctorEndpointOptions`, `FrontendLayout`.
|
||
|
||
## Environment variables
|
||
|
||
| Variable | Where | Effect |
|
||
|---|---|---|
|
||
| `IAPL_DOCTOR_TOKEN` | the site (Coolify), ≥ 32 characters | turns `GET /api/ipal/doctor` on; in the doctor's environment, `--url` uses it to read the deep counts |
|
||
| `CI` | the doctor's environment | set → the doctor never writes `seen` into `iapl-doctor.json` |
|
||
| `NO_COLOR` | the doctor's environment | no colours in the human report |
|
||
| `PAYLOAD_CONFIG_PATH` | the project | `--deep` loads this config instead of `src/payload.config.ts` |
|
||
| `IAPL_DOCTOR_IMPORT_MAP` | internal | set by the doctor for the probe: the committed import map to compare |
|
||
|
||
## Relation to the other checks
|
||
|
||
| Tool | When |
|
||
|---|---|
|
||
| `iapl-audit` | inside the edit loop: is the code I just wrote built the IAPL way (+ tsc and build without `--quick`) |
|
||
| `iapl-seo-check` | what crawlers see on a running site |
|
||
| `iapl-consent-check` | tracking waits for consent (a real browser) — not run by the doctor |
|
||
| `iapl-skills` | copies the skills; the doctor's `skills-current` uses the same comparison (`planSkills`) |
|
||
| **`iapl-doctor`** | the whole site against the team standard: runs `iapl-audit --quick` and (with `--url`) `iapl-seo-check` from the installed package and adds everything they do not check |
|