Security review found two RLS gaps in the auftraege migration that exactly
followed the (flawed) plan:
- The fahrer UPDATE policy had no public.user_role() = 'fahrer' predicate,
so any authenticated user -- including a readonly-role account (the
default role for new signups) -- could self-assign any open order via
the "status = 'offen'" branch of USING, since all app roles share the
same Postgres role and only user_role() distinguishes them.
- The disponent/admin INSERT policy did not bind erstellt_von to
auth.uid(), allowing a spoofed creator id on insert.
Adds public.user_role() = 'fahrer' to both USING and WITH CHECK on the
fahrer UPDATE policy, and erstellt_von = auth.uid() to the INSERT policy's
WITH CHECK. Column-level lockdown (fahrer changing abholort_id etc.) is
intentionally deferred to Task 4's trigger, not addressed here.
Verified behaviorally: with the pre-fix policy, a readonly-role user could
claim an open order (UPDATE 1); with the fix, the same attempt affects 0
rows. Migration amended in place since it was never applied outside this
local dev stack.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>