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.
Problem
increment_document_llm_call(p_user_id, p_day) (apps/web/scripts/005_document_llm_rate_limit.sql) is SECURITY DEFINER and executable by anon and authenticated (Supabase security advisor, lints 0028 and 0029, read 2026-11-21). Anyone could raise another user's counter to the daily limit of 10 (apps/web/lib/documents/doc-rate-limit.ts:3) and lock them out of /api/documents/simplify and /api/documents/summarize. Listed as a follow-up in the live migration run.
Change
supabase/migrations/20261121_document_llm_counter_lockdown.sql: the function refuses API callers (anon, authenticated) whose p_user_id is not their own auth.uid(), and pins search_path. Same pattern as 20261121_post_count_client_lockdown.sql. Both document routes call it with the signed-in user's own id and client (simplify/route.ts:176, summarize/route.ts:114), so they are unaffected.
Applied to live
Project oxixxrzdrryfztfxlady, 2026-11-21, as migration 20261121_document_llm_counter_lockdown.
Verification, each inside a transaction that was rolled back:
- Before applying (function replaced inside the transaction): own id counts (two calls, counter = 2); another user's id is refused for
authenticated; any id is refused foranon; no row for the other user. - After applying: own id counts; another user's id is refused.
- No test rows left (
user_document_llm_callshas 0 rows).
Other advisor findings, not changed
admin_user_viewis flagged as a SECURITY DEFINER view. Its definition returns rows only when the caller's own profile hasis_admin = true, and onlyid,pseudonym,is_admin, timestamps. Left as is.- 12 functions without a pinned
search_path; 15 SECURITY DEFINER functions executable byanon. Not reviewed one by one here. - Leaked-password protection is off in Supabase Auth (dashboard setting).
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.
2026-11-21 — Production outage from the start-up env check; check made non-fatal
The start-up check added on 2026-11-19 threw in production because NEXT_PUBLIC_SITE_URL was unset. Every server-rendered route on www.fragjulia.de failed from the first deployment that built with it until this fix. The check now only logs.