Files
ipal-kit/src/modules/consent/scanner/crawl/violations.ts
T
Radosław SmolińskiandClaude Opus 5.5 4bb9c663fd Cookie scanner, phase 2: browser crawl through a shared scanner service
cookieScanner.crawl (opt-in) adds "Crawl site" to the Cookie review box. The
site asks the shared scanner service (services/cookie-crawler: Node +
Playwright, Dockerfile, deployed once on Coolify) to crawl its sitemap pages
twice, with no consent and after "Accept all". The service posts cookies,
storage keys and third-party hosts back to POST /api/ipal/cookie-crawl/results
(bearer token, running job only). No browser in the site.

Findings land as drafts through the same merge rules. Anything stored before
consent that is not necessary, and tracker requests before consent, are
violations, flagged on the review entries from the latest crawl only. The
cookie-crawl global keeps the latest result (no history). A dashboard warning
(CookieCrawlAlert) and an opt-in e-mail through the project's mail adapter
follow a crawl with violations or new unknown cookies. Scheduled crawls: a
Coolify scheduled task with the token. ipalEnvRules({ cookieCrawl: true }).

Also: the six older real-Payload tests no longer leave an orphaned
payload generate:types process (typescript.autoGenerate: false).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-27 15:14:01 +01:00

72 lines
2.3 KiB
TypeScript

import type { CookieStorage } from '../types.js'
import type { CrawlObservation, CrawlRequest } from './result.js'
/**
* Hosts whose requests before consent are a violation. Google's tag hosts are
* separate: with Consent Mode `advanced` (the plugin's default) the Google tag
* loads before consent with every signal denied, which is allowed; with
* `basic` nothing may reach Google before consent.
*/
export const DEFAULT_TRACKER_HOSTS = [
'analytics.tiktok.com',
'bat.bing.com',
'clarity.ms',
'connect.facebook.net',
'facebook.com',
'hotjar.com',
'licdn.com',
'linkedin.com',
'youtube.com',
]
export const GOOGLE_TAG_HOSTS = [
'doubleclick.net',
'google-analytics.com',
'googleadservices.com',
'googlesyndication.com',
'googletagmanager.com',
]
export type CrawlViolation = {
/** Consent category of the cookie or key (null = not classified yet). */
category?: null | string
kind: 'request' | CookieStorage
/** Cookie / key name, or the host for a request. */
name: string
pages: string[]
}
const hostMatches = (host: string, list: string[]) => list.some((h) => host === h || host.endsWith(`.${h}`))
/**
* Violations of one crawl: anything stored before consent whose category is not
* `necessary` (unclassified counts — the editor decides), and requests before
* consent to tracker hosts. `categoryOf` gives the review entry's category after
* the scan merged it (an editor's category wins).
*/
export function findCrawlViolations({
categoryOf,
consentMode = 'advanced',
observations,
requests,
trackerHosts = DEFAULT_TRACKER_HOSTS,
}: {
categoryOf: (o: CrawlObservation) => null | string | undefined
consentMode?: 'advanced' | 'basic'
observations: CrawlObservation[]
requests: CrawlRequest[]
trackerHosts?: string[]
}): CrawlViolation[] {
const out: CrawlViolation[] = []
for (const o of observations) {
if (!o.before) {continue}
const category = categoryOf(o) ?? null
if (category !== 'necessary') {out.push({ name: o.name, category, kind: o.storage, pages: o.pages })}
}
const hosts = consentMode === 'basic' ? [...trackerHosts, ...GOOGLE_TAG_HOSTS] : trackerHosts
for (const r of requests) {
if (r.before && hostMatches(r.host, hosts)) {out.push({ name: r.host, kind: 'request', pages: r.pages })}
}
return out
}