2026-11-21 — Consent records validated on the server; accounts without consent are locked
Rework of the consent migration after the external review in #715. The database now validates the full consent set against registered versions, sets the time itself and locks accounts without valid consents. Not applied to the live database.
Addresses the findings in #715. The issue stays open: legal review and the live rollout are not done.
Findings and what changed
| #715 finding | Change |
|---|---|
| P1 — missing or partial consents let through | Signup with a consents key must carry all four types; otherwise the signup is rejected and nothing is created. Signup without the key creates a locked account. |
| P1 — any version and wrong types produce records | Versions are checked against the new consent_versions registry; values must be JSON strings equal to the current version. false, numbers, objects, arrays, padded or invented versions and unknown keys are rejected. A foreign key ties every record to a registered version. |
| P1 — client-controlled time | granted_at is set by a trigger from the server clock for every insert. consents_granted_at is no longer sent or read. |
| P2 — invalid time aborts signup | No client time is parsed. |
| No enforcement behind the checkboxes | Restrictive RLS policies on 17 tables refuse inserts and updates without valid consents; 16 API routes check before processing; yoga_join_meet() checks itself. |
| Existing accounts, re-consent | grant_consents() plus a gate in the app. Existing accounts are locked until their owner confirms; no historical consent is invented. A version change locks everyone until they accept the new text. |
| Explicit rights | No table grants for API roles beyond SELECT on own records; internal functions not executable by API roles. |
| Mobile and other clients | Mobile register screen asks for the three confirmations and sends the versions; a mobile gate handles locked accounts. Versions shared via packages/shared. |
| Negative tests | 42 database cases in apps/web/lib/consent-migration.test.ts, run in CI with the web tests. |
Files
supabase/migrations/20261121_user_consents.sqlreplaces20261119_user_consents.sql, which was never applied anywhere.apps/web/lib/consent.ts,lib/consent-server.ts,components/consent-fields.tsx,components/consent-gate.tsx,app/layout.tsx,app/registrieren/page.tsx, 16 routes underapp/api/.apps/mobile/components/ConsentChecks.tsx,ConsentGate.tsx,app/auth/register.tsx,app/_layout.tsx,hooks/useAuth.tsx;packages/shared/src/lib/consent.ts.- New dev dependency
@electric-sql/pglite(in-process Postgres for the migration tests). - Docs: consent records rewritten; go-live map section B and owner list.
Verification
- Web tests: 208 of 209 pass; the one failure is the study-data staleness check.
tsc,eslint(0 errors) andnext buildpass. - Mutation check: with the string-type check, the server-time trigger and the restrictive policy each weakened, 5 of the database tests fail.
- Live schema, inside a rolled-back transaction: see "Tests" in consent records. Nothing was left behind (no tables, no policies, 4 users as before).
Not verified
- A real signup through Supabase Auth against the migrated database, including e-mail confirmation.
- The gate against a real database. It was driven in a browser against a production build with a stubbed backend (desktop and 390 px), and by component tests.
- The mobile screens on a device or simulator. They are type-checked only; the mobile project has unrelated type errors of its own (voice services, React type versions).
Follow-ups
- Owner: legal review of the wording; decision to apply the migration (order: deploy code first, then migrate).
- Run the mobile consent screens on a device before a mobile release.
2026-11-21 — Signed-in page loads no longer block the Supabase client
The auth state handler awaited a profile query from inside the auth callback. While a stored session is being restored this blocks the client for good: header shows logged-out, no client query runs. Fixed; regression test added.
2026-11-21 — Document counter: no cross-user increments
increment_document_llm_call could be called for any user id by anyone, including callers without an account. It now only counts for the caller. Applied to the live database and verified.