1
0
Fork 0

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.
This commit is contained in:
Jonny 2026-07-04 11:48:26 +02:00
parent 2f2f354402
commit 92adebd710
1 changed files with 1 additions and 1 deletions

View File

@ -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;