Consent: withdrawal clears tool cookies, policy version, consent log, cookie scan; form input hardening
Consent (GDPR)
- Withdrawing consent now deletes GA/Meta/Ads/Clarity/LinkedIn/TikTok/Hotjar
cookies (prefix patterns) on the host AND parent domains — previously only
the locale cookie was removed and _ga & co. stayed. Projects extend the list
via <ConsentProvider cookieMap>, merged with the defaults.
- Cookie Settings → Policy version: raising it asks every visitor again.
- <CookieBanner equalChoice>: Reject styled like Accept (UODO/EDPB), opt-in.
- Opt-in consent log (ipalKit({ consentLog: true }) + logEndpoint): random id,
choices, version, time — no IP/UA; admin-only collection, retention purge.
- Cookie Settings → Cookies + getCookieTable + unstyled <CookieTable> (/rsc).
- Consent cookie gets Secure on HTTPS; consent id stored with the decision.
- ipal-consent-check: cookie-scan.mjs (before/after consent, known-tool
catalog PL/EN, flags non-necessary cookies set before consent) and
import-cookies.ts into the panel (idempotent, keeps editor edits).
Forms
- Server-side type checks per field from the panel definition: email = one
address (blocks "a@x, b@y" recipient injection into {{email}} confirmations
and CR/LF header injection), select/radio only configured options, numbers,
booleans; objects/arrays rejected; control and bidi characters stripped.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
@@ -37,3 +37,34 @@ się załadować wcześniej tylko z sygnałem Consent Mode „denied” i bez ci
|
||||
|
||||
Skrypt wymaga przycisków z `data-ipal="accept"` / `"reject"` — ma je
|
||||
`CookieBanner` z pluginu. Własny baner w projekcie to naruszenie AGENT.md §7.
|
||||
|
||||
## Lista ciasteczek do polityki cookies (cookie-scan)
|
||||
|
||||
Po każdej zmianie narzędzi (nowy piksel, czat, mapa, wideo) i przed oddaniem strony:
|
||||
|
||||
1. Skan działającej strony (bez zgody i po „Akceptuj wszystko”, strona główna + do 10 stron z sitemapy):
|
||||
```bash
|
||||
node .agents/skills/ipal-consent-check/scripts/cookie-scan.mjs http://localhost:3000 --lang pl
|
||||
```
|
||||
Wynik: `cookie-scan/cookies.json` i `cookie-scan/cookies.md` (tabela). `[ERROR]` = ciasteczko
|
||||
**nie-niezbędne ustawione przed zgodą** — napraw jak w tabeli wyżej. `[WARNING] unknown` —
|
||||
ustal dostawcę i cel, wpisz `category` (`necessary|functional|analytics|marketing`) i `purpose`
|
||||
w `cookies.json`. Nie zgaduj — zapytaj, jeśli nie wiesz.
|
||||
2. Import do panelu (Cookie Settings → Cookies), każdy język osobno (skan z `--lang en` dla angielskiego):
|
||||
```bash
|
||||
LOCALE=pl pnpm payload run .agents/skills/ipal-consent-check/scripts/import-cookies.ts cookie-scan/cookies.json
|
||||
```
|
||||
Łączy po nazwie, nie nadpisuje zmian redaktora (`OVERWRITE=1` wymusza). Nie usuwa ciasteczek,
|
||||
których skan nie widział — to robi redaktor w panelu.
|
||||
3. Strona polityki cookies pokazuje tabelę z panelu — **nie wklejaj listy do treści polityki**:
|
||||
```tsx
|
||||
import { getCookieTable, getConsentTexts } from '@intecion/ipal-kit'
|
||||
import { CookieTable } from '@intecion/ipal-kit/rsc'
|
||||
const rows = await getCookieTable({ payload, locale })
|
||||
<CookieTable rows={rows} categories={texts.categories} labels={/* nagłówki kolumn z panelu */} />
|
||||
```
|
||||
Tabela bez stylów (`classNames` per element). Blok w panelu typu „Cookie table” na stronie
|
||||
polityki to dobre miejsce — wtedy redaktor decyduje, gdzie się pojawi.
|
||||
|
||||
Czas życia: Chrome skraca każde ciasteczko do maks. 400 dni (13 mies.) — skan pokazuje to, co
|
||||
realnie zostaje w przeglądarce. `ipal-a11y` i inne klucze localStorage są wymienione osobno.
|
||||
|
||||
@@ -0,0 +1,176 @@
|
||||
#!/usr/bin/env node
|
||||
// ipal cookie-scan — lists every cookie (and localStorage key) a running site sets, for the cookie policy.
|
||||
// node cookie-scan.mjs <baseUrl> [--pages 10] [--lang pl|en] [--out cookie-scan] [--wait 3000]
|
||||
// Two fresh browser profiles: before any decision, and after "Accept all" (data-ipal="accept").
|
||||
// Pages: the base URL + up to --pages URLs from /sitemap.xml.
|
||||
// Writes <out>/cookies.json (import into the panel: import-cookies.ts) and <out>/cookies.md (table).
|
||||
// Needs Playwright: pnpm add -D playwright && pnpm exec playwright install chromium
|
||||
// Exit code: 0 = ok, 1 = non-necessary cookies set BEFORE consent, 2 = setup problem.
|
||||
import { mkdirSync, writeFileSync } from 'node:fs'
|
||||
import path from 'node:path'
|
||||
|
||||
const args = process.argv.slice(2)
|
||||
if (!args[0] || args.includes('--help') || args.includes('-h')) {
|
||||
console.log('Usage: cookie-scan.mjs <baseUrl> [--pages N] [--lang pl|en] [--out dir] [--wait ms]')
|
||||
process.exit(args[0] ? 0 : 2)
|
||||
}
|
||||
const opt = (name, def) => {
|
||||
const i = args.indexOf(`--${name}`)
|
||||
return i >= 0 ? args[i + 1] : def
|
||||
}
|
||||
const base = args[0].replace(/\/$/, '')
|
||||
const MAX = Number(opt('pages', 10)) || 10
|
||||
const LANG = opt('lang', 'pl') === 'en' ? 'en' : 'pl'
|
||||
const OUT = opt('out', 'cookie-scan')
|
||||
const WAIT = Number(opt('wait', 3000)) || 3000
|
||||
|
||||
let pw
|
||||
for (const mod of ['playwright', 'playwright-core', '@playwright/test']) {
|
||||
try { pw = await import(mod); break } catch { /* next */ }
|
||||
}
|
||||
if (!pw) {
|
||||
console.error('cookie-scan: Playwright not found. Install: pnpm add -D playwright && pnpm exec playwright install chromium')
|
||||
process.exit(2)
|
||||
}
|
||||
const { chromium } = pw.default ?? pw
|
||||
|
||||
// Known cookies → provider, consent category, purpose. `*` = prefix.
|
||||
const T = (pl, en) => ({ en, pl })
|
||||
const CATALOG = [
|
||||
['cookie-consent', 'this site', 'necessary', T('Zapamiętuje Twoją decyzję w sprawie plików cookies.', 'Stores your cookie consent decision.')],
|
||||
['NEXT_LOCALE', 'this site', 'functional', T('Zapamiętuje wybrany język strony.', 'Remembers the selected site language.')],
|
||||
['payload-token', 'this site', 'necessary', T('Sesja zalogowanego redaktora (panel administracyjny).', 'Logged-in editor session (admin panel).')],
|
||||
['__cf_bm', 'Cloudflare', 'necessary', T('Ochrona przed botami.', 'Bot protection.')],
|
||||
['_cfuvid', 'Cloudflare', 'necessary', T('Ochrona przed nadużyciami i limit zapytań.', 'Abuse protection and rate limiting.')],
|
||||
['cf_clearance', 'Cloudflare', 'necessary', T('Potwierdzenie przejścia weryfikacji Cloudflare.', 'Proof of passing a Cloudflare challenge.')],
|
||||
['_ga', 'Google', 'analytics', T('Google Analytics: rozróżnia użytkowników w statystykach.', 'Google Analytics: distinguishes users in statistics.')],
|
||||
['_ga_*', 'Google', 'analytics', T('Google Analytics: stan sesji w statystykach.', 'Google Analytics: session state for statistics.')],
|
||||
['_gid', 'Google', 'analytics', T('Google Analytics: rozróżnia użytkowników (24 h).', 'Google Analytics: distinguishes users (24 h).')],
|
||||
['_gat*', 'Google', 'analytics', T('Google Analytics: ogranicza liczbę zapytań.', 'Google Analytics: throttles request rate.')],
|
||||
['_gcl_*', 'Google', 'marketing', T('Google Ads: przypisanie konwersji do reklam.', 'Google Ads: attributes conversions to ads.')],
|
||||
['_fbp', 'Meta', 'marketing', T('Meta Pixel: pomiar i dopasowanie reklam.', 'Meta Pixel: ad measurement and targeting.')],
|
||||
['_fbc', 'Meta', 'marketing', T('Meta Pixel: zapamiętuje kliknięcie w reklamę.', 'Meta Pixel: stores the ad click.')],
|
||||
['_clck', 'Microsoft Clarity', 'analytics', T('Clarity: identyfikator użytkownika w analizie zachowań.', 'Clarity: user id for behaviour analytics.')],
|
||||
['_clsk', 'Microsoft Clarity', 'analytics', T('Clarity: łączy odsłony w jedną sesję.', 'Clarity: joins page views into a session.')],
|
||||
['CLID', 'Microsoft Clarity', 'analytics', T('Clarity: identyfikator użytkownika.', 'Clarity: user id.')],
|
||||
['MUID', 'Microsoft', 'marketing', T('Microsoft: identyfikator przeglądarki dla reklam.', 'Microsoft: browser id for advertising.')],
|
||||
['_uetsid', 'Microsoft Ads', 'marketing', T('Microsoft Ads: pomiar konwersji (sesja).', 'Microsoft Ads: conversion tracking (session).')],
|
||||
['_uetvid', 'Microsoft Ads', 'marketing', T('Microsoft Ads: pomiar konwersji (użytkownik).', 'Microsoft Ads: conversion tracking (user).')],
|
||||
['li_fat_id', 'LinkedIn', 'marketing', T('LinkedIn Insight: przypisanie konwersji.', 'LinkedIn Insight: conversion attribution.')],
|
||||
['lidc', 'LinkedIn', 'marketing', T('LinkedIn: wybór centrum danych.', 'LinkedIn: data-center routing.')],
|
||||
['bcookie', 'LinkedIn', 'marketing', T('LinkedIn: identyfikator przeglądarki.', 'LinkedIn: browser id.')],
|
||||
['bscookie', 'LinkedIn', 'marketing', T('LinkedIn: bezpieczny identyfikator przeglądarki.', 'LinkedIn: secure browser id.')],
|
||||
['UserMatchHistory', 'LinkedIn', 'marketing', T('LinkedIn Ads: synchronizacja identyfikatorów.', 'LinkedIn Ads: id sync.')],
|
||||
['AnalyticsSyncHistory', 'LinkedIn', 'marketing', T('LinkedIn: synchronizacja z analityką.', 'LinkedIn: analytics sync.')],
|
||||
['_ttp', 'TikTok', 'marketing', T('TikTok Pixel: pomiar reklam.', 'TikTok Pixel: ad measurement.')],
|
||||
['_tt_enable_cookie', 'TikTok', 'marketing', T('TikTok Pixel: sprawdza obsługę cookies.', 'TikTok Pixel: cookie support check.')],
|
||||
['_hj*', 'Hotjar', 'analytics', T('Hotjar: analiza zachowań użytkowników.', 'Hotjar: behaviour analytics.')],
|
||||
['YSC', 'YouTube', 'marketing', T('YouTube: statystyki odtworzeń osadzonych filmów.', 'YouTube: embedded video statistics.')],
|
||||
['VISITOR_INFO1_LIVE', 'YouTube', 'marketing', T('YouTube: szacuje przepustowość, preferencje odtwarzacza.', 'YouTube: bandwidth estimate, player preferences.')],
|
||||
['VISITOR_PRIVACY_METADATA', 'YouTube', 'marketing', T('YouTube: stan zgody użytkownika.', 'YouTube: user consent state.')],
|
||||
]
|
||||
const match = (name) =>
|
||||
CATALOG.find(([pattern]) => (pattern.endsWith('*') ? name.startsWith(pattern.slice(0, -1)) : name === pattern))
|
||||
|
||||
const human = (expires) => {
|
||||
if (!expires || expires < 0) {return LANG === 'pl' ? 'sesja' : 'session'}
|
||||
const days = Math.round((expires * 1000 - Date.now()) / 86_400_000)
|
||||
if (days < 1) {
|
||||
const h = Math.max(1, Math.round((expires * 1000 - Date.now()) / 3_600_000))
|
||||
return LANG === 'pl' ? `${h} godz.` : `${h} h`
|
||||
}
|
||||
if (days < 60) {return LANG === 'pl' ? `${days} dni` : `${days} days`}
|
||||
const months = Math.round(days / 30)
|
||||
if (months < 24) {return LANG === 'pl' ? `${months} mies.` : `${months} months`}
|
||||
const years = Math.round(days / 365)
|
||||
return LANG === 'pl' ? `${years} ${years < 5 ? 'lata' : 'lat'}` : `${years} years`
|
||||
}
|
||||
|
||||
// Pages to visit
|
||||
const pages = [base]
|
||||
try {
|
||||
const xml = await (await fetch(`${base}/sitemap.xml`)).text()
|
||||
for (const m of xml.matchAll(/<loc>\s*([^<\s]+)\s*<\/loc>/g)) {
|
||||
if (pages.length > MAX) {break}
|
||||
if (!pages.includes(m[1])) {pages.push(m[1])}
|
||||
}
|
||||
} catch { /* no sitemap — base only */ }
|
||||
|
||||
let browser
|
||||
try {
|
||||
browser = await chromium.launch()
|
||||
} catch (err) {
|
||||
console.error(`cookie-scan: cannot start Chromium — run: pnpm exec playwright install chromium\n${err.message?.split('\n')[0] ?? err}`)
|
||||
process.exit(2)
|
||||
}
|
||||
const host = new URL(base).hostname.replace(/^www\./, '')
|
||||
|
||||
async function visit(accept) {
|
||||
const ctx = await browser.newContext()
|
||||
const page = await ctx.newPage()
|
||||
const storage = new Set()
|
||||
try {
|
||||
for (const [i, url] of pages.entries()) {
|
||||
await page.goto(url, { waitUntil: 'networkidle', timeout: 30_000 }).catch(() => {})
|
||||
if (accept && i === 0) {
|
||||
const btn = page.locator('[data-ipal="accept"]')
|
||||
if (await btn.count()) {await btn.first().click().catch(() => {})}
|
||||
}
|
||||
await page.waitForTimeout(WAIT)
|
||||
for (const k of await page.evaluate(() => Object.keys(localStorage)).catch(() => [])) {storage.add(k)}
|
||||
}
|
||||
return { cookies: await ctx.cookies(), storage: [...storage] }
|
||||
} finally {
|
||||
await ctx.close()
|
||||
}
|
||||
}
|
||||
|
||||
const before = await visit(false)
|
||||
const after = await visit(true)
|
||||
await browser.close()
|
||||
|
||||
const beforeNames = new Set(before.cookies.map((c) => c.name))
|
||||
const seen = new Map()
|
||||
for (const c of [...before.cookies, ...after.cookies]) {
|
||||
if (seen.has(c.name)) {continue}
|
||||
const known = match(c.name)
|
||||
const firstParty = c.domain.replace(/^\./, '').endsWith(host)
|
||||
seen.set(c.name, {
|
||||
category: known?.[2] ?? 'unknown',
|
||||
domain: c.domain.replace(/^\./, ''),
|
||||
duration: human(c.expires),
|
||||
firstParty,
|
||||
name: c.name,
|
||||
provider: known ? (known[1] === 'this site' ? (LANG === 'pl' ? 'ta strona' : 'this site') : known[1]) : firstParty ? (LANG === 'pl' ? 'ta strona' : 'this site') : c.domain.replace(/^\./, ''),
|
||||
purpose: known?.[3][LANG] ?? '',
|
||||
setBeforeConsent: beforeNames.has(c.name),
|
||||
})
|
||||
}
|
||||
const ORDER = ['necessary', 'functional', 'analytics', 'marketing', 'unknown']
|
||||
const cookies = [...seen.values()].sort((a, b) => ORDER.indexOf(a.category) - ORDER.indexOf(b.category) || a.name.localeCompare(b.name))
|
||||
|
||||
mkdirSync(OUT, { recursive: true })
|
||||
writeFileSync(path.join(OUT, 'cookies.json'), JSON.stringify({ base, cookies, lang: LANG, localStorage: after.storage, pages, scannedAt: new Date().toISOString() }, null, 2))
|
||||
const head = LANG === 'pl'
|
||||
? '| Nazwa | Dostawca | Kategoria | Cel | Czas przechowywania |\n|---|---|---|---|---|'
|
||||
: '| Name | Provider | Category | Purpose | Duration |\n|---|---|---|---|---|'
|
||||
const rows = cookies.map((c) => `| \`${c.name}\` | ${c.provider} | ${c.category} | ${c.purpose || '—'} | ${c.duration} |`)
|
||||
writeFileSync(path.join(OUT, 'cookies.md'), `${head}\n${rows.join('\n')}\n`)
|
||||
|
||||
let errors = 0
|
||||
console.log(`cookie-scan — ${base} (${pages.length} page(s))`)
|
||||
const early = cookies.filter((c) => c.setBeforeConsent && c.category !== 'necessary')
|
||||
if (early.length) {
|
||||
errors += early.length
|
||||
console.log(`\n[ERROR] set BEFORE consent and not necessary (${early.length}) — GDPR: gate it (ConsentScript / Analytics) or classify it as necessary if it truly is`)
|
||||
for (const c of early) {console.log(` ${c.name} (${c.domain}, ${c.category})`)}
|
||||
}
|
||||
const unknown = cookies.filter((c) => c.category === 'unknown')
|
||||
if (unknown.length) {
|
||||
console.log(`\n[WARNING] unknown cookies (${unknown.length}) — find the provider and purpose, set the category in cookies.json before importing`)
|
||||
for (const c of unknown) {console.log(` ${c.name} (${c.domain})`)}
|
||||
}
|
||||
if (after.storage.length) {console.log(`\nlocalStorage keys (mention in the policy if they hold personal data): ${after.storage.join(', ')}`)}
|
||||
console.log(`\n${cookies.length} cookie(s) → ${path.join(OUT, 'cookies.json')}, ${path.join(OUT, 'cookies.md')}`)
|
||||
console.log(`Import into the panel: LOCALE=${LANG} pnpm payload run .agents/skills/ipal-consent-check/scripts/import-cookies.ts ${path.join(OUT, 'cookies.json')}`)
|
||||
process.exit(errors ? 1 : 0)
|
||||
@@ -0,0 +1,59 @@
|
||||
/**
|
||||
* Imports a cookie-scan result into Cookie Settings → Cookies (panel), so the
|
||||
* cookie policy page (<CookieTable>) lists what the site really sets.
|
||||
*
|
||||
* LOCALE=pl pnpm payload run .agents/skills/ipal-consent-check/scripts/import-cookies.ts cookie-scan/cookies.json
|
||||
* # second language: scan again with --lang en, then import with LOCALE=en
|
||||
* # (rows are matched by cookie name; only purpose/duration are localized)
|
||||
*
|
||||
* Merges by cookie name: an editor's own purpose/duration/provider are kept
|
||||
* unless OVERWRITE=1. Cookies no longer seen are kept too (remove them in the
|
||||
* panel) — a scan of a few pages can miss cookies set elsewhere. `unknown`
|
||||
* category rows are skipped: classify them in cookies.json first.
|
||||
*/
|
||||
import config from '@payload-config'
|
||||
import { readFileSync } from 'node:fs'
|
||||
import { getPayload } from 'payload'
|
||||
|
||||
type Scanned = { category: string; duration?: string; name: string; provider?: string; purpose?: string }
|
||||
type Row = { category?: string; duration?: null | string; id?: string; name?: string; provider?: null | string; purpose?: null | string }
|
||||
|
||||
// `payload run` forwards positional args but not --flags — options come from env.
|
||||
const file = process.argv.slice(2).find((a) => a.endsWith('.json'))
|
||||
const locale = process.env.LOCALE
|
||||
const overwrite = process.env.OVERWRITE === '1'
|
||||
if (!file || !locale) {
|
||||
console.error('Usage: LOCALE=<code> [OVERWRITE=1] pnpm payload run import-cookies.ts <cookies.json>')
|
||||
process.exit(2)
|
||||
}
|
||||
|
||||
const scan = JSON.parse(readFileSync(file, 'utf8')) as { cookies: Scanned[] }
|
||||
const payload = await getPayload({ config })
|
||||
const current = (await payload.findGlobal({ slug: 'cookie-settings' as never, depth: 0, locale: locale as never })) as { cookies?: Row[] }
|
||||
const rows: Row[] = [...(current.cookies ?? [])]
|
||||
|
||||
let added = 0
|
||||
let updated = 0
|
||||
let skipped = 0
|
||||
for (const c of scan.cookies) {
|
||||
if (c.category === 'unknown') {
|
||||
skipped++
|
||||
continue
|
||||
}
|
||||
const existing = rows.find((r) => r.name === c.name)
|
||||
if (!existing) {
|
||||
rows.push({ category: c.category, duration: c.duration, name: c.name, provider: c.provider, purpose: c.purpose })
|
||||
added++
|
||||
continue
|
||||
}
|
||||
const pick = (mine: null | string | undefined, theirs?: string) => (overwrite || !mine ? (theirs ?? mine) : mine)
|
||||
existing.provider = pick(existing.provider, c.provider)
|
||||
existing.purpose = pick(existing.purpose, c.purpose)
|
||||
existing.duration = pick(existing.duration, c.duration)
|
||||
if (overwrite) {existing.category = c.category}
|
||||
updated++
|
||||
}
|
||||
|
||||
await payload.updateGlobal({ slug: 'cookie-settings' as never, data: { cookies: rows } as never, locale: locale as never })
|
||||
console.log(`Cookie Settings (${locale}): ${added} added, ${updated} updated, ${skipped} unknown skipped. Review them in the panel.`)
|
||||
process.exit(0)
|
||||
Reference in New Issue
Block a user