1
0
Fork 0
fahrPool/supabase/migrations
Jonny 55c4ac5949 fix: gate auftraege RLS policies on user_role() to close readonly claim gap
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>
2026-07-05 11:27:27 +02:00
..
20260704092843_profiles.sql fix: never derive new user role from raw_user_meta_data (privilege escalation) 2026-07-04 11:48:26 +02:00
20260704095119_rls_profiles.sql feat: add RLS policies and pgTAP tests for profiles 2026-07-04 11:58:09 +02:00
20260704224211_add_profiles_update_with_check.sql test: cover profiles UPDATE RLS boundary and privilege-escalation trigger 2026-07-05 00:45:27 +02:00
20260705085814_orte_fahrzeuge.sql feat: add orte and fahrzeuge lookup tables with RLS 2026-07-05 10:59:55 +02:00
20260705090655_auftraege.sql fix: gate auftraege RLS policies on user_role() to close readonly claim gap 2026-07-05 11:27:27 +02:00