Files
ipal-kit/src/globals/CookieSettings/fields.ts
T
radoslaw.smolinskiandClaude Opus 5.5 ebf70d49bd 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]>
2026-10-16 02:31:58 +02:00

111 lines
3.2 KiB
TypeScript

import type { Field } from 'payload'
import { CONSENT_CATEGORIES } from '../../modules/consent/categories.js'
/**
* Fields for the CookieSettings global — GDPR consent banner copy, editable
* per locale. The privacy-policy link TARGET is NOT stored here: it comes from
* the pages module (system page role 'privacyPolicy'), keeping one source of
* truth. Only the link's visible text lives here (privacyLinkLabel).
*/
export const cookieSettingsFields: Field[] = [
{
name: 'policyVersion',
type: 'number',
admin: {
description:
'Raise by 1 when you add a tool or change the cookie policy — every visitor is asked for consent again.',
position: 'sidebar',
step: 1,
},
defaultValue: 1,
min: 1,
required: true,
},
{
name: 'message',
type: 'textarea',
admin: {
description: 'Main consent message shown in the banner.',
},
localized: true,
},
{
name: 'settingsTitle',
type: 'text',
admin: {
description: 'Heading for the detailed settings panel.',
},
localized: true,
},
{
name: 'privacyLinkLabel',
type: 'text',
admin: {
description:
'Text of the privacy-policy link in the banner, e.g. "Privacy policy". The link target is the page assigned as Privacy Policy in Site Settings → System Pages. Empty → the page title is used.',
},
localized: true,
},
{
name: 'buttons',
type: 'group',
admin: {
description: 'Button labels.',
},
fields: [
{ name: 'acceptAll', type: 'text', localized: true },
{ name: 'reject', type: 'text', localized: true },
{ name: 'settings', type: 'text', localized: true },
{ name: 'save', type: 'text', localized: true },
{ name: 'back', type: 'text', localized: true },
],
},
{
name: 'categories',
type: 'array',
admin: {
description: 'Per-category titles and descriptions.',
},
fields: [
{
name: 'key',
type: 'select',
options: CONSENT_CATEGORIES.map((c) => ({ label: c, value: c })),
required: true,
},
{ name: 'title', type: 'text', localized: true },
{ name: 'description', type: 'textarea', localized: true },
],
},
{
name: 'cookies',
type: 'array',
admin: {
description:
'Cookies the site uses — shown on the cookie policy page (<CookieTable>). Fill it from a scan: ipal-consent-check → cookie-scan.',
initCollapsed: true,
},
fields: [
{
type: 'row',
fields: [
{ name: 'name', type: 'text', admin: { width: '40%' }, required: true },
{ name: 'provider', type: 'text', admin: { description: 'e.g. Google, this site', width: '30%' } },
{
name: 'category',
type: 'select',
admin: { width: '30%' },
defaultValue: 'necessary',
options: CONSENT_CATEGORIES.map((c) => ({ label: c, value: c })),
required: true,
},
],
},
{ name: 'purpose', type: 'textarea', localized: true },
{ name: 'duration', type: 'text', admin: { description: 'e.g. "2 years", "session"' }, localized: true },
],
labels: { plural: 'Cookies', singular: 'Cookie' },
},
]