Consent compliance: Global Privacy Control honoured, equal choice by default, withdrawal that stops running tools, consent log on by default

- GPC (gpc.ts): read in the browser before the first paint (consentBannerScript) and in the consent store; pages stay
  static. 'honour' (default): no banner, analytics and marketing off, no request to Google or a pixel; an explicit
  choice on the site wins; a grant made without the signal gives way when it appears. 'ask' and false as opt-outs.
- equalChoice defaults to true; a development warning when the banner has no 'reject'.
- Withdrawal: Meta / TikTok / Clarity told at once, listed localStorage / sessionStorage keys removed.
- Clarity gets consentv2 when it loads; ads_data_redaction with the Consent Mode default.
- consentLog on by default (consentLog: false turns it off); SiteProviders posts to it by itself; a missing SQL table
  answers 503 with one log line.
- Default banner text: one sentence on changing the choice and browser settings; the GPC line (PL / EN).
- Doctor: consent-log-migration, consent-banner rules.
- Stats: Sec-GPC over a choice made without it keeps the visitor id out.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
Radosław Smoliński
2026-11-26 13:38:39 +01:00
co-authored by Claude Opus 5.5
parent 41771fd51a
commit 99036eb70c
31 changed files with 1130 additions and 120 deletions
+26 -5
View File
@@ -1,6 +1,7 @@
import type { ReactNode } from 'react'
import type { AnalyticsProps } from '../analytics/Analytics.js'
import type { GpcMode } from '../consent/gpc.js'
import type { ConsentCookieMap } from '../consent/useConsent.js'
import type { LightboxProviderProps } from '../lightbox/LightboxProvider.js'
import type { PageStatsProps } from '../stats/PageStats.js'
@@ -20,7 +21,7 @@ import { TurnstileProvider } from '../turnstile/TurnstileProvider.js'
export type SiteProvidersProps = {
/** `defer` etc. for <Analytics>; `false` = no analytics tags at all. */
analytics?: false | Omit<AnalyticsProps, keyof SiteShell['analytics']>
/** The cookie banner. Default `<CookieBanner />`; pass your own configured one (`equalChoice`, classNames) or `false`. */
/** The cookie banner. Default `<CookieBanner />`; pass your own configured one (`settings`, classNames) or `false`. */
banner?: false | ReactNode
children: ReactNode
/**
@@ -33,6 +34,11 @@ export type SiteProvidersProps = {
cookieButton?: false | ReactNode
/** Extra cookies per category to delete when consent is withdrawn. */
cookieMap?: ConsentCookieMap
/**
* Global Privacy Control: `'honour'` (default), `'ask'` or `false`. See ConsentProvider `gpc` and
* docs/consent.md → Global Privacy Control.
*/
gpc?: GpcMode
/** More site-wide JSON-LD nodes next to shell.jsonLd (e.g. buildNavigationJsonLd). */
jsonLd?: (null | Record<string, unknown> | undefined)[]
/**
@@ -43,8 +49,13 @@ export type SiteProvidersProps = {
* yourself in a client component.
*/
lightbox?: boolean | Omit<LightboxProviderProps, 'children' | 'renderDialog' | 'renderImage'>
/** Consent log endpoint, e.g. '/api/ipal/consent' (iapl consentLog: true). */
logEndpoint?: string
/**
* Consent log endpoint. Default: the site shell's (`shell.consentLogEndpoint`, '/api/ipal/consent' whenever the
* plugin's consent log is on — the default since 1.17.0). `false` = decisions are not posted.
*/
logEndpoint?: false | string
/** Days a choice is kept before the banner asks again. Default 180. */
maxAgeDays?: number
/**
* CSP nonce for a nonce-based policy (createProxy `csp`): read it in the layout
* with `(await headers()).get('x-nonce')`. Goes on the theme script, the cookie
@@ -77,7 +88,7 @@ export type SiteProvidersProps = {
*
* const shell = await getSiteShell(locale)
* <body>
* <SiteProviders shell={shell} logEndpoint="/api/ipal/consent" banner={<CookieBanner equalChoice />}>
* <SiteProviders shell={shell} banner={<CookieBanner settings="detailed" />}>
* <Header … /><main>{children}</main><Footer … />
* </SiteProviders>
* </body>
@@ -92,9 +103,11 @@ export function SiteProviders({
consentCookie,
cookieButton,
cookieMap,
gpc,
jsonLd = [],
lightbox = false,
logEndpoint,
maxAgeDays,
nonce,
preconnect = true,
shell,
@@ -106,7 +119,15 @@ export function SiteProviders({
{theme ? <ThemeScript {...shell.theme} nonce={nonce ?? undefined} /> : null}
{preconnect ? <MediaPreconnect /> : null}
<JsonLdGraph schemas={[...shell.jsonLd, ...jsonLd]} />
<ConsentProvider cookieMap={cookieMap} cookieValue={consentCookie} logEndpoint={logEndpoint} nonce={nonce} texts={shell.consent}>
<ConsentProvider
cookieMap={cookieMap}
cookieValue={consentCookie}
gpc={gpc}
logEndpoint={logEndpoint === false ? undefined : (logEndpoint ?? shell.consentLogEndpoint ?? undefined)}
maxAgeDays={maxAgeDays}
nonce={nonce}
texts={shell.consent}
>
<TurnstileProvider siteKey={shell.turnstileSiteKey}>
{lightbox ? (
<LightboxProvider texts={shell.lightboxTexts} {...(lightbox === true ? {} : lightbox)}>
@@ -16,6 +16,7 @@ import type { FormNotificationTexts } from '../notifications/types.js'
import type { PageMetadata, RobotsOptions, RobotsRules, SitemapEntry, SitemapRouteOptions, SitemapStyleOptions } from '../seo/index.js'
import { getAnalyticsConfig } from '../analytics/getAnalyticsConfig.js'
import { CONSENT_LOG_PATH } from '../consent/consentLog.js'
import { getConsentTexts } from '../consent/getConsentTexts.js'
import { isPathAllowed, isPathVisibleIn } from '../construction/logic.js'
import { pathOf } from '../construction/visibility.js'
@@ -829,6 +830,7 @@ export function createContentHelpers({
return {
analytics,
consent,
consentLogEndpoint: consentLogEndpointOf(payload.config),
formTexts: notifications.form,
jsonLd: jsonLd.map(({ '@context': _context, ...node }) => node),
lightboxTexts: notifications.lightbox,
@@ -909,6 +911,12 @@ export function createContentHelpers({
export type SiteShell = {
analytics: AnalyticsConfig
consent: ConsentTexts
/**
* Where the cookie banner posts each decision (the consent log): '/api/ipal/consent' (with the config's API
* route) while the plugin's consent log is on — the default — or null with `consentLog: false`. Optional so a
* hand-built shell keeps compiling. <SiteProviders> uses it unless `logEndpoint` is given.
*/
consentLogEndpoint?: null | string
formTexts: FormNotificationTexts
/** Site-wide nodes (WebSite, Organization…) for <JsonLdGraph>. */
jsonLd: Record<string, unknown>[]
@@ -921,3 +929,10 @@ export type SiteShell = {
}
export type ContentHelpers = ReturnType<typeof createContentHelpers>
/** The consent log's public path when the plugin added its endpoint (consentLog on), else null. */
function consentLogEndpointOf(config: { endpoints?: unknown; routes?: { api?: string } }): null | string {
const endpoints = Array.isArray(config.endpoints) ? (config.endpoints as Array<{ method?: string; path?: string }>) : []
if (!endpoints.some((e) => e.path === CONSENT_LOG_PATH && e.method === 'post')) {return null}
return `${(config.routes?.api ?? '/api').replace(/\/+$/, '')}${CONSENT_LOG_PATH}`
}