# 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 ` | 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 ` | with `--url`: the panel path (default `/admin`) | | `--deep` | read-only database checks through `pnpm exec payload run` (below) | | `--env-file ` | a production env export (e.g. copied from Coolify): its `DATABASE_URI` must name `_prod` | | `--only `, `--skip ` | run or leave out rules or whole groups | | `--sites ` | 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 `, 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) } })` (only a literal `true` allows since 1.18.0 — `req.user` refuses; `strictAccessAnswers: false` = the old truthy reading) (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/()` (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 `_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 `