Merge claude/security-c-1172: form submissions over REST only for staff, the job queue for an admin or Bearer CRON_SECRET, doctor visitor-writes

Conflicts with security-a-1172 kept both sides: imports (adminSameOrigin, jobsAccess), the doctor status (originKnown and visitorWrites), its test, and the e2e:built line (A's sign-in answers spec with C's CRON_SECRET).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
Radosław Smoliński
2026-12-01 11:17:51 +01:00
co-authored by Claude Opus 5.5
40 changed files with 657 additions and 187 deletions
+8 -2
View File
@@ -636,12 +636,18 @@ for visitors. Then, all four:
`access.staffCollections` is for a second collection of STAFF (access.md → "Who is staff").
3. In every auth collection use `adminOrSelfIn('<its slug>')`, not `adminOrSelf`, for "only my own record".
4. Payload's default for a collection or global without `access` is "any logged-in account" — a customer too.
Give every collection and global explicit `access`. 2FA covers the panel's collection only.
Give every collection and global explicit `access` (writes: `adminOrEditor`, as the reference site's collections
and globals do since 1.17.2). Verify with `iapl-doctor --url …` (deep): no `visitor-writes` finding. 2FA covers
the panel's collection only.
5. Never let a sign-up write a field that grants rights (`roles`, `isAdmin`, …): give such a field
`access: { create: adminOnlyField, update: adminOnlyField }`.
6. Check: log in as such an account (`POST /api/customers/login`), then `GET /api/globals/site-integrations`,
`GET /api/form-submissions` and `GET /api/users` with its token must answer `403`, and so must
`POST /api/setup-totp`.
`POST /api/setup-totp`, `POST /api/form-submissions` and (a site with Payload jobs) `GET /api/payload-jobs/run`
(`401`).
7. Payload jobs run over HTTP: since 1.17.2 only an admin or `Authorization: Bearer <CRON_SECRET>` (when the project
writes no `jobs.access.run`). A Coolify scheduled task that calls `/api/payload-jobs/run` sends that header;
`CRON_SECRET` goes into the app's environment (security.md "Payload's job queue").
**NEVER:** a second `media`, `daneFirmy`/`settings`/
`navigation`/`footer` as collections (they are globals), FAQ/hero/features as collections
+19 -56
View File
@@ -279,7 +279,7 @@ Rules: AGENT.md §5, iapl-nav, iapl-collection.
| `src/collections/Pages.ts` | Pages: slug, blocks layout, AI summary, noindex, slug history, revalidation, system-page delete guard (below) |
| `src/collections/Posts.ts` | the blog collection (archive in System pages) (below) |
| `src/collections/entryFields.ts` | shared fields of archive collections (names the entry card reads) (below) |
| `src/globals/Company.ts` | company data (PL market): footer, contact details, LocalBusiness JSON-LD (below) |
| `src/globals/Company.ts` | company data (PL market): footer, contact details, LocalBusiness JSON-LD |
| `src/globals/Footer.ts` | footer navigation global (below) |
| `src/globals/Header.ts` | header navigation global (below) |
@@ -288,7 +288,7 @@ Rules: AGENT.md §5, iapl-nav, iapl-collection.
```ts
import type { CollectionConfig } from 'payload'
import { buildRevalidateHook } from '@intecion/ipal-kit'
import { adminOrEditor, buildRevalidateHook } from '@intecion/ipal-kit'
import { revalidatePath } from 'next/cache'
import { i18nConfig } from '@/i18n.config'
@@ -301,7 +301,8 @@ const revalidate = buildRevalidateHook({ config: i18nConfig, revalidatePath })
export const CaseStudies: CollectionConfig = {
slug: 'caseStudies',
admin: { defaultColumns: ['title', 'publishedAt', 'updatedAt'], useAsTitle: 'title' },
access: { read: () => true },
// write rules of its own: Payload's default is "any signed-in account" — a visitor login collection would reach it (security.md "Visitor accounts")
access: { create: adminOrEditor, delete: adminOrEditor, read: () => true, update: adminOrEditor },
defaultSort: '-publishedAt',
fields: entryFields,
hooks: { afterChange: [revalidate.afterChange], afterDelete: [revalidate.afterDelete] },
@@ -315,6 +316,7 @@ export const CaseStudies: CollectionConfig = {
import type { CollectionConfig } from 'payload'
import {
adminOrEditor,
buildMediaPlaceholderField,
buildMediaPlaceholderHook,
buildOptimizeUploadField,
@@ -325,7 +327,8 @@ import {
/** media.md "Full collection", 1:1. */
export const Media: CollectionConfig = {
slug: 'media',
access: { read: () => true }, // public files; media are served by the app (/api/media/file/…)
// write rules of its own: Payload's default is "any signed-in account" — a visitor login collection would reach it (security.md "Visitor accounts")
access: { create: adminOrEditor, delete: adminOrEditor, read: () => true, update: adminOrEditor }, // public files; media are served by the app (/api/media/file/…)
upload: { focalPoint: true, mimeTypes: ['image/*', 'application/pdf', 'video/mp4', 'video/webm'] },
hooks: {
beforeOperation: [normalizeFilenameHook, buildOptimizeUploadHook(), buildMediaPlaceholderHook()],
@@ -344,6 +347,7 @@ export const Media: CollectionConfig = {
import type { CollectionConfig } from 'payload'
import {
adminOrEditor,
buildNoindexField,
buildPreventDeleteSystemPage,
buildRevalidateHook,
@@ -362,7 +366,8 @@ const revalidate = buildRevalidateHook({ config: i18nConfig, revalidatePath })
export const Pages: CollectionConfig = {
slug: 'pages',
admin: { defaultColumns: ['title', 'slug', 'updatedAt'], useAsTitle: 'title' },
access: { read: () => true },
// write rules of its own: Payload's default is "any signed-in account" — a visitor login collection would reach it (security.md "Visitor accounts")
access: { create: adminOrEditor, delete: adminOrEditor, read: () => true, update: adminOrEditor },
fields: [
{ name: 'title', type: 'text', localized: true, required: true },
buildSlugField({ from: 'title' }),
@@ -385,7 +390,7 @@ export const Pages: CollectionConfig = {
```ts
import type { CollectionConfig } from 'payload'
import { buildRevalidateHook } from '@intecion/ipal-kit'
import { adminOrEditor, buildRevalidateHook } from '@intecion/ipal-kit'
import { revalidatePath } from 'next/cache'
import { i18nConfig } from '@/i18n.config'
@@ -398,7 +403,8 @@ const revalidate = buildRevalidateHook({ config: i18nConfig, revalidatePath })
export const Posts: CollectionConfig = {
slug: 'posts',
admin: { defaultColumns: ['title', 'publishedAt', 'updatedAt'], useAsTitle: 'title' },
access: { read: () => true },
// write rules of its own: Payload's default is "any signed-in account" — a visitor login collection would reach it (security.md "Visitor accounts")
access: { create: adminOrEditor, delete: adminOrEditor, read: () => true, update: adminOrEditor },
defaultSort: '-publishedAt',
fields: entryFields,
hooks: { afterChange: [revalidate.afterChange], afterDelete: [revalidate.afterDelete] },
@@ -431,63 +437,19 @@ export const entryFields: Field[] = [
]
```
### `src/globals/Company.ts`
```ts
import type { GlobalConfig } from 'payload'
import { buildGlobalRevalidateHook, rowLabel } from '@intecion/ipal-kit'
import { revalidatePath } from 'next/cache'
/** Company data for a PL market site: footer, contact block details, LocalBusiness JSON-LD. */
export const Company: GlobalConfig = {
slug: 'company',
access: { read: () => true },
fields: [
{ name: 'name', type: 'text', required: true },
{ name: 'legalName', type: 'text' },
{ name: 'taxId', type: 'text', label: 'NIP' },
{ name: 'taxIdLabel', type: 'text', admin: { description: 'Shown before the tax ID in the footer.' }, defaultValue: 'NIP', label: 'Tax ID label', localized: true },
{
name: 'address',
type: 'group',
fields: [
{ name: 'street', type: 'text' },
{ name: 'postalCode', type: 'text' },
{ name: 'city', type: 'text' },
{ name: 'country', type: 'text', defaultValue: 'PL' },
],
},
{ name: 'phone', type: 'text' },
{ name: 'email', type: 'email' },
{ name: 'hours', type: 'text', localized: true, admin: { description: 'Shown next to the contact form, e.g. "Mon–Fri 9:00–17:00".' } },
{
name: 'socials',
type: 'array',
admin: { components: rowLabel('label', 'Profile'), initCollapsed: true },
labels: { plural: 'Profiles', singular: 'Profile' },
fields: [
{ name: 'label', type: 'text', required: true },
{ name: 'url', type: 'text', required: true },
],
},
],
hooks: { afterChange: [buildGlobalRevalidateHook({ revalidatePath })] },
}
```
### `src/globals/Footer.ts`
```ts
import type { GlobalConfig } from 'payload'
import { buildGlobalRevalidateHook, buildLinkField, rowLabel } from '@intecion/ipal-kit'
import { adminOrEditor, buildGlobalRevalidateHook, buildLinkField, rowLabel } from '@intecion/ipal-kit'
import { revalidatePath } from 'next/cache'
/** iapl-nav: link columns and a note. Legal links come from System pages (getSystemLinks), not from here. */
export const Footer: GlobalConfig = {
slug: 'footer',
access: { read: () => true },
// write rules of its own: Payload's default is "any signed-in account" — a visitor login collection would reach it (security.md "Visitor accounts")
access: { read: () => true, update: adminOrEditor },
fields: [
{
name: 'columns',
@@ -517,13 +479,14 @@ export const Footer: GlobalConfig = {
```ts
import type { GlobalConfig } from 'payload'
import { buildGlobalRevalidateHook, buildLinkField, buildLinksField, rowLabel } from '@intecion/ipal-kit'
import { adminOrEditor, buildGlobalRevalidateHook, buildLinkField, buildLinksField, rowLabel } from '@intecion/ipal-kit'
import { revalidatePath } from 'next/cache'
/** iapl-nav: menu with one submenu level, a CTA button, the mobile menu label. Logo comes from Site settings. */
export const Header: GlobalConfig = {
slug: 'header',
access: { read: () => true },
// write rules of its own: Payload's default is "any signed-in account" — a visitor login collection would reach it (security.md "Visitor accounts")
access: { read: () => true, update: adminOrEditor },
fields: [
{
name: 'navItems',
@@ -46,12 +46,16 @@ const DOORS: Door[] = [
{ 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' },
// IAPL 1.17.2: a staff account only; an open door answers 400 (validation) instead of 403
{ body: { form: NO_ID, submissionData: [] }, closedFor: OUTSIDERS, method: 'POST', name: 'a submission past submitForm', path: '/api/form-submissions', closed: status(403) },
{ 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) },
// a site without jobs: 404. A site WITH jobs (IAPL 1.17.2): refused (401) for everybody but an admin and
// `Authorization: Bearer <CRON_SECRET>` — drop `closed: status(404)` there
{ closedFor: ALL, name: 'Payload\'s job queue', 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) },
]
+3 -1
View File
@@ -95,7 +95,7 @@ description: Complete map of everything @intecion/ipal-kit provides — every ia
| `forms.adminGroup` | `'Forms'` | sidebar group | `false` = Payload default; `admin.group` in overrides wins |
| `forms.fields.*` | on: `checkbox`, `checkboxGroup`, `country`, `date`, `email`, `message`, `number`, `radio`, `select`, `state`, `step`, `text`, `textarea`, `time`; off: `payment` | block types in the builder (all with "Show only when") | `<type>: false`; a block object replaces it; `payment: true` **does nothing** (filtered out) — pass a block object |
| `forms.formOverrides` | Form/Forms labels, `emails` readable by logged-in users only | overrides the `forms` collection (`fields: ({ defaultFields }) => …`, `slug`, `admin`, `access`…) | any `CollectionConfig` |
| `forms.formSubmissionOverrides` | create: logged-in, read: editor+, delete: admin | overrides `form-submissions` | `access.create` etc. wins |
| `forms.formSubmissionOverrides` | create: a staff account with its second factor (since 1.17.2; before: any signed-in account), read: editor+, delete: admin | overrides `form-submissions` | `access.create` etc. wins |
| `forms.redirectRelationships` | none | collections a form can redirect to | `['pages']` |
| `forms.emailLayout` | `false` | `beforeEmail` with a layout (logo, colour, footer) + Site settings → **Emails** tab; `{{*:table}}` readable | `true` |
| `forms.beforeEmail` | none | your own e-mail changes (after the layout) | form-builder function |
@@ -104,6 +104,7 @@ description: Complete map of everything @intecion/ipal-kit provides — every ia
| `forms.consentFieldName` | `'consent'` | name of the GDPR consent field `submitForm` requires (read from `config.custom.ipal`) | `createSubmitAction({ consentFieldName })` / `submitForm` argument wins |
| `consentLog` | **on** (since 1.17.0) | `consent-records` collection + `POST /api/ipal/consent` (rate limit 20/min); Postgres / SQLite: a table, migration in the same deploy | `false` / `{ retentionDays }` (default 1095) |
| `consentLog.collectionOverrides` | none | changes `consent-records`: an object merges `access` / `admin` / `hooks` key by key (your keys win), a function `(collection) => collection` takes over (keep the slug) | e.g. `{ access: { read: ({ req }) => req.user?.email === '[email protected]' } }` — narrows who reads records in a project without roles |
| `jobsRunAccess` | on (since 1.17.2), only when the project writes no `jobs.access.run` | Payload's job queue over HTTP (`/api/payload-jobs/run`, `/handle-schedules`): an admin with the second factor (an admin API key counts) or `Authorization: Bearer <CRON_SECRET>` (16+ chars); before: any signed-in account of any auth collection. In-process runs (`jobs.autoRun`, `payload jobs:run`) unaffected | `false` = Payload's default; `{ secretVar }` = another variable; your own `jobs.access.run` wins. Check: `curl -H "Authorization: Bearer $CRON_SECRET" $URL/api/payload-jobs/run` → 200, without it 401 (security.md "Payload's job queue") |
| `doctor` | on (404 until `IAPL_DOCTOR_TOKEN` is set) | `GET /api/ipal/doctor` — read-only counts for `iapl-doctor --url` (users without TOTP, cookies waiting for approval, versions); Bearer token ≥ 32 characters, rate-limited, never names or values | `false` = no endpoint; `{ tokenVar, access }` (doctor.md) |
| `cookieScanner` | off | `cookie-review` collection, "Scan cookies" box above its list (`CookieScanButton`), `GET`/`POST /api/ipal/cookie-scan`, and (unless `approval: false`) the *Approve cookies* view `/admin/cookie-approval` (`CookieApprovalView`) + `GET`/`POST /api/ipal/cookie-approval` + the dashboard reminder; a scan lists the cookies of the integrations switched on + names looked up in the bundled Open Cookie Database; one **Approve and add** puts the ticked cookies into Cookies → Cookie list (so `<CookieTable>` and the detailed window); never deletes, never overwrites edited text, never duplicates, nothing reaches the banner before approval | `true` / object; after switching on: `pnpm generate:importmap` + `migrate:create`. Check: *Privacy → Cookie review* → **Scan cookies** → "Waiting for approval: N" → **Review and approve** → **Approve and add** → the cookies are in Cookies → Cookie list (cookie-scanner.md) |
| `cookieScanner.adminLayout` | `'combined'` | one *Cookies* entry: *Review and approve* and (with `crawl`) *Site check* tabs on the `cookie-settings` global (`ui` fields, `CookieReviewTab` / `CookieSiteCheckTab`); `cookie-review` and `cookie-crawl` get `admin.group: false` (out of the nav, pages and API kept) | `'separate'`; no migration, `generate:importmap` |
@@ -279,6 +280,7 @@ The plugin's own variables are `IAPL_<NAME>`; a deploy that sets the spelling fr
| `IAPL_IP_HEADER` | `ipHeader: true` + production | rate limit trusts any IP header (spoofing) + warning in prod | env: `cf-connecting-ip` (Cloudflare) / `x-forwarded-for` (Traefik/nginx) |
| `IAPL_COOKIE_SCAN_URL`, `IAPL_COOKIE_SCAN_TOKEN` | `cookieScanner.crawl` (`iaplEnvRules({ cookieCrawl: true })` requires both in production; token ≥ 16 chars) | **Check site** disabled, the box names the missing variable | env; the token also goes into the scanner service's `IAPL_CRAWLER_SITES` as `host=token` |
| `IAPL_DOCTOR_TOKEN` | no; ≥ 32 characters | `GET /api/ipal/doctor` answers 404; with it the endpoint answers a Bearer token, and `iapl-doctor --url` with the same variable reads the deep counts | env (Coolify) and the doctor's shell; also read by the doctor: `CI`, `NO_COLOR`, `PAYLOAD_CONFIG_PATH` (`--deep`), `IAPL_DOCTOR_IMPORT_MAP` (internal) — doctor.md |
| `CRON_SECRET` | no; ≥ 16 characters (name: `jobsRunAccess.secretVar`) | Payload's job queue runs over HTTP only for an admin; the start log says so when the queue is on | env (Coolify); the cron sends `Authorization: Bearer <CRON_SECRET>` to `/api/payload-jobs/run` |
| `IAPL_NOINDEX` | no; `1`/`true`/`yes` **staging/preview only** | — (when set: robots Disallow, meta noindex, `X-Robots-Tag`, IndexNow sends nothing) | staging env |
| `NEXT_PHASE` | set by Next | only tells `next build` from runtime: during the build an unreachable database gives an empty sitemap; at runtime the sitemap throws (route → 503) | do not set by hand |
| `NEXT_RUNTIME` | set by Next | `instrumentation.ts` checks for `nodejs`; missing (scripts, seed) → `buildRevalidateHook` does not revalidate | do not set by hand |
@@ -876,6 +876,9 @@ 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`. |
| `jobsRunAccess({ secretVar? })` | `@intecion/ipal-kit` | The rule iapl puts on `jobs.access.run` when the project writes none: `cronSecretMatches(req, process.env[secretVar])` or an admin with the second factor. Reuse it in your own rule: `run: (a) => jobsRunAccess()(a) \|\| myCheck(a)`. Type `JobsRunAccessOptions`. |
| `withJobsRunAccess(config, options \| false)` / `jobsRunNotice(config)` | `@intecion/ipal-kit` | The config with that rule (only when `jobs.access.run` is missing; marks `custom.iapl.jobsRunDefault`); the start-up line when the queue is on and the secret is missing (null otherwise). |
| `cronSecretMatches(req, secret)`, `CRON_SECRET_ENV`, `CRON_SECRET_MIN_LENGTH` | `@intecion/ipal-kit` | `Authorization: Bearer <secret>` compared in constant time; an unset or shorter-than-16 secret never matches. Default variable `CRON_SECRET`. |
| `runRouteCheck({ config, appDir?, snapshot?, update?, graphql?, cwd?, log? })` | `@intecion/ipal-kit/doctor` | `routes:check`: every public route (REST, GraphQL, Next route files) against the judged snapshot (default `e2e/routes.snapshot.json`); returns 1 on a route nobody judged or an entry without a reason; `update` writes new routes with an empty reason. Template: `iapl-audit/resources/routes.template.ts` (security.md "Routes nobody has judged"). Type `RunRouteCheckOptions`. |
| `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). |
+9
View File
@@ -25,6 +25,15 @@ 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.2:** (1) Payload jobs: if the project has tasks or workflows and a cron calls `/api/payload-jobs/run` (or
`/handle-schedules`) without its own `jobs.access.run`, set `CRON_SECRET` (16+ characters) in the app's environment
and send `Authorization: Bearer <CRON_SECRET>` from the cron; in-process runs (`jobs.autoRun`, `payload jobs:run`)
and an admin's API key need nothing (security.md "Payload's job queue"). Verify: the run route answers 401 without
the header, 200 with it. (2) A front end that posted to `/api/form-submissions` as a customer account (not through
`submitForm`): move it to `submitForm` / `createSubmitAction`, or set `forms.formSubmissionOverrides.access.create`.
(3) A site with a visitor login collection: `iapl-doctor --url …` lists `visitor-writes`; give each listed collection
and global its own write rule (`adminOrEditor`). (4) If the project has `tests/routes.ts`: `update`, judge, commit.
**→ 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`):