Merge claude/security-c-files-jobs-tests-cfba70: resolved paths in the bins and starter, proxy matcher ends at /, closed doors on the built site, every public route judged

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
Radosław Smoliński
2026-11-26 20:57:50 +01:00
co-authored by Claude Opus 5.5
47 changed files with 1675 additions and 34 deletions
+36
View File
@@ -9,6 +9,42 @@ versions at once, go through every "Requires project changes" section in order,
version you have. A new release = a new section at the top; we remove the oldest ones only
once there are more than 20.
## 1.17.1 — DRAFT (security group C: files, jobs, outside-in tests; not released)
> Draft lines from the IAWL-ideas session C (branch `claude/security-c-files-jobs-tests-cfba70`); the integration
> session merges them with A and B. No option, schema, migration or import-map change. Nothing locks anybody out.
### Security
- **The proxy matcher skipped pages that only start with `api`, `admin` or `_next`.** The documented literal
`'/((?!api|admin|_next|.*\\..*).*)'` did not end those names at "/", so `/administracja`, `/admin-guide` or `/apis`
skipped the proxy: no locale redirect, and on a single-locale site with `createProxy({ csp })` no CSP. The
literal is now `'/((?!(?:api|admin|_next)(?:/|$)|.*\\..*).*)'` (`DEFAULT_PROXY_MATCHER`, the reference site, the
starter, the docs). **Requires a project change:** Next reads the matcher from each site's `proxy.ts`, so paste
the new literal there; `iapl-doctor` reports the old one (`proxy-matcher`, warning).
- **Form files: a program inside a DOCX / XLSX named `setup.exe.` or `setup.exe ` passed** (Windows drops the
trailing dot or space when the file is extracted). Trailing dots and spaces are ignored now.
- **`iapl-skills --dest` compared the paths before resolving links**: `--dest <a link to .>`, `..` or `/` passed
the "not the project root" rule and lost the `iapl-*` folders there. The paths are resolved first; a folder that
is the project root or holds it is refused. A folder elsewhere (shared skills) still works.
- **The starter bundle followed symbolic links**: a link committed under `reference/` would have shipped its
target's content in the published bundle (none existed). Links are refused; `iapl create` also refuses a bundle
path that leaves the new folder.
### Added
- **`routes:check`** — every public route (REST, GraphQL, Next route files) against a committed snapshot with one
reason per entry; fails on a route nobody has judged. `listPublicRoutes`, `listNextRouteFiles`,
`compareRouteSnapshot`, `updateRouteSnapshot` (`@intecion/ipal-kit`), `runRouteCheck` (`@intecion/ipal-kit/doctor`);
a template in the `iapl-audit` skill (security.md "Routes nobody has judged").
- **Closed doors from outside** — a Playwright template that asks every door that must stay closed as an anonymous
visitor, a customer and an editor on a production build (security.md "Closed doors from outside"); in this
repository part of `pnpm e2e:built`, in both bundlers.
- `iapl-doctor` rule **`proxy-matcher`** (above).
### Changed
- The plugin's own `package.json` declares `@swc/core` in `pnpm.ignoredBuiltDependencies`: its install script only
checks the native binary, which the build already has. pnpm no longer asks about it (repository only; no effect on
projects).
## 1.17.0 — the plugin is called IAPL; mail works with no setup
> **Read before upgrading.** In this order: the security follow-ups prepared as 1.16.8 (never released on their
+3 -1
View File
@@ -528,7 +528,7 @@ No abbreviations (`HeroSection`, not `HeroSec`). Do not create `lib/pages.ts`,
1. **`proxy.ts`, never `middleware.ts`.** middleware.ts exists → delete it. Proxy:
`export const proxy = createProxy(i18nConfig, { NextResponse, markdown: true })`, the matcher
as an **inline literal** (`['/((?!api|admin|_next|.*\\..*).*)']`), not an import.
as an **inline literal** (`['/((?!(?:api|admin|_next)(?:/|$)|.*\\..*).*)']`), not an import.
2. **No explicit `<head>` in the layout.** It pushes metadata into `<body>`.
`<MediaPreconnect/>` in `<body>` (React 19 hoists it).
3. **ISR:** `export const revalidate = 3600` in `page.tsx`. Refresh after save:
@@ -1411,6 +1411,8 @@ its own tests). Order from the cheapest:
| Build | `pnpm build` — page routes `●` (SSG), not `ƒ` | before every "done" |
| Smoke (Playwright) | `iapl-audit/resources/smoke.spec.template.ts` → `tests/smoke.spec.ts`: all URLs from the sitemap 200 + title + one h1, 404, GEO routes, banner, form end-to-end | before handover and after every IAPL update |
| 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 |
| 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 |
+26 -2
View File
@@ -265,7 +265,7 @@ import { i18nConfig } from '@/i18n.config'
export const proxy = createProxy(i18nConfig, { markdown: true, NextResponse })
// Inline LITERAL — Next reads the matcher statically (importing DEFAULT_PROXY_MATCHER breaks /admin)
export const config = { matcher: ['/((?!api|admin|_next|.*\\..*).*)'] }
export const config = { matcher: ['/((?!(?:api|admin|_next)(?:/|$)|.*\\..*).*)'] }
```
## Collections and globals
@@ -1164,6 +1164,8 @@ Rules: AGENT.md §8a.
| File | What it shows |
|---|---|
| `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) |
| `e2e/global-setup.ts` | Playwright global setup: resets the test admins and clears their stored 2FA attempt counts before every run, so specs do not depend on run order (below) |
| `e2e/late-staff-fixture.ts` | test fixture, on only with E2E_LATE_STAFF=1: one plugin before iapl (staff collections of the config: roles with one more value, the plugin's roles, roles of the project's own) and one after it (a staff collection without rules, one whose roles field is text, copies of staff collections under new slugs — plain, with rules of their own, one rule used for another operation, other role values, the opt-out, not staff — and a visitor collection with open sign-up) |
@@ -1171,9 +1173,11 @@ Rules: AGENT.md §8a.
| `e2e/mail-relay-fixture.ts` | test fixture, on only with E2E_MAIL_RELAY_URL: points the mail service's client at the stand-in the spec starts; never in a real site (a real site names no address) (below) |
| `e2e/mail-relay-setup.ts` | for the mail-service spec: empties the SMTP fields and the stored token, so the next e-mail enrols and goes through the mail service (local database only) (below) |
| `e2e/mail-relay.spec.ts` | the mail service on a built site: the state block in the panel, the first e-mail through the public confirm route, no token in anything the browser receives |
| `e2e/routes.snapshot.json` | every public route of the site (REST, GraphQL, Next route files) with one line saying who may use it and why — the judged list `routes:check` compares with |
| `e2e/routes.ts` | `routes:check`: the site's public routes against e2e/routes.snapshot.json (`pnpm payload run e2e/routes.ts [update]`; from the repository `pnpm routes:check`) (below) |
| `e2e/smoke.spec.ts` | the smoke tests every release must pass: pages, showcase, forms (also a file sent by e-mail), sitemap, SEO/GEO, headers, consent, 2FA |
| `e2e/smtp-sink.ts` | a local mail sink for the smoke tests: reads what the site really sent (recipients, attachments) |
| `e2e/totp.ts` | RFC 6238 code generator for the 2FA sign-in in the smoke test, and the address of the second test admin (below) |
| `e2e/totp.ts` | RFC 6238 code generator for the 2FA sign-in in the smoke test, and the addresses of the second test admin and the test editor (below) |
| `e2e/two-factor-back.spec.ts` | browser test of the 2FA screens' `back` link (twoFactor.safeBack): a prepared link — script or another host — ends on the admin root, an ordinary one is followed |
| `e2e/two-factor-setup.spec.ts` | browser check of "2FA setup required": the first admin of a fresh site, a new editor, the administrator's reset on the account page |
@@ -1249,6 +1253,23 @@ console.log('[e2e] no SMTP server and no mail-service token: the next e-mail enr
process.exit(0)
```
### `e2e/routes.ts`
```ts
/**
* routes:check — every public route of this site (REST, GraphQL, Next route files) against the judged list in
* e2e/routes.snapshot.json (docs/security.md "Routes nobody has judged"). Reads the config only, never the database.
* pnpm payload run e2e/routes.ts → fails on a route nobody has judged
* pnpm payload run e2e/routes.ts update → adds new routes with an empty reason (judge them), drops gone ones
* (`payload run` drops `--flags`, so the word is `update`.) From the plugin repository: pnpm routes:check [--update],
* also the first step of pnpm e2e:built.
*/
import config from '@payload-config'
import { runRouteCheck } from '@intecion/ipal-kit/doctor'
process.exit(await runRouteCheck({ config: await config, update: process.argv.slice(2).includes('update') }))
```
### `e2e/totp.ts`
```ts
@@ -1270,4 +1291,7 @@ export function totp(secret: string, now = Date.now()): string {
/** The second smoke-test admin (create-test-admin.ts makes both): `e2e-admin@…` → `e2e-admin-2@…`. */
export const secondTestAdmin = (email: string): string => email.replace('@', '-2@')
/** The smoke-test editor (create-test-admin.ts makes it): `e2e-admin@…` → `e2e-admin-editor@…`, role `editor`, the same password and secret. */
export const editorTestAccount = (email: string): string => email.replace('@', '-editor@')
```
+7
View File
@@ -51,6 +51,13 @@ names, env, admin, AGENTS.md, skills, seeds and — with `--url` / `--deep` —
## What the script does not check (do it by hand)
- **Closed doors and judged routes** (security.md "Closed doors from outside", "Routes nobody has judged"):
`resources/closed-doors.spec.template.ts` → `tests/closed-doors.spec.ts` (add the project's own doors; run on a
production build as anonymous, customer and editor) and `resources/routes.template.ts` → `tests/routes.ts`
(`pnpm payload run tests/routes.ts update` once, write a reason per route, commit the snapshot; then
`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.
- **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,105 @@
/**
* Closed doors from outside — every door of the site that must stay CLOSED, asked on a PRODUCTION build (`pnpm build
* && pnpm start`: Payload's GraphQL playground and introspection, among others, behave differently outside
* production) as an anonymous visitor, a customer and an editor (IAPL docs/security.md "Closed doors from outside").
* Copy to tests/closed-doors.spec.ts and run:
*
* BASE_URL=http://localhost:3000 pnpm exec playwright test tests/closed-doors.spec.ts
*
* Callers (each is skipped when its variables are missing):
* anonymous always;
* customer a site with a visitor login collection: E2E_CUSTOMER_COLLECTION (its slug), E2E_CUSTOMER_EMAIL,
* E2E_CUSTOMER_PASSWORD — an existing test account of that collection;
* editor E2E_EDITOR_EMAIL, E2E_EDITOR_PASSWORD, E2E_EDITOR_TOTP_SECRET — a staff test account with the role
* `editor` and a known 2FA secret, on a LOCAL or staging database only (never production accounts).
* Add the project's own doors to DOORS (a custom endpoint, a collection only staff may read, a global with secrets).
* A write door is asked with a body that changes nothing when the door is open (an id that does not exist, `{}`).
*/
import { type APIRequestContext, expect, test } from '@playwright/test'
import { createHmac } from 'node:crypto'
type Caller = 'anonymous' | 'customer' | 'editor'
type Answer = { body: unknown; status: number }
type Door = { body?: unknown; closed?: (a: Answer) => boolean; closedFor: Caller[]; graphql?: string; method?: 'DELETE' | 'GET' | 'PATCH' | 'POST'; name: string; path?: string }
const BASE = (process.env.BASE_URL ?? 'http://localhost:3000').replace(/\/$/, '')
const ALL: Caller[] = ['anonymous', 'customer', 'editor']
const OUTSIDERS: Caller[] = ['anonymous', 'customer']
const NO_ID = '000000000000000000000000' // MongoDB; use 999999999 on Postgres / SQLite
const refused = ({ status }: Answer) => [401, 403, 404].includes(status)
const status = (code: number) => (a: Answer) => a.status === code
const noData = (field: string) => ({ body, status: s }: Answer) => {
const b = body as { data?: Record<string, unknown> | null; errors?: unknown[] } | null
return s >= 400 || Boolean(b?.errors?.length) || b?.data?.[field] == null
}
const DOORS: Door[] = [
// the plugin's own — keep them
{ closedFor: ALL, name: 'Site integrations cannot be read', path: '/api/globals/site-integrations' },
{ body: {}, closedFor: ALL, method: 'POST', name: 'Site integrations cannot be saved', path: '/api/globals/site-integrations' },
{ closedFor: ALL, graphql: '{ SiteIntegration { smtpHost } }', closed: noData('SiteIntegration'), name: 'Site integrations over GraphQL' },
{ closedFor: ALL, name: 'the key-value store (2FA counts, the mail-service token)', path: '/api/payload-kv' },
{ closedFor: ALL, name: 'the consent log', path: '/api/consent-records' },
{ closedFor: ALL, name: 'the deep doctor status without its token', path: '/api/ipal/doctor', closed: status(404) },
{ closedFor: ALL, method: 'POST', name: 'a test e-mail', path: '/api/ipal/test-email', body: { to: '[email protected]' } },
{ closedFor: ALL, name: 'the mail-service status', path: '/api/iapl/mail-relay/status' },
{ closedFor: ALL, method: 'POST', name: 'the crawler\'s call-back without its token', path: '/api/ipal/cookie-crawl/results', body: { jobId: 'x', ok: true } },
{ closedFor: OUTSIDERS, method: 'POST', name: 'a crawl without the schedule\'s token', path: '/api/ipal/cookie-crawl' },
{ closedFor: OUTSIDERS, name: 'form submissions', path: '/api/form-submissions' },
{ body: { email: '[email protected]', password: 'Door-Password-1234', roles: ['admin'] }, closedFor: ALL, method: 'POST', name: 'nobody creates a staff account', path: '/api/users', closed: status(403) },
{ body: { email: '[email protected]', password: 'Door-Password-1234' }, closedFor: ALL, method: 'POST', name: 'the first-user route once an account exists', path: '/api/users/first-register', closed: status(403) },
{ body: {}, closedFor: OUTSIDERS, method: 'POST', name: 'Site settings cannot be saved', path: '/api/globals/site-settings', closed: status(403) },
{ closedFor: ALL, name: 'the GraphQL playground (production)', path: '/api/graphql-playground', closed: status(404) },
{ closedFor: ALL, graphql: '{ __schema { queryType { name } } }', closed: ({ body }) => Boolean((body as { errors?: unknown[] })?.errors?.length), name: 'GraphQL introspection (production)' },
{ closedFor: ALL, name: 'Payload\'s job queue (a site without jobs)', path: '/api/payload-jobs/run', closed: status(404) },
// the project's own doors: add them here
// { closedFor: OUTSIDERS, body: {}, method: 'PATCH', name: 'pages cannot be changed', path: `/api/pages/${NO_ID}`, closed: status(403) },
]
/** RFC 6238 TOTP (SHA-1, 6 digits, 30 s) for a base32 secret. */
function totp(secret: string): string {
const alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567'
let bits = ''
for (const ch of secret.replace(/=+$/, '').toUpperCase()) {bits += alphabet.indexOf(ch).toString(2).padStart(5, '0')}
const key = Buffer.from((bits.match(/.{8}/g) ?? []).map((b) => parseInt(b, 2)))
const counter = Buffer.alloc(8)
counter.writeBigUInt64BE(BigInt(Math.floor(Date.now() / 30_000)))
const h = createHmac('sha1', key).update(counter).digest()
return (((h.readUInt32BE(h[h.length - 1]! & 0xf) & 0x7fffffff) % 1_000_000).toString().padStart(6, '0'))
}
async function signIn(caller: Caller, playwright: { request: { newContext: (o: object) => Promise<APIRequestContext> } }): Promise<APIRequestContext | null> {
const api = await playwright.request.newContext({ baseURL: BASE, extraHTTPHeaders: { origin: BASE } })
const env = process.env
if (caller === 'customer') {
if (!env.E2E_CUSTOMER_COLLECTION || !env.E2E_CUSTOMER_EMAIL || !env.E2E_CUSTOMER_PASSWORD) {return null}
expect((await api.post(`/api/${env.E2E_CUSTOMER_COLLECTION}/login`, { data: { email: env.E2E_CUSTOMER_EMAIL, password: env.E2E_CUSTOMER_PASSWORD } })).status()).toBe(200)
}
if (caller === 'editor') {
if (!env.E2E_EDITOR_EMAIL || !env.E2E_EDITOR_PASSWORD || !env.E2E_EDITOR_TOTP_SECRET) {return null}
expect((await api.post('/api/users/login', { data: { email: env.E2E_EDITOR_EMAIL, password: env.E2E_EDITOR_PASSWORD } })).status()).toBe(200)
expect((await (await api.post('/api/verify-totp', { data: { token: totp(env.E2E_EDITOR_TOTP_SECRET) } })).json()).ok).toBe(true)
}
return api
}
for (const caller of ALL) {
test.describe(`closed doors as ${caller}`, () => {
let api: APIRequestContext | null = null
test.beforeAll(async ({ playwright }) => {
api = await signIn(caller, playwright)
})
for (const door of DOORS.filter((d) => d.closedFor.includes(caller))) {
test(door.name, async () => {
test.skip(!api, `no ${caller} test account configured`)
const res = door.graphql
? await api!.post('/api/graphql', { data: { query: door.graphql } })
: await api!.fetch(door.path!, { data: door.body, maxRedirects: 0, method: door.method ?? 'GET' })
const text = await res.text()
let body: unknown = text
try { body = JSON.parse(text) } catch { /* not JSON */ }
expect((door.closed ?? refused)({ body, status: res.status() }), `${door.graphql ?? door.path} → ${res.status()} ${text.slice(0, 200)}`).toBe(true)
})
}
})
}
@@ -0,0 +1,24 @@
/**
* Routes nobody has judged — every public route of this site (REST, GraphQL, Next route files) against the judged
* list in tests/routes.snapshot.json (IAPL docs/security.md "Routes nobody has judged"). Reads the config, never the
* database: the same on MongoDB, Postgres and SQLite. Copy to tests/routes.ts, then:
*
* pnpm payload run tests/routes.ts update → writes tests/routes.snapshot.json, every route with an EMPTY reason
* (write one line per route: who may use it and why it is open, or that it is closed and to whom)
* pnpm payload run tests/routes.ts → fails on a route nobody has judged or an entry without a reason
*
* Run it in CI and after every Payload / IAPL / plugin upgrade; an upgrade that adds a route fails here until somebody
* judges it (`update` adds it with an empty reason; review the diff). `payload run` drops `--flags`: the word is `update`.
*/
import config from '@payload-config'
import { runRouteCheck } from '@intecion/ipal-kit/doctor'
process.exit(
await runRouteCheck({
config: await config,
snapshot: 'tests/routes.snapshot.json',
// appDir: 'src/app', // where the Next routes live
// graphql: false, // a site that deleted app/(payload)/api/graphql
update: process.argv.slice(2).includes('update'),
}),
)
@@ -865,6 +865,10 @@ Bin: `iapl-doctor` (`pnpm exec iapl-doctor [dir] [--json] [--md] [--strict] [--f
| `runDeepProbe(ctx)` | `@intecion/ipal-kit/doctor` | `pnpm exec payload run …/dist/modules/doctor/probe.js` in the project → `DoctorStatus`. |
| `collectDoctorStatus(payload)` | `@intecion/ipal-kit/doctor` | Read-only counts: `usersWithout2fa`, `pendingCookies`, `plugin`, `node`. |
| `buildDoctorEndpoint({ tokenVar, access })` | `@intecion/ipal-kit/doctor` | `GET /ipal/doctor` (`/api/ipal/doctor`): 404 until the token variable (default `IAPL_DOCTOR_TOKEN`, ≥ 32 chars) is set, Bearer token or `access`, rate-limited. Added by `iapl` unless `doctor: false`. |
| `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`. |
| `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`,
`DoctorSource`, `DoctorStatus`, `DoctorContext`, `RunDoctorOptions`, `DoctorEndpointOptions`, `FrontendLayout`.
+1 -1
View File
@@ -401,7 +401,7 @@ import { createProxy } from '@intecion/ipal-kit'
import { i18nConfig } from '@/i18n.config'
export const proxy = createProxy(i18nConfig, { NextResponse, markdown: true })
// Inline LITERAL (importing DEFAULT_PROXY_MATCHER = 500 on /admin); with adminRoute '/its' write `its` instead of `admin`
export const config = { matcher: ['/((?!api|admin|_next|.*\\..*).*)'] }
export const config = { matcher: ['/((?!(?:api|admin|_next)(?:/|$)|.*\\..*).*)'] }
```
`src/lib/content.ts` = PROGRAMISTA §2.7 1:1: `createContentHelpers({ config, content: contentConfig, i18n: i18nConfig,
baseUrl: process.env.NEXT_PUBLIC_SERVER_URL, markdownAlternate: true, summaryField: 'aiSummary', mcp: { serverName:
+8
View File
@@ -25,6 +25,14 @@ the MANDATORY SET (GEO: llms-full, Markdown, MCP; R2; Turnstile through
`getTurnstileConfig`…). Wire each one according to PROGRAMISTA §2 — it is part of the update,
not an extra. Skip one only with a client decision in `AGENTS.md` (`iapl-audit-skip:`).
**→ 1.17.1:** (1) `src/proxy.ts`: replace the matcher literal with
`['/((?!(?:api|admin|_next)(?:/|$)|.*\\..*).*)']` (i18n.md "Next matcher"; `iapl-doctor` rule `proxy-matcher`).
The old one skipped every page whose first segment only starts with `api`, `admin` or `_next` (`/administracja`):
no locale redirect, no proxy CSP there. Verify on a build: `curl -sI localhost:3000/administracja` → 307 to
`/pl/administracja`; `/admin` and `/api/health` unchanged. (2) If the project has `tests/routes.ts`: run
`pnpm payload run tests/routes.ts update`, judge the new entries, commit (after EVERY Payload / IAPL upgrade). New
projects: add the closed-doors spec and the route check (iapl-audit "What the script does not check").
**1.8.x → 1.9.0 (PROGRAMISTA §6, items 17–21):** `twoFactor.plugin` required;
`getTurnstileConfig` instead of `turnstileSiteKey` (with both keys set the token is
required — check that every form has the widget); `clientIp(await headers())` in
+1 -1
View File
@@ -245,7 +245,7 @@ import { i18nConfig } from '@/i18n.config'
export const proxy = createProxy(i18nConfig, { NextResponse, markdown: true })
// Inline literal — Next analyzes it statically; importing a variable = proxy on /admin → 500
export const config = { matcher: ['/((?!api|admin|_next|.*\\..*).*)'] }
export const config = { matcher: ['/((?!(?:api|admin|_next)(?:/|$)|.*\\..*).*)'] }
```
Sets `x-locale` / `x-pathname`, the language cookie with consent, redirects `/`.
The headers are for dynamic routes (API, route handlers) — in SSG/ISR pages,
+1
View File
@@ -101,6 +101,7 @@ Turn off: `iapl({ doctor: false })`. Adapt: `iapl({ doctor: { tokenVar: 'MY_TOKE
| | `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 |
| | `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`) |
+4 -4
View File
@@ -132,7 +132,7 @@ See [proxy in this section](#proxy-formerly-middleware) below.
> import { createProxy } from '@intecion/ipal-kit'
> import { i18nConfig } from '@/i18n.config'
> export const proxy = createProxy(i18nConfig, { NextResponse, markdown: true }) // markdown: GEO, content.md
> export const config = { matcher: ['/((?!api|admin|_next|.*\\..*).*)'] }
> export const config = { matcher: ['/((?!(?:api|admin|_next)(?:/|$)|.*\\..*).*)'] }
> ```
> Use the manual variant below only when you need your own logic in the proxy.
@@ -171,7 +171,7 @@ export function proxy(req) {
return res
}
export const config = { matcher: ['/((?!api|admin|_next|.*\\..*).*)'] } // = DEFAULT_MIDDLEWARE_MATCHER, inline
export const config = { matcher: ['/((?!(?:api|admin|_next)(?:/|$)|.*\\..*).*)'] } // = DEFAULT_MIDDLEWARE_MATCHER, inline
```
Behavior:
@@ -182,7 +182,7 @@ Behavior:
`DEFAULT_MIDDLEWARE_MATCHER` excludes `api`, `admin`, `_next`, static files.
The `admin` prefix is hard-coded — with a custom `adminRoute` (e.g. `/its`) add
it to the matcher (`'/((?!api|its|_next|.*\\..*).*)'`), otherwise the proxy redirects the admin panel
it to the matcher (`'/((?!(?:api|its|_next)(?:/|$)|.*\\..*).*)'`), otherwise the proxy redirects the admin panel
to `/pl/its`.
## Locale cookie and consent (GDPR)
@@ -398,7 +398,7 @@ in the proxy/middleware file, not an import/variable. Even though the plugin exp
```ts
// proxy.ts — matcher INLINE (not an import)
export const config = { matcher: ['/((?!api|admin|_next|.*\\..*).*)'] }
export const config = { matcher: ['/((?!(?:api|admin|_next)(?:/|$)|.*\\..*).*)'] }
```
Use `DEFAULT_PROXY_MATCHER` as a reference value, but if Next complains
+48
View File
@@ -1106,6 +1106,54 @@ loosens it. **`'all'` checks nothing** — no role and no second factor: whoever
the full text, as before. The components take the same as props
(`details`, `audience`).
## Closed doors from outside (`closed-doors.spec`)
Access rules are tested from OUTSIDE, on a **production build** (`pnpm build && pnpm start`): some doors behave
differently outside production (Payload's GraphQL playground and introspection), and a bundler renames every
function (a rule told apart by its name was skipped there in 1.16.7). The test asks every door that must stay closed
as three callers and fails when one opens:
- **anonymous** — no session;
- **customer** — an account of a visitor login collection (a shop, a member zone), if the site has one;
- **editor** — a staff account with the role `editor`, signed in with the second factor.
**In a project:** copy `.agents/skills/iapl-audit/resources/closed-doors.spec.template.ts` to
`tests/closed-doors.spec.ts`, set the test accounts' variables (the file's header: `E2E_CUSTOMER_*`, `E2E_EDITOR_*`,
local or staging database only) and add the project's own doors to `DOORS`: each names who it is closed for and,
where 401 / 403 / 404 is not the whole story, what a closed answer looks like. A write door is asked with a body
that changes nothing when it is open (a document id that does not exist, `{}`): an open door then answers 404 or
400 instead of 403. Run it before every release and after every Payload / IAPL upgrade. Verify: the run lists one
test per door and caller; temporarily set a collection's `read: () => true` where a door says closed and the test
fails.
**In the plugin repository** it is `reference/e2e/closed-doors.ts` (the doors) and `closed-doors.spec.ts`, run by
`pnpm e2e:built` after a webpack and a Turbopack build; the customer is the late-staff fixture's self-signing-up
`e2e-visitors` collection, the editor `e2e/create-test-admin.ts`'s `…-editor@` account. A door that is still open
for a caller while the owner decides is listed under `openFor` and asserted OPEN (`test.fail`): the day somebody
closes it, the run says "passed unexpectedly" and the entry moves to `closedFor`.
## Routes nobody has judged (`routes:check`)
A Payload, plugin or project change can add a public route without anybody noticing (IAWL idea 34). `routes:check`
lists every door a built config opens — each REST route of every collection, global and root endpoint (Payload's
own and the plugin's), each GraphQL query and mutation, each Next route file with its methods — and compares the list
with a committed snapshot in which **every entry carries one line saying who may use it and why**. It fails on a
route that is not in the snapshot and on an entry without a reason (or one that still says `TODO`); routes that went
away are listed, not failed. The list comes from the config only, never from the database, so it is the same on
MongoDB, Postgres and SQLite.
**In a project:** copy `.agents/skills/iapl-audit/resources/routes.template.ts` to `tests/routes.ts`; `pnpm payload
run tests/routes.ts update` writes `tests/routes.snapshot.json` with an empty reason per route; write the reasons
(the reference site's `e2e/routes.snapshot.json` in the plugin repository shows the style), commit, and run
`pnpm payload run tests/routes.ts` in CI. After an upgrade: `update` again, judge the new entries, review the diff.
(`payload run` drops `--flags`, so the word is `update`.) Building blocks, for a test of your own:
`listPublicRoutes(config, { graphqlSchema, routeFiles })`, `listNextRouteFiles`, `compareRouteSnapshot`,
`updateRouteSnapshot` (`@intecion/ipal-kit`) and `runRouteCheck` (`@intecion/ipal-kit/doctor`, Node only). Verify: add
a root endpoint to the config and the check names it as "not judged".
**In the plugin repository:** `pnpm routes:check` (`--update` after a Payload upgrade) on the reference site, also
the first step of `pnpm e2e:built`; the test fixtures are switched off for it.
## Turn off, override, extend
- **Stored secrets:** `secrets: { writeOnly: false }`, `secrets: { reenterOnChange: false }`; `writeOnlySecret` /