Skip to content

Legal 0.6.0: Consent recorded on the server, Cookie Policy from what modules declare

Legal 0.6.0 records each visitor’s cookie decision on the server, not only in the browser, and writes the Cookie Policy from what your site’s modules say they collect instead of a fixed list.

The server keeps a record

Until now the banner kept a decision only in the visitor’s browser. Now each decision is also sent to /api/consent under PhoenixKit’s URL prefix. The server sets a signed first-party cookie, pk_consent, and writes one consent log row per category. Requests must come from the same site, only known categories are accepted, writes are rate-limited, and an unchanged decision is not logged twice.

Server code can ask what a visitor agreed to with Legal.Consent.status/2, read/1 and objected?/1, without a database query. objected?/1 is true when the browser sends Sec-GPC: 1.

The settings page gets a Record of decisions block:

  • Keep a log of each decision
  • Keep the visitor’s IP address with it (off by default)
  • Keep a hash of the browser’s User-Agent with it
  • Reload the page when a visitor takes a consent back
  • Ask again after (days), 180 by default

Every settings change now records the admin who made it in core’s settings history.

What this site collects

Modules now declare what they collect through data_collection/0. The banner’s preferences dialog, a new What this site collects list on the settings page and the generated Cookie Policy all read the same declarations. The Cookie Policy no longer names Google and Facebook cookies a site may not have. When the declarations change after the policy was generated, the settings page says so and asks you to generate it again. If the list cannot be gathered, generation fails instead of writing an empty policy.

Fixes

Withdrawing a consent now applies at once, Google Consent Mode included, and reaches other open tabs. A delayed browser request can no longer undo a newer choice. The settings page no longer shows a stale “outdated” alert right after a save.

Upgrading

No migration. The banner script now ships through the module’s js_sources/0, in the app’s phoenix_kit_modules.js, and retires the older copy bundled in core’s phoenix_kit.js. An existing Cookie Policy keeps its old text until you generate it again; regenerate the Cookie Policy so it lists what your site really collects.

Full release notes: Legal 0.6.0

0.6.0 · 13 October 2026

Added

  • A server-side record of consent (#25). GET/POST/DELETE {prefix}/api/consent records each decision as a consent log row per category and a signed, first-party pk_consent cookie. Same-origin only (scheme, host and port), booleans for known categories only, rate-limited per network, and an unchanged decision is not logged twice.
  • Legal.Consent (read/1, status/2, objected?/1): other modules ask what a visitor agreed to without a database query. Never raises.
  • What the site collects is declared, not written (Legal.DataCollection). Modules export data_collection/0; the preferences dialog, the settings page and the generated Cookie Policy read the same list, and the settings page says when the policy has fallen behind it.
  • Settings for the record: keep the log, keep the address, keep a User-Agent hash, days before asking again, reload on withdrawal. Every settings write carries the acting admin into core’s settings history.
  • The banner script ships through js_sources/0 and retires the older copy bundled in core’s phoenix_kit.js.

Changed

  • The Cookie Policy is generated from the declared list instead of naming Google and Facebook cookies a site may not have. A list that cannot be gathered fails generation rather than writing an empty policy.

Fixed

  • The settings page compared the Cookie Policy with the settings cache right after a write and could show a stale “outdated” alert; only listed entries can be hidden.
  • Origin checks compare the scheme; delayed browser requests can no longer reverse a newer choice; withdrawal applies a refusal immediately (Google Consent Mode included) and is honored in other tabs; expired grants do not survive a hook remount; clock skew cannot discard an undelivered refusal; hot-path readers are total functions; listeners are installed once.

Legal 0.6.0. Install or update: {:phoenix_kit_legal, "~> 0.6"}, then mix deps.get && mix phoenix_kit.update. Full history: CHANGELOG.