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:
@@ -5,6 +5,8 @@ type FormField = {
|
||||
blockType?: string
|
||||
label?: string
|
||||
name?: string
|
||||
/** select / radio choices defined in the panel. */
|
||||
options?: { value?: unknown }[] | null
|
||||
required?: boolean | null
|
||||
}
|
||||
|
||||
@@ -24,7 +26,7 @@ export type FormValidationResult =
|
||||
| {
|
||||
/** Offending field, when a single field is at fault. */
|
||||
field?: string
|
||||
kind: 'required' | 'too_long' | 'unknown_fields'
|
||||
kind: 'invalid_format' | 'required' | 'too_long' | 'unknown_fields'
|
||||
ok: false
|
||||
reason: 'invalid'
|
||||
}
|
||||
@@ -47,6 +49,60 @@ const CAPTCHA_KEYS = new Set(['cf-turnstile-response', 'g-recaptcha-response'])
|
||||
/** Hard ceiling on a single field's length, independent of the form config. */
|
||||
const MAX_FIELD_LENGTH = 5000
|
||||
|
||||
/**
|
||||
* ONE address, nothing else. The form-builder can send a confirmation to
|
||||
* `{{email}}`, so a value like "[email protected], [email protected]" or one with a line break would
|
||||
* turn the site into a spam relay (and CR/LF into header injection). Commas,
|
||||
* semicolons, whitespace and angle brackets are rejected outright.
|
||||
*/
|
||||
const EMAIL = /^[^\s@,;<>"()[\]\\]+@[^\s"(),;<>@[\\\]][^\s"(),.;<>@[\\\]]*\.[^\s"(),;<>@[\\\]]{2,}$/
|
||||
const MAX_EMAIL_LENGTH = 254
|
||||
|
||||
// Control characters except tab and line breaks (U+0000–U+001F, U+007F), plus
|
||||
// bidi overrides that can disguise text in the admin panel and e-mails.
|
||||
// eslint-disable-next-line no-control-regex
|
||||
const CONTROL = /[\u0000-\u0008\v\f\u000E-\u001F\u007F\u202A-\u202E\u2066-\u2069]/g
|
||||
|
||||
type Checked = { error?: 'invalid_format'; value?: unknown }
|
||||
|
||||
/**
|
||||
* Type-checks one value against its field's block type, as defined in the
|
||||
* panel, and normalizes it. Anything not a plain value for that type is
|
||||
* rejected — a hand-crafted request can't smuggle objects, extra recipients or
|
||||
* values outside a select's options.
|
||||
*/
|
||||
function checkValue(field: FormField, value: unknown): Checked {
|
||||
if (value === undefined || value === null || value === '') {return { value }}
|
||||
switch (field.blockType) {
|
||||
case 'checkbox':
|
||||
return typeof value === 'boolean' ? { value } : { error: 'invalid_format' }
|
||||
case 'email': {
|
||||
if (typeof value !== 'string') {return { error: 'invalid_format' }}
|
||||
const email = value.trim()
|
||||
return email.length <= MAX_EMAIL_LENGTH && EMAIL.test(email) ? { value: email } : { error: 'invalid_format' }
|
||||
}
|
||||
case 'number': {
|
||||
const n = typeof value === 'number' ? value : typeof value === 'string' && value.trim() !== '' ? Number(value) : NaN
|
||||
return Number.isFinite(n) ? { value: n } : { error: 'invalid_format' }
|
||||
}
|
||||
case 'radio':
|
||||
case 'select': {
|
||||
if (typeof value !== 'string' && typeof value !== 'number') {return { error: 'invalid_format' }}
|
||||
const allowed = (field.options ?? []).map((o) => String(o?.value))
|
||||
// No options configured → nothing to compare against; still a plain value.
|
||||
return allowed.length === 0 || allowed.includes(String(value)) ? { value } : { error: 'invalid_format' }
|
||||
}
|
||||
case 'textarea':
|
||||
return typeof value === 'string' ? { value: value.replace(CONTROL, '') } : { error: 'invalid_format' }
|
||||
default:
|
||||
// text, country, state and custom blocks: one line of plain text.
|
||||
if (typeof value === 'number') {return { value }}
|
||||
return typeof value === 'string'
|
||||
? { value: value.replace(CONTROL, '').replace(/[\r\n]+/g, ' ') }
|
||||
: { error: 'invalid_format' }
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Default name for a GDPR consent field. A checkbox with this name is treated
|
||||
* as a consent gate: it MUST be checked for the submission to go through,
|
||||
@@ -116,10 +172,15 @@ export async function validateSubmission(
|
||||
return { field: field.name, kind: 'too_long', ok: false, reason: 'invalid' }
|
||||
}
|
||||
|
||||
const checked = field.name === consentFieldName ? { value } : checkValue(field, value)
|
||||
if (checked.error) {
|
||||
return { field: field.name, kind: checked.error, ok: false, reason: 'invalid' }
|
||||
}
|
||||
|
||||
// Only carry through keys that belong to the form — unknown keys from a
|
||||
// hand-crafted request are dropped, not stored.
|
||||
if (value !== undefined) {
|
||||
cleaned[field.name] = value
|
||||
if (checked.value !== undefined) {
|
||||
cleaned[field.name] = checked.value
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user