1
0
Fork 0
Commit Graph

9 Commits

Author SHA1 Message Date
Jonny dd725b5027 feat: add auftrag status transition trigger with pgTAP coverage 2026-07-05 17:01:43 +02:00
Jonny bb4f276c72 feat: add auftrag_fotos table with RLS and required-photo constraint 2026-07-05 16:47:26 +02:00
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
Jonny 8ed34cfa96 feat: add auftraege table with status enum and RLS 2026-07-05 11:08:47 +02:00
Jonny 0850f0ccfc feat: add orte and fahrzeuge lookup tables with RLS 2026-07-05 10:59:55 +02:00
Jonny d03052ca73 test: cover profiles UPDATE RLS boundary and privilege-escalation trigger
Final review found the RLS test suite only covered SELECT, never the
actual security-relevant path: a non-admin changing a profile's role.
Add pgTAP coverage for a fahrer's own-role UPDATE being blocked by RLS
(0 rows affected, role unchanged), the positive admin-can-update-others
case, and a regression test for handle_new_user() ignoring
raw_user_meta_data.role so a future edit reintroducing that read fails
loudly instead of quietly reopening the escalation hole.

Also add a migration giving the admin UPDATE policy an explicit
WITH CHECK (behavior unchanged, since Postgres already falls back to
USING for UPDATE policies without one) to document the pattern for
future sub-projects copying this RLS setup.
2026-07-05 00:45:27 +02:00
Jonny d13994b386 feat: add RLS policies and pgTAP tests for profiles 2026-07-04 11:58:09 +02:00
Jonny 92adebd710 fix: never derive new user role from raw_user_meta_data (privilege escalation)
Fixes a CRITICAL finding from automated security review of a9e67ce: the
handle_new_user() trigger read the role from
new.raw_user_meta_data ->> 'role', which is attacker-controllable in
certain GoTrue flows (OAuth, invite links). A user could set
role: admin in their own signup metadata and self-escalate.

Every new user now always gets role = 'readonly' on creation; an admin
must explicitly promote via SQL/Table Editor afterwards (enforced later
by the "Admins aktualisieren alle Profile" RLS policy in Task 3).

Edited the already-applied migration file directly rather than adding a
new one, since this project has no deployment/production data yet.

Verified: inserting a user with raw_user_meta_data = {"role": "admin"}
still results in role = readonly in public.profiles.
2026-07-04 11:48:26 +02:00
Jonny a9e67ce04d feat: add profiles table, role enum and auto-create trigger 2026-07-04 11:30:13 +02:00