From 92adebd7102fbabff5c42d66088cc1dcd0f7011f Mon Sep 17 00:00:00 2001 From: Jonny Date: Sat, 4 Jul 2026 11:48:26 +0200 Subject: [PATCH] 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. --- supabase/migrations/20260704092843_profiles.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/supabase/migrations/20260704092843_profiles.sql b/supabase/migrations/20260704092843_profiles.sql index 9e967e5..1415321 100644 --- a/supabase/migrations/20260704092843_profiles.sql +++ b/supabase/migrations/20260704092843_profiles.sql @@ -20,7 +20,7 @@ begin values ( new.id, coalesce(new.raw_user_meta_data ->> 'name', new.email), - coalesce((new.raw_user_meta_data ->> 'role')::public.app_role, 'readonly') + 'readonly' ); return new; end;