Why does "users can update their own row" include the role?
This is the policy most tutorials and AI coding tools produce for a profiles table:
create policy "Users can update own profile"
on public.profiles for update
to authenticated
using (auth.uid() = id);
Row level security decides which rows a request can touch. It says nothing about columns. Supabase's documentation notes that by default the authenticated role holds a table-level UPDATE privilege, "which means that the authenticated role can update all the columns" (column level security).
A with check does not save you either. PostgreSQL evaluates it "against the proposed new contents of the row, not the original contents", and when only using is given, that same expression is reused as the check (PostgreSQL docs on CREATE POLICY). The new row still has id = auth.uid(), so the update with role = 'admin' passes.
Firebase has the same shape. A rule like allow write: if request.auth.uid == userId on users/{userId} lets the owner write every field. Firebase's own docs show admin checks that read a user document, such as get(/databases/$(database)/documents/users/$(request.auth.uid)).data.admin == true (rule conditions). That check is only as strong as the rule that stops users writing admin on their own document.
The same applies to plan, credits, is_verified, tier and org_id. OWASP calls this mass assignment: a request sets a field the form never showed, such as isAdmin=true (OWASP cheat sheet).
What does this look like in a real app?
On August 3, 2025, between about 2 AM and 8 AM EST, the drawing app DrawAFish had every username changed to offensive text. The developer's postmortem, published the next day, lists the causes plainly. "The username modification did not perform any auth logic whatsoever." Admin actions used a sign-in token but "never confirmed that the JWT token belonged to the userId / email" in the request, and an old admin password was still active.
He calls it a blameful postmortem: "And I blame me. (Not the LLM, sorry)." A user named iceweaselfan44 used the same token flaw to remove the worst drawings, then worked with him on the fixes. The lesson for roles: the server has to decide who the caller is and what they may change, every time.
How do I stop users changing their role in Supabase?
Pick one of these. We would start with the first or second, and add the trigger as a backstop.
Take the column away with privileges
revoke update on table public.profiles from authenticated;
grant update (display_name, avatar_url) on table public.profiles to authenticated;
Now an update that includes role fails with a permission error, even though the row policy allows it. Supabase calls column privileges an advanced feature and does not recommend them for most projects; every new safe column has to be added to the grant (column level security).
Move roles to their own table
Supabase's role-based access guide keeps roles in a user_roles table, runs revoke all on table public.user_roles from authenticated, anon, public, and adds the role to the token with a custom access token hook. A simpler version that reads the table in policies:
create table public.user_roles (
user_id uuid primary key references auth.users on delete cascade,
role text not null check (role in ('member', 'admin'))
);
alter table public.user_roles enable row level security;
revoke all on table public.user_roles from anon, authenticated;
create schema if not exists private;
create function private.is_admin() returns boolean
language sql stable security definer set search_path = ''
as $$ select exists (
select 1 from public.user_roles
where user_id = auth.uid() and role = 'admin'
) $$;
grant usage on schema private to authenticated;
Then policies on admin-only tables use using ((select private.is_admin())). The function sits outside public on purpose: Supabase warns that a security definer function in an exposed schema "is callable over the Data API with the creator's privileges" (row level security). Only your server, using the secret key, or the SQL editor writes to user_roles.
Add a trigger as a backstop
create function public.block_role_change() returns trigger
language plpgsql as $$
begin
if new.role is distinct from old.role
and current_user in ('anon', 'authenticated') then
raise exception 'role can only be changed by the server';
end if;
return new;
end $$;
create trigger profiles_block_role_change
before update on public.profiles
for each row execute function public.block_role_change();
This catches the change even if someone later adds a broad grant back.
Is user_metadata safe for roles?
No. Supabase is direct about it: "Users can edit their own user metadata, so a role or tenant ID stored there lets a user grant themselves access" (managing user data). Any signed-in user can call supabase.auth.updateUser({ data: { role: 'admin' } }).
-- Don't: the user controls this value
using ((select auth.jwt() -> 'user_metadata' ->> 'role') = 'admin')
-- Do: app_metadata can't be changed by the user
using ((select auth.jwt() -> 'app_metadata' ->> 'role') = 'admin')
Set app_metadata from a trusted server with your secret key. Search your code for user_metadata and raw_user_meta_data in policies, functions and route handlers.
How do I do the same in Firebase?
Pin the fields a user may change. Firebase recommends hasOnly() because new fields are then refused by default (control access to specific fields):
match /users/{userId} {
allow read: if request.auth != null && request.auth.uid == userId;
allow create: if request.auth != null && request.auth.uid == userId
&& request.resource.data.keys().hasOnly(['displayName', 'photoURL']);
allow update: if request.auth != null && request.auth.uid == userId
&& request.resource.data.diff(resource.data).affectedKeys()
.hasOnly(['displayName', 'photoURL']);
}
For real roles, use custom claims. They "should only be set from a privileged server environment by the Firebase Admin SDK", for example getAuth().setCustomUserClaims(uid, { admin: true }), and they are meant for access control, not profile data (custom claims). Rules then check request.auth.token.admin == true (rules and Auth).
Isn't hiding the admin page enough?
No. A React check like {profile.role === 'admin' && <AdminLink />} hides a link; it does not stop the request behind it. Every admin route, edge function and server action has to work out the caller from a verified token, look up their role in a place they cannot write, and refuse otherwise. Never take the role, or the user id, from the request body. Our broken access control guide covers the wider version of this test.
Try it on your own app with two test accounts
Use a staging copy or your own app with test accounts: A is an ordinary user, B is an admin.
- Find the fields worth testing. In the Supabase SQL editor, run
select has_column_privilege('authenticated', 'public.profiles', 'role', 'UPDATE');. PostgreSQL counts both table-wide and column grants (system functions), sotruemeans users can write it. - Signed in as A, change your display name with the developer tools open. In the Network tab, right-click that request and choose Copy as fetch.
- Paste it into the Console, add
"role": "admin"(andplan,is_admin,creditsif you have them) to the body, and run it. Expect a permission error from Supabase orPERMISSION_DENIEDfrom Firestore. - Reload and confirm the role did not change, even if the response looked like a success. Then try the same edit through
user_metadataand check that no admin access follows. - As A, open
/admindirectly and replay one request copied from B's admin session. Expect the server to refuse it. A hidden page alone is not a pass.
A pass covers that one table and those fields. Repeat it for every table with a field like role or plan, and for your Supabase policies or Firebase rules generally.