# Threat model and known limits

> What consent-kit is built to catch, what each layer stops, and every known limit of every part.

What consent-kit is built to catch, what each layer stops, and every known limit of every part. Read this before you tell anyone what consent-kit guarantees.

## What it is built against

consent-kit is aimed at **drift and accident**, not at a determined adversary inside your own page.

| It is built to catch | It is not built to stop |
| --- | --- |
| A vendor script that starts setting a new cookie | A script that deliberately evades JavaScript hooks |
| A tag that a colleague added without declaring it | A registry that is knowingly false |
| A script that runs before the visitor agreed | What a vendor does with data on its own servers |
| A banner whose "reject" is harder to reach than "accept" | Server-side processing by your own backend |
| A policy that no longer matches the code | A legal basis that does not hold |
| A change to what visitors were told that nobody noticed | A reviewer who signs without reading |

The honest summary: consent-kit makes it hard to be wrong by accident and easy to see when you are. It does not make a site compliant, and it cannot tell whether your registry is complete or your purposes lawful.

## Who is trusted

| Party | Trusted to | Not trusted to |
| --- | --- | --- |
| The registry's authors | Declare what they know | Know everything. The audit exists for what they missed. |
| First-party code | Use the storage facade (the ESLint rule checks it) | Never bypass it. The guard and the policy are behind it. |
| Declared third-party scripts | Load from their declared origin | Keep to the cookies, keys and endpoints declared for them. The guard checks writes, the policy checks destinations. |
| Undeclared origins | Nothing | The policy refuses them. |
| The visitor's browser | Enforce the Content-Security-Policy | Send honest receipts. The receipt endpoint is unauthenticated. |
| People with commit access | Be the sign-off | consent-kit does not verify who edited the review file or recorded a phrase review. |

## What each layer stops

| Layer | Stops | Cannot stop |
| --- | --- | --- |
| Validator | An inconsistent registry: a third-party artefact without a processor, a consent purpose that defaults to granted, a consent-bound stylesheet | A registry that is consistent and wrong |
| Diff, lock, review file | A material change released without a version bump or a sign-off | A person acknowledging a change they did not read |
| ESLint rule | First-party code calling raw storage APIs | Aliased access (`const w = window; w.localStorage…`), third-party code |
| Storage facade | Your code writing an undeclared or unconsented key | Code that does not use it |
| Blocked script tags, embed placeholders | A declared script or iframe loading before consent | A hard-coded `<script src>` or `<iframe>` that bypasses them |
| Inline guard | Undeclared or unconsented writes to cookies and storage, and inserted scripts and iframes, in the top-level document | See [the guard](#the-guard) |
| Content-Security-Policy | Any load from or connection to an undeclared origin | Anything on a declared origin; anything, if the header is not served |
| Audit | Drift that shows up on the pages and interactions it runs | What it did not exercise |
| Receipts | "We cannot show what this visitor chose" | Forged receipts; see [receipts](#receipts) |

## Limits, part by part

### The registry and the validator

- The validator checks consistency, not truth. It cannot know about a cookie you did not declare; only the audit can find one, and only on pages it visits.
- The check for vague purpose descriptions matches a short list of stock phrases in English and German, in full. A vague sentence that is not on the list passes.
- The check for a vague receipt opt-out reason works the same way.
- The registry does not record where the controller is established, so it cannot demand an EU representative.
- The registry does not record where a form posts to. `form-action` is `'self'`; a third-party form target is a manual `csp.allow` entry.
- A storage artefact's `duration` is a declaration for the documents. Nothing enforces it; your own code has to honour it.
- A cookie's declared `duration` is applied when your code writes it through the facade. A third-party script sets its own lifetime; the audit's attribute-drift check compares what it observed.
- `processors[].transferMechanism` is recorded and printed. Whether the mechanism is valid for that transfer is not checked.
- The EU/EEA list is fixed in the code: the EU-27 plus Iceland, Liechtenstein and Norway.

### Stylesheets, fonts and media

- A third-party stylesheet, font or media file cannot be held back until consent by anything consent-kit generates. The validator therefore refuses to bind one to a consent purpose.
- The guard does not police these kinds. They appear in its manifest only so that the audit can tell a declared load from an undeclared one.
- A declared one is fetched on every page view, and its provider learns the visitor's IP address, whatever the visitor chose.

### The Content-Security-Policy

- It protects only a page that is served with it. Delivering the header is your host's job. The audit computes the policy from the registry and does not verify the header your server sent.
- It is origin-level. A path that nothing declares, on an origin that is declared, passes. The guard and the audit work with the declared paths.
- It is the same before and after a decision. It separates declared from undeclared, never consented from unconsented.
- `frame-ancestors` only works as a response header. The `meta` variant in `csp.json` omits it, along with reporting, and does not exist for a report-only policy.
- `upgrade-insecure-requests` is dropped automatically when the registry declares an `http:` URL.
- `'self'` is allowed for every fetch directive. Anything your own origin serves is admitted, including user-uploaded files if you serve those from the same origin.
- `csp.reportOnly: true` blocks nothing. It is for rolling a policy out, not for staying on.
- Every `csp.allow` entry weakens the wall. `'unsafe-inline'` in `script-src` removes most of it.
- No package receives the guard's or the browser's violation reports. You provide the endpoint.

### The guard

The guard is JavaScript in the same page as the code it checks. These limits are stated in its source.

- **Reads are not seen.** Nothing is blocked or recorded when a script reads a cookie or a storage key.
- **Only the top-level document is patched.** A script can take an unpatched API from a fresh iframe. A cross-origin iframe has its own storage, which nothing in your page can reach.
- **Property access on storage is not seen.** `localStorage.foo = 'x'` does not go through `setItem`.
- **`Storage#clear` and `indexedDB.deleteDatabase` are not patched.**
- **Server-set cookies are not seen.** A `Set-Cookie` header and HttpOnly cookies never touch `document.cookie`.
- **Scripts and iframes are noticed after insertion.** For a script the parser inserted, marking it `text/plain` and removing it reliably stops execution. For an element inserted by script, the request may already have started, and a fetched script may still run.
- **No hook for `<link>`, CSS `url()`, `<img>`, `<video>`.**
- **Network requests are never blocked.** They are observed only when asked, to label them for the audit.
- **It must run first, and unmodified.** It is allowed by the hash of its exact text. If a build step changes one byte, the browser refuses it silently and the page has no guard. Only the audit's "runtime guard installed" check notices.
- **In `record` mode, undeclared writes are allowed.** That is the mode's purpose. Do not ship `record` to production by accident; the CLI default is `enforce`.
- **Unconsented writes are blocked but never reported**, in any mode. Reports are about undeclared things.
- **A blocked write fails silently** in every mode but `throw`. A third-party script whose cookie write was ignored gets no error.

### The banner and re-consent

- consent-kit generates configuration for CookieConsent v3 (`vanilla-cookieconsent` 3.3) and depends on its behaviour for showing the banner, storing the choice, activating scripts, erasing cookies and honouring GPC.
- CookieConsent's `autoClear` erases cookies only. localStorage, sessionStorage and IndexedDB are cleared only if your `onChange` calls `storage.clearUnconsented()`.
- `clearUnconsented()` does not remove HttpOnly cookies, IndexedDB databases declared by pattern, or anything undeclared.
- A script that has run cannot be unloaded. After a withdrawal, reload the page.
- Re-consent is global. One revision counter covers all consent purposes: when any of them changes materially, every visitor is asked about all of them again.
- A script can be bound to at most one consent purpose.
- The banner's own strings (button labels, modal titles, the "Strictly necessary" text, table headers) exist in English and German. For any other registry locale the banner shows your purpose titles and descriptions in that locale, and the English strings around them.
- The material-change table is a conservative engineering reading, not a legal test. Overrides can only make it stricter.
- There is no rename detection. A renamed id is a removal and a material addition.

### The storage facade and the ESLint rule

- The facade governs only code that calls it.
- The value-type map is a compile-time claim. Use a type guard to check a stored value at runtime.
- The ESLint rule does not follow aliases: `const w = window; w.localStorage.setItem(…)` and `const d = document; d.cookie = …` are not reported.
- A disable comment silences the rule. Nothing in the CLI or the audit reports disable comments.

### Embeds

- A hard-coded `<iframe>` is not gated; only the guard and the policy stand behind it.
- Withdrawal removes the frame, not the data the vendor stored on its own origin.
- Consent is per category and service, not per embed. Accepting loads every placeholder of that category on every page.

### The audit

The audit is evidence about the runs it made, not a proof about the site.

- Only the pages you list. There is no crawler; the default is `/` alone.
- Only the interactions it knows: the banner, and whatever your exercise file does. Anything behind a login, a form, a scroll position or a timer is not observed.
- Only Chromium, with its defaults.
- It sees an undeclared write only if the write happens. A guard built in `enforce` mode blocks an undeclared cookie or storage write before it lands, and the audit then reports nothing for it. Audit a build made with `--guard-mode record`, as the example site does.
- One short visit per state. A script that waits before acting can be missed.
- Not inside third-party iframes, apart from their cookies.
- Not the server side, and not the content of requests. It records origin and path, not what data a declared request carries.
- Not purposes. Whether a declared artefact really serves the purpose the registry gives it is not something a browser can show.
- Not the policy header your server sent.
- CookieConsent v3 markup only, unless you set other selectors through the programmatic API.
- It checks that each decision sends one well-formed receipt. It does not check that the endpoint stores it.

### Receipts

- The endpoint is unauthenticated by nature. Anyone can send a well-formed receipt with a made-up consent id. The record proves what was received, not who sent it.
- A consent id identifies a browser's consent cookie, not a person.
- No retries. A receipt lost to a network error is gone.
- No receipt is sent for a visitor with the Global Privacy Control signal.
- The request that carries a receipt still carries the visitor's IP address and any cookies for the endpoint's origin. `@consent-kit/server` stores neither; a custom endpoint has to take the same care.
- The timestamp in the body is the visitor's clock.
- JSON with duplicate keys is read the way `JSON.parse` reads it: the last key wins.
- No rate limiting, no bot filtering.
- No retention sweep and no erasure tooling are built. Both are left as planned deletions on the table.
- A lost or rotated HMAC key makes existing rows unreachable by consent id.
- The receiving end must be redeployed with every release, or it refuses receipts for the new policy.
- The example static site's own server only collects receipt bodies for the audit. It is not a receipt store.

### Presets

- A preset does not make a declaration true. `verified` on a fact means a person read it on the cited page on that day, not that anyone watched the tool do it.
- A `draft` preset has not been checked against the live vendor at all. The `plausible` preset is a draft, and its fixture has never been run.
- A `verified` preset was true on the day its fixture last ran. Vendors change.
- The scheduled job that would re-run fixtures against live vendors is not built.
- Two presets cannot share a processor. Consent Mode style adapters are not generated.
- Presets carry no lawful basis. A slot may expect one; binding it differently is a warning, never an error.

### Documents

- Every phrase is an unreviewed draft, written by non-lawyers, until a review of its exact text is recorded. None is recorded as shipped.
- The phrase library is English and German only. Other registry locales get no documents.
- A recorded review covers the wording of a template, not the facts filled into it and not the document's sufficiency.
- consent-kit does not verify who a reviewer is.
- With `dpo: false`, the privacy policy has no section on a data protection officer.
- The changelog entry exists only while there are unreleased changes.

## What no layer covers

- **Server-side processing.** Logs, databases, backups, analytics computed on the server, data forwarded to another service. consent-kit sees the browser.
- **What a vendor does after receiving data.**
- **Data subject requests**, beyond leaving the receipt table queryable.
- **Other browsers' behaviour**, ad blockers, extensions.
- **Mobile apps, emails, PDFs** and anything else that is not a web page served with the generated policy.
- **Whether consent was freely given, specific, informed and unambiguous** in the legal sense. The tool can show that the banner offered a real choice and what was chosen.
- **Whether the lawful basis you declared is the right one.**

## Next

- [FAQ and compliance notes](/docs/manual/faq/)
- [How consent flows at runtime](/docs/manual/concepts/runtime-consent-flow/)
