forked from fahrPool/fahrPool
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:
parent
2f2f354402
commit
92adebd710
|
|
@ -20,7 +20,7 @@ begin
|
||||||
values (
|
values (
|
||||||
new.id,
|
new.id,
|
||||||
coalesce(new.raw_user_meta_data ->> 'name', new.email),
|
coalesce(new.raw_user_meta_data ->> 'name', new.email),
|
||||||
coalesce((new.raw_user_meta_data ->> 'role')::public.app_role, 'readonly')
|
'readonly'
|
||||||
);
|
);
|
||||||
return new;
|
return new;
|
||||||
end;
|
end;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue