Consent compliance: docs, agent guide, skills, changelog, shared behaviour spec, browser check, reference e2e

- docs/consent.md: compliance defaults, Global Privacy Control, withdrawal, consent log on by default and the SQL
  migration; no more "UODO requirement" or "GPC not needed". docs/analytics.md: what Consent Mode advanced sends.
- docs/consent-behaviour-spec.md: the behaviour IAPL and IAWL share, with the 13-item test list.
- CHANGELOG 1.17.0: the SQL migration first, a before → after table for an existing site.
- AGENT.md, iapl-setup / iapl-upgrade / iapl-reference / iapl-consent-check, PROGRAMISTA item 78; reference skills copy.
- iapl-consent-check: Global Privacy Control, equal prominence and withdrawal runs; Google asset warnings.
- Reference site uses the new defaults; e2e for GPC, a stale grant, equal prominence, withdrawal; e2e:built runs every
  consent test in both bundlers. YouTubeEmbed warns in development without a poster.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
Radosław Smoliński
2026-11-26 13:48:19 +01:00
co-authored by Claude Opus 5.5
parent 99036eb70c
commit f5c53e4523
33 changed files with 821 additions and 112 deletions
+129 -27
View File
@@ -45,11 +45,13 @@ when you update them.
Usually one line in the layout (PROGRAMISTA §2.8) — `SiteProviders` (`/rsc`) wires the provider,
banner, button and `Analytics` in the right order, with texts from `getSiteShell(locale).consent`:
```tsx
<SiteProviders shell={await getSiteShell(locale)} logEndpoint="/api/ipal/consent"
banner={<CookieBanner equalChoice classNames={…} />}>{children}</SiteProviders>
<SiteProviders shell={await getSiteShell(locale)}
banner={<CookieBanner settings="detailed" classNames={…} />}>{children}</SiteProviders>
```
`SiteProviders` also takes `cookieMap`, `banner={false}`, `cookieButton={false}`
(or your own element) and `analytics={false | { consentMode, defer, deferTimeoutMs }}`
(or your own element), `gpc` (Global Privacy Control, below), `maxAgeDays` (re-ask period),
`logEndpoint` (default: the shell's consent log endpoint; `false` = not posted) and
`analytics={false | { consentMode, defer, deferTimeoutMs }}`
(`consentMode: 'basic'` = no Google request before consent — see [analytics.md](./analytics.md)).
By hand (your own layout) — the same from the individual parts:
@@ -82,8 +84,10 @@ export default async function Layout({ children, params }) {
`ConsentProvider` — props: `texts` (required, `ConsentTexts` from `getConsentTexts`),
`cookieMap` (extra cookies to delete on withdrawal), `logEndpoint`
(consent log), `nonce` (CSP nonce for the banner's first-paint script), `cookieValue` (optional
server-read cookie — [First paint](#first-paint-the-banner-is-part-of-the-first-render-1170)).
(consent log — pass `"/api/ipal/consent"` when you wire the provider by hand; `SiteProviders` does it itself),
`gpc` (`'honour'` default, `'ask'`, `false` — [Global Privacy Control](#global-privacy-control-1170)),
`maxAgeDays` (days a choice is kept, default 180), `nonce` (CSP nonce for the banner's first-paint script),
`cookieValue` (optional server-read cookie — [First paint](#first-paint-the-banner-is-part-of-the-first-render-1170)).
`CookieBanner` does not render after a decision, `CookieButton` —
the opposite (it shows only after a decision and reopens the banner). Since 1.17.0 the banner is in
the server HTML and painted with the page, not after hydration (next section).
@@ -100,11 +104,11 @@ takes `locale` and optional `labels`; defaults: `COOKIE_TABLE_LABELS` (`@intecio
| `CookieBanner` prop | Default | Description |
|---|---|---|
| `classNames` | — | slots (table below) — a given one replaces the default |
| `equalChoice` | `false` | "Reject" styled as the primary button |
| `equalChoice` | `true` (since 1.17.0) | "Reject" styled like "Accept all"; `false` = the secondary look (before 1.17.0; iapl-doctor warns) |
| `firstPaint` | `true` | banner in the server HTML, decided before the first paint; `false` = nothing until the page has hydrated (as before 1.17.0) |
| `nonce` | provider's | CSP nonce for the first-paint script; default: the one given to `ConsentProvider` / `SiteProviders` |
| `icon` | `true` | cookie icon |
| `order` | `['settings', 'reject', 'accept']` | banner buttons |
| `order` | `['settings', 'reject', 'accept']` | banner buttons; keep `'reject'` (a development warning and iapl-doctor say so when it is missing) |
| `settings` | `'inline'` | `'inline' \| 'modal' \| 'detailed'` |
| `controls` | `'checkbox'` | `'checkbox' \| 'switch'` |
| `settingsActions` | `['back', 'save']` | buttons under the categories (`'accept' \| 'back' \| 'reject' \| 'save'`) |
@@ -116,6 +120,81 @@ moves up by its visible part (`bottomOverlap`), so it never covers footer links.
`--ipal-cookie-button-offset` (from the bottom, default `1rem`), `--ipal-cookie-button-inset` (from the
side, default `1rem`); z-index `--ipal-z-header`. Type `CookieButtonProps`.
## Compliance defaults (1.17.0)
What the plugin now does with no project setting, each with its opt-out. Where the rules come from, and which are
law, regulator guidance or vendor policy: [dev/consent-compliance-proposal.md](./dev/consent-compliance-proposal.md).
The behaviour both IAPL and IAWL follow: [consent-behaviour-spec.md](./consent-behaviour-spec.md).
| Default | Opt-out |
|---|---|
| Global Privacy Control honoured (below) | `gpc="ask"` or `gpc={false}` on `SiteProviders` / `ConsentProvider` |
| "Reject" styled like "Accept all" (`equalChoice`) | `<CookieBanner equalChoice={false} />` |
| Consent log on (`consent-records`, posted by `SiteProviders`) | `iapl({ consentLog: false })`, or `logEndpoint={false}` on one layout |
| Withdrawal tells the running tools (Meta, TikTok, Clarity) and removes listed storage keys | none needed (a fix); `signalVendors` is exported for your own banner |
| Clarity gets its consent signal (`consentv2`) when it loads | — (Clarity needs one for EEA visits since 31 October 2025) |
| `ads_data_redaction` with the Consent Mode default | — (it acts only while `ad_storage` is denied) |
| Default text: "You can change your choice at any time with the cookie button, and set cookie rules in your browser too." | your own text in Cookies → *Banner* → message (the default is used only when it is empty) |
Not changed: Consent Mode stays `'advanced'` by default (the Google tag loads before a choice with every signal
`denied` and sends cookieless pings — [analytics.md](./analytics.md#how-consent-mode-works)); `'basic'` is the option for
"no request to Google before consent". The re-ask period stays 180 days (`maxAgeDays` to change it).
### Global Privacy Control (1.17.0)
Global Privacy Control ([W3C draft](https://www.w3.org/TR/gpc/)) is a browser setting that says "do not sell or
share my data": the browser sends `Sec-GPC: 1` and exposes `navigator.globalPrivacyControl === true`. Brave and
DuckDuckGo send it by default, Firefox on request and in private windows; Chrome and Safari are adding a setting.
In the EU it has no binding force of its own today (in California and eleven more US states it must be honoured);
optional categories are off until opt-in anyway, so the plugin reads it as a **refusal of analytics and marketing
that the visitor did not have to click**, and a choice the visitor makes on the site wins.
| Stored choice | Signal | `gpc: 'honour'` (default) |
|---|---|---|
| none | on | no banner (decided before the first paint), the cookie button; analytics and marketing off; **no request to Google** (also in Consent Mode `advanced`) or a pixel; nothing stored |
| made with the signal on (`gpc: true` in the record) | on | the choice stands, also a grant — the visitor chose it for this site |
| made without the signal (`gpc: false`) that granted analytics or marketing | on | both switched off without asking: cookies and listed storage keys deleted, the tools and Google told, the record rewritten (`gpc: true`) and posted to the consent log |
| from before 1.17.0 (no `gpc` field) | on | stands until it expires or the visitor changes it |
| any | off | stands — the absence of the signal is never consent |
`functional` is not the signal's business (no data is shared): a functional grant stays; with no choice it is off,
as for everyone. In the settings window (cookie button) a line says the signal is honoured
(`texts.gpcNotice`, filled by `getConsentTexts` in Polish or English; `classNames.gpcNotice`); "Accept all" or a
saved category there is the visitor's own choice and is stored with `gpc: true`.
- `gpc="ask"`: the banner is shown as usual (with the line); until a choice nothing is sent to any tracker, Google
included. `gpc={false}`: the signal is ignored (before 1.17.0) — iapl-doctor warns.
- **Static pages stay static.** The signal is read in the browser — by the first-paint script
(`consentBannerScript({ gpc })`) and the consent store — never while rendering a page: the HTML is the same with
and without it, and no `Vary` is needed. In server-read mode (`consentCookie`) a visitor with no stored choice
still gets the hidden banner and the script, because the server cannot know the signal.
- **On the server**, where a response is per visitor anyway: `gpcFromHeaders(headers)` (`Sec-GPC: 1` exactly). The
statistics endpoint uses it: a visitor id is not accepted while the signal overrides a choice made without it.
Reading the header in a layout makes the page dynamic; a cached response that differs by it needs
`Vary: Sec-GPC` (many CDNs then refuse to cache or need a rule) — so don't.
- **Building blocks:** `resolveConsent(record, signal, mode)` (pure, the table above), `gpcFromNavigator()`,
`gpcFromHeaders()`, `GPC_CATEGORIES`, `GPC_HEADER`, types `GpcMode`, `ResolvedConsent` (all `@intecion/ipal-kit`);
`readEffectiveConsent(version, mode)` from `/client` (the stored choice with the signal applied, read live —
for your own tag loader).
- **The site statement** `/.well-known/gpc.json` (optional): `app/.well-known/gpc.json/route.ts` with
`export const GET = gpcWellKnown({ lastUpdate: '2026-11-26' })` (`@intecion/ipal-kit`). The proxy's matcher
usually skips paths with a dot; if yours does not, let this path through.
- Do Not Track is not read (retired by the W3C; removed from Firefox). A site should never *state* that it ignores
browser signals (a German court treated DNT as a valid objection).
### Withdrawal stops what already runs (1.17.0)
When a category goes from on to off (the visitor reopens the settings, or GPC overrides an old grant):
- its cookies are deleted — the built-in list (`DEFAULT_COOKIE_MAP`), `cookieMap`, and the panel's cookie list
(Cookies → *Cookie list*, rows of that category), on this host and every parent domain;
- its **browser storage keys** from the panel's cookie list (rows of type *Local storage* / *Session storage*,
`name*` = prefix) are removed; necessary rows never;
- the tools already running are told: Meta Pixel `fbq('consent', 'revoke')`, TikTok `ttq.revokeConsent()`,
Clarity `clarity('consent', false)` (stops and erases its cookies); granting again on the same page sends
`grant` / `consentv2`. LinkedIn Insight has no such call: it stops with the next page load. Google gets the
Consent Mode update as before. Building blocks: `signalVendors(prev, next)`, `clarityConsent(state)` (`/client`).
## First paint: the banner is part of the first render (1.17.0)
Before 1.17.0 the banner rendered nothing until React had hydrated the page and an effect had read the
@@ -133,6 +212,7 @@ parsed, before the browser paints:
|---|---|---|
| no decision; decision under an older **Policy version**; unreadable or foreign `cookie-consent` | `hidden` removed → banner painted with the page | the same element becomes live (no re-render, no shift: the bar is `position: fixed`) |
| current decision | `display: none` on the banner → never painted | React removes it; `CookieButton` appears |
| no decision, browser sends Global Privacy Control (`gpc: 'honour'`, default) | `display: none` → never painted | React removes it; `CookieButton` appears |
| JavaScript off, or a CSP refused the script | banner stays hidden | with JS: appears after hydration, as before 1.17.0; without JS: no banner (and no tag: every tag is loaded by JS) |
The script decides exactly as `readConsentRecord` does, reads only the consent cookie, stores nothing and
@@ -143,7 +223,7 @@ React hydrates with "no decision" (what the server rendered) and switches to the
before the next paint (`useSyncExternalStore`).
What does **not** change: what counts as consent, when tags load (nothing earlier), the Consent Mode
default (still pushed first), the cookie (`cookie-consent`, `{ id, state, timestamp, version }`), the
default (still pushed first), the cookie (`cookie-consent`, `{ id, state, timestamp, version }`, plus `gpc`), the
consent log, withdrawal, `CookieButton`, the settings window in all three modes, texts per language.
**CSP.** With the header-only policy (`buildSecurityHeaders`, `'unsafe-inline'` for scripts — what
@@ -184,7 +264,7 @@ dynamic anyway (a nonce CSP, signed-in pages). `undefined` (the prop left out) =
| Banner at first paint for a new visitor | yes | yes |
**Your own banner** (AGENT.md §7 says: don't; when you must): `consentBannerScript({ version })` from
`@intecion/ipal-kit` (options: `ConsentBannerScriptOptions` — `version`, `cookieName`) is the same script — put `hidden` and `suppressHydrationWarning` on your banner's root and
`@intecion/ipal-kit` (options: `ConsentBannerScriptOptions` — `version`, `cookieName`, `gpc`) is the same script — put `hidden` and `suppressHydrationWarning` on your banner's root and
the script in a `<script>` as its next sibling; `useConsentContext()` gives `hydrated` (false in the
server render and while hydrating) and `serverRead`.
@@ -466,23 +546,26 @@ to add the hook to a config. Nothing to migrate.
LinkedIn, TikTok, Hotjar…) — also on the parent domain (`.client.com`), where GA stores them.
The project's own cookies: `<ConsentProvider cookieMap={{ marketing: ['_my*'] }}>` (added to the
default list, `*` = prefix).
- **Equal choice:** `<CookieBanner equalChoice />` — "Reject" looks like "Accept all"
(UODO/EDPB requirement: refusing must be as easy as consenting). Off by default so the look of
existing sites does not change; **turn it on in new projects**.
- **Consent log (proof of consent, GDPR Art. 7(1)):** `iapl({ consentLog: true })` or
`iapl({ consentLog: { retentionDays: 730 } })` + `<ConsentProvider logEndpoint="/api/ipal/consent">`
(or `SiteProviders logEndpoint`). It stores a random identifier (the same as in the cookie), the
choices, the policy version and the time — **no IP and no user agent**. *Consent records* collection
(admin only), automatic cleanup after `retentionDays` (default 1095). Details below. Postgres:
`migrate:create`.
- **Equal choice:** "Reject" looks like "Accept all" — **the default since 1.17.0** (`equalChoice={false}`
restores the secondary look). This is the position of the EU data-protection authorities (EDPB Cookie Banner
Taskforce report, 2023: no reject option on a layer that has a consent button is an infringement for a vast
majority of them; colours are judged case by case), repeated in a UODO article (2025); it is regulator guidance,
not a statute, and no UODO or UKE decision on a banner was found.
- **Consent log (proof of consent, GDPR Art. 7(1)):** **on by default since 1.17.0**;
`iapl({ consentLog: { retentionDays: 730 } })` to change it, `consentLog: false` to turn it off.
`SiteProviders` posts every decision there by itself (`shell.consentLogEndpoint`); a hand-wired
`<ConsentProvider>` needs `logEndpoint="/api/ipal/consent"`. It stores a random identifier (the same as in the
cookie), the choices, the policy version and the time — **no IP and no user agent**. *Consent records*
collection (admin only), automatic cleanup after `retentionDays` (default 1095). Details below.
**Postgres / SQLite: a new table** — [create and apply a migration](#postgres-sqlite-the-consent-log-is-a-table).
- **Cookie table** for the policy page: Cookies → *Cookie list* + `getCookieTable` + `<CookieTable>` from `/rsc`.
Fill the list from the panel with the cookie scanner (`cookieScanner` option — one approval adds every cookie found to the list, the table and the detailed window,
[cookie-scanner.md](./cookie-scanner.md)) and check the real site with `iapl-consent-check` → cookie-scan.
- Consent cookie: `cookie-consent` (`CONSENT_COOKIE`), JSON `{ id, state, timestamp, version }`,
`max-age` 180 days (`CONSENT_MAX_AGE`), `samesite=lax`, `Secure` on HTTPS. Consent with another
`max-age` 180 days (`CONSENT_MAX_AGE`; `maxAgeDays` changes it), `samesite=lax`, `Secure` on HTTPS. Since 1.17.0
the record may carry `gpc` (was the signal on when the choice was made). Consent with another
policy version is treated as no decision.
- Global Privacy Control is not needed: in the EU everything except necessary is off by default
anyway until consent.
- Global Privacy Control: honoured by default since 1.17.0 — [above](#global-privacy-control-1170).
## Consent log — details (`consentLog`)
@@ -494,13 +577,30 @@ to add the hook to a config. Nothing to migrate.
| Collection | `consent-records` (`CONSENT_LOG_SLUG`), group *Privacy*; fields `consentId` (index), `version`, `choices.{necessary,functional,analytics,marketing}`, `createdAt` |
| 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) |
| Body | `{ id: string (hex 16–64), version: int ≥ 1, state: { necessary, functional, analytics, marketing: boolean } }` |
| Responses | `201 { ok: true }`, `400` (bad JSON/validation), `429` (limit 20 requests/min per IP, scope `consent`), `500` |
| 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 process), `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 —
the banner never waits). By hand: `buildConsentLogCollection()` / `buildConsentLogEndpoint(opts)`
from `@intecion/ipal-kit`.
from `@intecion/ipal-kit`; `CONSENT_LOG_PATH` is the endpoint's path under the API route (`/ipal/consent`).
### Postgres / SQLite: the consent log is a table
On MongoDB the collection appears by itself. On a SQL database `consent-records` is a table (`consent_records`
plus `consent_records_choices`… as Payload names them), so the deploy that brings 1.17.0 to a project that never had
`consentLog` on must create it — **in the same deploy**, before the new version serves requests:
```bash
pnpm payload migrate:create consent-log # commit the file in src/migrations/
pnpm payload migrate # applied at container start (prodMigrations, or `pnpm payload migrate && pnpm start`)
```
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
migration in `src/migrations` creates `consent_records`.
Narrow who reads the records (e.g. a project without roles, only the data protection officer):
@@ -516,9 +616,10 @@ iapl({
- **Turn off:** do not mount `CookieBanner` / `CookieButton` (or `SiteProviders banner={false}
cookieButton={false}`). The `cookie-settings` global is currently always added (no option to drop
it); the consent log only with `consentLog`.
it); the consent log with `consentLog: false`; Global Privacy Control with `gpc={false}`.
- **Override:** texts and the cookie list in the panel; the look with `--ipal-*` tokens and `classNames`;
the layout with the props `order`, `settings`, `controls`, `settingsActions`, `equalChoice`, `icon`;
`gpc` and `maxAgeDays` on the provider;
the log's `retentionDays`; `privacyPolicy` / `settingsSlug` in `getConsentTexts`. The `cookie-settings`
global (write access is `admin` + `editor` by default, hooks, admin options):
`iapl({ globalOverrides: { 'cookie-settings': { access: { update } } } })` — your access rules win,
@@ -532,5 +633,6 @@ iapl({
warning, optional e-mail ([cookie-scanner.md → Browser crawl](./cookie-scanner.md#browser-crawl)).
- **Extend:** `cookieMap` (your own cookies to delete), `ConsentScript` (scripts without Consent
Mode), `useConsentContext()` (your own UI: `state`, `acceptAll`, `rejectAll`, `savePreferences`,
`reopen`, `texts`), server-safe helpers (`parseConsent`, `readConsentRecord`, `CONSENT_COOKIE`,
`getCookieTable`) and the builders `buildConsentLogCollection` / `buildConsentLogEndpoint`.
`reopen`, `texts`, `gpc`, `gpcMode`), server-safe helpers (`parseConsent`, `readConsentRecord`, `CONSENT_COOKIE`,
`getCookieTable`, `resolveConsent`, `gpcFromHeaders`) and the builders `buildConsentLogCollection` /
`buildConsentLogEndpoint`.