Outside-in tests (IAWL ideas 33, 34): closed doors on the built site as anonymous, customer and editor; every public route judged
- reference/e2e/closed-doors.ts + closed-doors.spec.ts: one table of doors, asked by pnpm e2e:built in both bundlers; doors still open while the owner decides are asserted open (test.fail) with their question - listPublicRoutes / listNextRouteFiles / compareRouteSnapshot / updateRouteSnapshot (main entry), runRouteCheck (/doctor) - reference/e2e/routes.ts + routes.snapshot.json (395 routes, one reason each); pnpm routes:check [--update], first step of e2e:built - create-test-admin.ts makes an editor test account - docs: security.md sections, AGENT.md 8a, iapl-audit templates, iapl-upgrade 1.17.1, changelog draft Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
498b3dbf38
commit
2468390538
@@ -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
|
||||
|
||||
@@ -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 |
|
||||
|
||||
|
||||
@@ -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'),
|
||||
}),
|
||||
)
|
||||
@@ -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
|
||||
|
||||
@@ -1078,6 +1078,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` /
|
||||
|
||||
Reference in New Issue
Block a user