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]>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
4f69f6ed20
commit
4bb9c663fd
@@ -9,19 +9,34 @@ import type { CookieScanSummary } from './types.js'
|
||||
|
||||
import { COOKIE_SCAN_LABELS } from './labels.js'
|
||||
|
||||
type CrawlState = {
|
||||
configured: boolean
|
||||
error: null | string
|
||||
finishedAt: null | string
|
||||
missing: string[]
|
||||
startedAt: null | string
|
||||
status: 'done' | 'failed' | 'idle' | 'running'
|
||||
summary: { newUnknown?: null | number; pages?: null | number; violations?: null | number } | null
|
||||
}
|
||||
|
||||
type Status =
|
||||
| { kind: 'done'; summary: CookieScanSummary }
|
||||
| { kind: 'error' }
|
||||
| { kind: 'idle' }
|
||||
| { kind: 'scanning' }
|
||||
|
||||
const fill = (template: string, values: Record<string, null | number | string>) =>
|
||||
template.replace(/\{(\w+)\}/g, (_, k: string) => String(values[k] ?? ''))
|
||||
|
||||
/**
|
||||
* Admin UI above the Cookie review list (beforeListTable): shows which
|
||||
* integrations a scan covers, takes optional extra cookie names, runs
|
||||
* POST /api/ipal/cookie-scan and reloads the list. Labels in the admin language
|
||||
* (`labels` from the collection config, English fallback).
|
||||
* POST /api/ipal/cookie-scan and reloads the list. With `crawl`, also "Crawl
|
||||
* site" (POST /api/ipal/cookie-crawl) and the latest crawl's status, polled
|
||||
* while it runs. Labels in the admin language (`labels` from the collection
|
||||
* config, English fallback).
|
||||
*/
|
||||
export function CookieScanButton({ labels = COOKIE_SCAN_LABELS }: { labels?: Record<string, CookieScanLabels> }) {
|
||||
export function CookieScanButton({ crawl = false, labels = COOKIE_SCAN_LABELS }: { crawl?: boolean; labels?: Record<string, CookieScanLabels> }) {
|
||||
const { i18n } = useTranslation()
|
||||
const { config } = useConfig()
|
||||
const router = useRouter()
|
||||
@@ -30,6 +45,45 @@ export function CookieScanButton({ labels = COOKIE_SCAN_LABELS }: { labels?: Rec
|
||||
const [names, setNames] = useState('')
|
||||
const [integrations, setIntegrations] = useState<{ key: string; label: string }[] | null>(null)
|
||||
const [status, setStatus] = useState<Status>({ kind: 'idle' })
|
||||
const [crawlState, setCrawlState] = useState<CrawlState | null>(null)
|
||||
const [crawlStarting, setCrawlStarting] = useState(false)
|
||||
const crawlEndpoint = endpoint.replace(/cookie-scan$/, 'cookie-crawl')
|
||||
const when = (iso: null | string) => (iso ? new Date(iso).toLocaleString(i18n.language) : '')
|
||||
|
||||
useEffect(() => {
|
||||
if (!crawl) {return}
|
||||
let stopped = false
|
||||
let wasRunning = false
|
||||
const poll = async () => {
|
||||
try {
|
||||
const res = await fetch(crawlEndpoint, { credentials: 'include' })
|
||||
const data = res.ok ? ((await res.json()) as CrawlState) : null
|
||||
if (stopped || !data) {return}
|
||||
setCrawlState(data)
|
||||
if (wasRunning && data.status !== 'running') {router.refresh()}
|
||||
wasRunning = data.status === 'running'
|
||||
} catch {
|
||||
// offline — try again on the next tick
|
||||
}
|
||||
}
|
||||
void poll()
|
||||
const timer = setInterval(() => void poll(), 3000)
|
||||
return () => {
|
||||
stopped = true
|
||||
clearInterval(timer)
|
||||
}
|
||||
}, [crawl, crawlEndpoint, router])
|
||||
|
||||
const startCrawl = async () => {
|
||||
setCrawlStarting(true)
|
||||
try {
|
||||
await fetch(crawlEndpoint, { credentials: 'include', method: 'POST' })
|
||||
const res = await fetch(crawlEndpoint, { credentials: 'include' })
|
||||
if (res.ok) {setCrawlState((await res.json()) as CrawlState)}
|
||||
} finally {
|
||||
setCrawlStarting(false)
|
||||
}
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
fetch(endpoint, { credentials: 'include' })
|
||||
@@ -93,6 +147,30 @@ export function CookieScanButton({ labels = COOKIE_SCAN_LABELS }: { labels?: Rec
|
||||
<span role="alert" style={{ color: 'var(--theme-error-500, crimson)' }}>✗ {t.scanError}</span>
|
||||
) : null}
|
||||
</div>
|
||||
{crawl ? (
|
||||
<div data-ipal="cookie-crawl" style={{ borderTop: '1px solid var(--theme-elevation-150, #ddd)', marginTop: '1.25rem', paddingTop: '1rem' }}>
|
||||
<p style={{ marginTop: 0 }}>{t.crawlIntro}</p>
|
||||
<div style={{ alignItems: 'center', display: 'flex', flexWrap: 'wrap', gap: '1rem' }}>
|
||||
<button
|
||||
className="btn btn--style-secondary"
|
||||
disabled={!crawlState?.configured || crawlState.status === 'running' || crawlStarting}
|
||||
onClick={startCrawl}
|
||||
style={{ margin: 0 }}
|
||||
type="button"
|
||||
>
|
||||
{t.crawlButton}
|
||||
</button>
|
||||
<span role="status">
|
||||
{crawlState && !crawlState.configured ? `${t.crawlNotConfigured} (${crawlState.missing.join(', ')})` : null}
|
||||
{crawlState?.configured && crawlState.status === 'running' ? fill(t.crawlRunning, { startedAt: when(crawlState.startedAt) }) : null}
|
||||
{crawlState?.configured && crawlState.status === 'done'
|
||||
? fill(t.crawlDone, { finishedAt: when(crawlState.finishedAt), newUnknown: crawlState.summary?.newUnknown ?? 0, pages: crawlState.summary?.pages ?? 0, violations: crawlState.summary?.violations ?? 0 })
|
||||
: null}
|
||||
{crawlState?.configured && crawlState.status === 'failed' ? fill(t.crawlFailed, { error: crawlState.error ?? '' }) : null}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user