Consent log endpoint: body capped at 4 KiB (413), version bounded by the policy version; consent-log-migration a warning

Review C-1: the endpoint, on on every site, parsed a 20 MB body. It now refuses a content-length over
CONSENT_LOG_MAX_BYTES (4096) before reading and reads the stream only up to the cap (readCappedBody), so a missing or
false length cannot make it hold more. A version above Cookie settings' policy version is 400 (the cached version is
read again once, for an editor's fresh raise); versions from 1 up are accepted (pages rendered before a raise).
Review C-2: consent-log-migration is a warning, like every consent check of 1.17.0 (the owner's decision).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
Radosław Smoliński
2026-11-26 14:10:44 +01:00
co-authored by Claude Opus 5.5
parent 9a448ba5df
commit 963464d6cb
10 changed files with 147 additions and 21 deletions
+4 -3
View File
@@ -207,7 +207,7 @@ once there are more than 20.
consent-log`, commit the migration and have it applied when the new container starts (`prodMigrations`, or the start
command `pnpm payload migrate && pnpm start`) — **in the same deploy**. Or set `iapl({ consentLog: false })`. Without
either nothing breaks: the page and the banner work, `POST /api/ipal/consent` answers `503`, the server logs once
"the consent-records table does not exist…", and `iapl-doctor` reports `consent-log-migration` (error). A project
"the consent-records table does not exist…", and `iapl-doctor` reports `consent-log-migration` (warning). A project
that already had `consentLog: true`: nothing. **MongoDB** (the eight client sites): nothing — the collection
appears by itself.
- **Generated types:** where the consent log was off, `payload generate:types` adds the `consent-records` collection
@@ -280,7 +280,8 @@ once there are more than 20.
Cookie Banner Taskforce (2023) found a missing or weaker reject option an infringement for most authorities; a UODO
article repeats it. `equalChoice={false}` restores the secondary look; `iapl-doctor` (`consent-banner`) warns, and a
development console warning names a banner `order` without `'reject'`.
- **Consent log on by default** (`consentLog` — `false` turns it off). `<SiteProviders>` posts every decision to it by
- **Consent log on by default** (`consentLog` — `false` turns it off). The endpoint reads at most 4 KiB of body
(`413` beyond, before anything is parsed) and refuses a `version` above the site's policy version (`400`). `<SiteProviders>` posts every decision to it by
itself: `getSiteShell` gives `consentLogEndpoint` (`'/api/ipal/consent'` with the config's API route, `null` when
the log is off); `logEndpoint={false}` stops one layout. A write without its SQL table answers `503` and logs one line
per process. The posted body gains `gpc`; the record's fields are unchanged.
@@ -343,7 +344,7 @@ once there are more than 20.
- **`maxAgeDays`** on `SiteProviders` / `ConsentProvider` / `useConsent`: the re-ask period (default 180 days).
- **`CONSENT_LOG_PATH`** (`'/ipal/consent'`).
- **Doctor rules** `consent-log-migration` (Postgres / SQLite with the log on and no migration creating
`consent_records`: error) and `consent-banner` (`equalChoice={false}`, an `order` without `'reject'`, `gpc={false}`,
`consent_records`: warning — every consent check of 1.17.0 is a warning) and `consent-banner` (`equalChoice={false}`, an `order` without `'reject'`, `gpc={false}`,
`cookieButton={false}` with no `reopen`, a hand-wired `ConsentProvider` without `logEndpoint`: warnings; `gpc="ask"`:
info; the crawl judging another Consent Mode than the layout: warning).
- **`iapl-consent-check`**: five runs — adds Global Privacy Control, equal prominence (computed size and look of
@@ -187,6 +187,7 @@ Fifteen ready blocks and ten page templates. **Use a library block (or a variant
| `REJECT_ALL_CONSENT` | `@intecion/ipal-kit` | Only `necessary: true` (a copy of `DEFAULT_CONSENT`). |
| `CONSENT_LOG_SLUG` | `@intecion/ipal-kit` | Consent log collection slug: `'consent-records'`. |
| `CONSENT_LOG_PATH` | `@intecion/ipal-kit` | The consent log endpoint's path under the API route: `'/ipal/consent'` (`/api/ipal/consent`). |
| `CONSENT_LOG_MAX_BYTES`, `readCappedBody(request, max?)` | `@intecion/ipal-kit` | The consent log endpoint's body cap (4096 bytes) and the reader it uses: `null` when a declared `content-length` or the stream itself passes the cap (read only up to it), else the text — for your own public JSON endpoint. |
| `resolveConsent(record, signal, mode?)` | `@intecion/ipal-kit` | Pure: what is in effect for a stored record (or `null`), the Global Privacy Control signal and the mode (`'honour'` default / `'ask'` / `false`) → `{ decided, gpc, stale, state }` (type `ResolvedConsent`; mode type `GpcMode`). The table in consent.md → "Global Privacy Control". |
| `gpcFromNavigator()` / `gpcFromHeaders(headers)` | `@intecion/ipal-kit` | The signal: `navigator.globalPrivacyControl === true` (false on the server) / `Sec-GPC: 1` exactly. Read the header only where a response is per visitor (endpoints) — never while rendering a static page. |
| `GPC_CATEGORIES`, `GPC_HEADER` | `@intecion/ipal-kit` | `['analytics', 'marketing']` (what the signal refuses) and `'sec-gpc'`. |
+1 -1
View File
@@ -588,7 +588,7 @@ tracker request. Every decision is now recorded in *Privacy → Consent records*
1. **Postgres / SQLite and the project never had `consentLog` on:** the consent log is now on by default and is a new
table. In the same deploy: `pnpm payload migrate:create consent-log`, commit it, apply it at container start
(`prodMigrations` or `pnpm payload migrate && pnpm start`). Or `iapl({ consentLog: false })`. Without either the site
works, but every choice answers 503 and is not recorded (one log line; `iapl-doctor` error `consent-log-migration`).
works, but every choice answers 503 and is not recorded (one log line; `iapl-doctor` warning `consent-log-migration`).
MongoDB: the collection appears by itself.
2. Every site: `pnpm payload generate:types` adds the `consent-records` collection's types (where it was off) — run it and
commit. No import-map change.
+3 -3
View File
@@ -578,8 +578,8 @@ to add the hook to a config. Nothing to migrate.
| Collection access | `read` / `delete` — admin (without `access`, i.e. no roles: any logged-in account — narrow it with `collectionOverrides`); `create` / `update` — nobody through the API (written only by the endpoint, `overrideAccess`) |
| Endpoint | `POST /api/ipal/consent`, public (no login) |
| Default | on (since 1.17.0); `consentLog: false` = no collection, no endpoint, `shell.consentLogEndpoint` null |
| Body | `{ id: string (hex 16–64), version: int ≥ 1, state: { necessary, functional, analytics, marketing: boolean }, gpc?: boolean }` (`gpc` is accepted and not stored) |
| Responses | `201 { ok: true }`, `400` (bad JSON/validation), `429` (limit 20 requests/min per IP, scope `consent`), `503` (the table does not exist: one log line per server start), `500` |
| Body | `{ id: string (hex 16–64), version: int from 1 to the site's policy version, state: { necessary, functional, analytics, marketing: boolean }, gpc?: boolean }` (`gpc` is accepted and not stored); at most 4 KiB (`CONSENT_LOG_MAX_BYTES`) |
| Responses | `201 { ok: true }`, `400` (bad JSON/validation, a version above the policy version), `413` (body over 4 KiB: refused by `content-length` before reading, or when the stream passes the cap), `429` (limit 20 requests/min per IP, scope `consent`), `503` (the table does not exist: one log line per server start), `500` |
| Cleanup | on a write, at most once per 24 h per process: one `db.deleteMany` for records older than `retentionDays`, **in the background** (the consent write does not wait; an error is logged and the cleanup is retried on the next write) |
The provider sends a record after every decision (`fetch` with `keepalive`, errors ignored —
@@ -601,7 +601,7 @@ pnpm payload migrate # applied at container start (prodMi
Or `iapl({ consentLog: false })` when the project does not want the log. Without the table nothing breaks: the page
and the banner work, each choice answers `503` and the server logs once *"the consent-records table does not
exist — create and apply a migration…"*; `iapl-doctor` reports `consent-log-migration` as an error while no
exist — create and apply a migration…"*; `iapl-doctor` reports `consent-log-migration` (a warning) while no
migration in `src/migrations` creates `consent_records`.
Narrow who reads the records (e.g. a project without roles, only the data protection officer):