Blog · November 24, 2026 · 9 min read

Supabase roles: stop users making themselves admin

Can users of your Supabase app change their own role, plan or credits? Test it in a minute, then lock it down with RLS, column grants and app_metadata.

Here is one of the most common holes in AI-built apps, and it hides behind a policy that looks perfectly safe.

Your app has a profiles table. It has a display_name, an avatar_url, and also a role column, or is_admin, or plan, or credits. Row Level Security is on. There is a policy called something like "Users can update their own profile". The Security Advisor is happy.

And every signed-in user can make themselves an admin, upgrade themselves to the paid plan, or give themselves 10,000 credits. They don't need to hack anything. They open the browser console on your site and send one update.

This guide shows why that happens, how to test your own app in about a minute, and three ways to fix it, from the quickest to the cleanest.

Why "users can update their own profile" isn't enough

RLS works on rows, not columns. A policy like this one:

create policy "Users can update their own profile"
on public.profiles for update
to authenticated
using ((select auth.uid()) = id)
with check ((select auth.uid()) = id);

answers one question: is this your row? If the answer is yes, the user may change any column in it. Postgres has no idea that display_name is harmless and role is the key to your admin panel. If you want a refresher on how policies decide who sees what, read Supabase Row Level Security in plain English.

Your app's own screens never let anyone edit the role, of course. But the screens don't matter. Your Supabase URL and publishable (or anon) key are in your JavaScript, which is normal and expected. Together with the user's own login, that is everything needed to talk to your database directly, without your interface in the way.

The same goes for any column your app trusts for decisions:

If a user can write it and your code reads it to decide what they may do, it isn't a setting. It's a self-service upgrade.

The second trap: user_metadata

Supabase gives every user two metadata fields, and they are not equal.

So if your policies, or your code, check something like auth.jwt() -> 'user_metadata' ->> 'role', any user can set that value themselves. Supabase's own docs warn against using user_metadata for authorization for exactly this reason.

There's a quieter version of this bug too. Many apps have a "handle new user" trigger that copies signup data into profiles. If that trigger copies a role or plan field from raw_user_meta_data, then anyone can sign up as an admin by adding role: 'admin' to the signup call. Open your trigger function and check which fields it copies.

Test your own app in a minute

Do this only on your own app. Sign in as a normal test user (not your admin account), open your live site, then open the browser developer tools and go to the Console.

Most AI-built apps expose a Supabase client somewhere, but the easiest way is to create one yourself. Paste this, filling in your project URL and publishable key (both are in your JavaScript already, so this isn't a secret):

const { createClient } = await import('https://esm.sh/@supabase/supabase-js@2')
const sb = createClient('https://YOUR-PROJECT.supabase.co', 'YOUR-PUBLISHABLE-KEY')
await sb.auth.signInWithPassword({ email: 'test@example.com', password: 'your-test-password' })
const { data: { user } } = await sb.auth.getUser()
await sb.from('profiles').update({ role: 'admin' }).eq('id', user.id).select()

Change role: 'admin' to whatever your column is called, like plan: 'pro' or credits: 99999.

Read the result:

Then try the metadata trap:

await sb.auth.updateUser({ data: { role: 'admin', plan: 'pro' } })

This call is supposed to work, since user metadata is the user's to edit. The question is what happens next: reload your app as that user. If the admin menu appears or paid features unlock, your app trusts user_metadata.

Set the test user back afterwards, from the Supabase dashboard.

Find the risky columns with SQL

In the Supabase SQL Editor, list columns whose names suggest they control access or money:

select table_name, column_name
from information_schema.columns
where table_schema = 'public'
  and column_name ~* '(role|admin|staff|plan|tier|pro|subscription|credit|balance|limit|verified|approved|banned)'
order by table_name, column_name;

Then see which of those tables signed-in users can update or insert into:

select tablename, policyname, cmd, roles, qual, with_check
from pg_policies
where schemaname = 'public' and cmd in ('UPDATE', 'INSERT', 'ALL');

Every table that shows up in both lists needs one of the fixes below. Don't forget INSERT: if users can create their own profile row, they can create it with role = 'admin' from the start.

Fix 1: column grants (quickest)

Postgres lets you grant permissions per column. Take away the general right to update the table, then give back only the columns users should edit:

revoke update on public.profiles from authenticated, anon;
grant update (display_name, avatar_url, bio) on public.profiles to authenticated;

Your RLS policy still decides which rows a user can touch. The grant decides which columns. Together they say "your own row, and only these fields". An update to role now fails with a permission denied error, and the server, using the secret key, can still change it.

Do the same for insert if users create their own profile rows:

revoke insert on public.profiles from authenticated, anon;
grant insert (id, display_name, avatar_url) on public.profiles to authenticated;

Two things to watch. First, when you add a new editable column later, you also have to add it to the grant, or updates to it will fail. Second, upsert from the client needs both insert and update rights on the columns it sends, so send only the allowed fields.

Fix 2: a guard trigger

If you'd rather keep normal table grants, a trigger can refuse changes to protected columns when the request comes from a signed-in user:

create or replace function public.protect_profile_columns()
returns trigger
language plpgsql
set search_path = ''
as $$
begin
  if current_user in ('authenticated', 'anon') then
    if new.role is distinct from old.role
       or new.plan is distinct from old.plan
       or new.credits is distinct from old.credits then
      raise exception 'You cannot change role, plan or credits';
    end if;
  end if;
  return new;
end;
$$;

create trigger protect_profile_columns
before update on public.profiles
for each row execute function public.protect_profile_columns();

Requests from your app's users run as the authenticated role, so they are blocked. Your server code with the secret key runs as service_role and passes. Add a similar check on insert that forces the protected columns to their defaults.

The downside is that the list of protected columns lives in a function that's easy to forget when you add a new one.

Fix 3: move roles and plans out of profiles (cleanest)

The sturdiest design is to keep anything that grants power in a table users can read but never write:

create table public.user_roles (
  user_id uuid primary key references auth.users on delete cascade,
  role text not null default 'user'
);

alter table public.user_roles enable row level security;

create policy "Users can read their own role"
on public.user_roles for select
to authenticated
using ((select auth.uid()) = user_id);

There are no insert, update or delete policies, so with RLS on, signed-in users can't write to it at all. Only your server, or you in the dashboard, can.

Then write one helper that your other policies use:

create or replace function public.is_admin()
returns boolean
language sql
stable
security definer
set search_path = ''
as $$
  select exists (
    select 1 from public.user_roles
    where user_id = (select auth.uid()) and role = 'admin'
  );
$$;

And use it where admins need extra rights:

create policy "Admins can read all orders"
on public.orders for select
to authenticated
using ((select public.is_admin()));

Plans and credits work the same way: a subscriptions or billing table that only your payment webhook writes, using the secret key on the server. The Stripe checkout security checklist covers why the webhook, not the browser, should be the thing that marks someone as paid.

If you want roles inside the login token, put them in app_metadata from the server, or use Supabase's custom access token hook, never user_metadata. Remember that a token keeps its old claims until it refreshes, so a removed admin can keep access for up to an hour unless you also check the table.

Check the server side, too

Locking the database is half the job. Look at your own code for:

A prompt for your AI tool

Audit my Supabase project for privilege escalation. 1) List every column that controls access, plan, credits or verification. 2) Make sure signed-in users cannot update or insert those columns: use column-level GRANTs or move them to a separate table with a SELECT-only RLS policy. 3) Never use user_metadata for authorization; use a server-written table or app_metadata. 4) Check the new-user trigger doesn't copy role or plan from signup data. 5) Make every admin page and admin API route check the role on the server. Show me each change before applying it.

Check your app

Start with the outside view. Run the free Greenlight Scan on your live URL: in about two minutes you get a security score and your worst problem by name, such as a secret key in your JavaScript or a Supabase table that answers signed-out visitors. The $19 Full Scan, a one-time payment, shows every problem with a ready-made fix to paste into Lovable, Cursor, Bolt, Replit or v0. If you want to check if your Supabase database is exposed by hand first, that guide walks through it.

A self-promotion bug like this one lives in your policies and code, where an outside scan can't see it. If your app takes payments or stores personal data, the $79 Launch Audit also reads your GitHub code: a deep AI review of your auth, database policies and server routes, with every finding double-checked by a second AI and a one-page launch verdict. It's automated, not a pentest, but it's built to catch exactly the "users can edit their own role" kind of mistake. And if you keep shipping changes with an AI tool, Greenlight Watch ($9 a month) re-checks your live app every week and emails you when something new turns up.

Newsletter

The Friday leak report

One short email a week: the newest ways AI-built apps leak data, and the one-line fix for each. No spam, unsubscribe any time.