</>RescueMyRepoFree scan

// guide · Supabase RLS · published Nov 19, 2026

Can your users make themselves admin? Lock the role column in your Supabase profiles table

Short answer

Row Level Security decides which rows a user can change, not which columns. If your profiles table has a role, is_admin, plan or credits column and an “update own profile” policy, any signed-in user can run supabase.from('profiles').update({ role: 'admin' }) on their own row. Move those columns to a table users can only read, or revoke the table-level UPDATE grant and allow only safe columns, then re-test as a normal user.

Why this happens in AI-built apps

Lovable, Bolt, Cursor and Claude Code usually add an admin page or a Pro plan by putting one more column on the table they already have: profiles. That same table already has an owner UPDATE policy so the settings page can save a name and avatar. Supabase's own docs warn that such a policy “gives the post owner full access to update the row, including all of the columns” (Supabase column-level security). The settings form never shows the role field, so nobody notices that the API accepts it.

-- What AI tools often generate
create table public.profiles (
  id uuid primary key references auth.users(id) on delete cascade,
  full_name text,
  avatar_url text,
  role text not null default 'user',   -- decides who sees /admin
  plan text not null default 'free'     -- decides who gets Pro
);
alter table public.profiles enable row level security;

create policy "Users can update own profile" on public.profiles
  for update using ((select auth.uid()) = id);
-- RLS is on and the policy is "correct"... for rows. Every column is editable.

It's one of the most common checks people now run before launch (“as a normal user, set is_admin to true on your own profile; if it saves, anyone can be admin”), and it is a close cousin of reading roles from user-editable user_metadata.

Test it on your own app in 2 minutes

Sign in as a throwaway test account (never someone else's app or account) and try to promote yourself:

// Your OWN app only, signed in as a throwaway test user (browser console or a script)
const { data: { user } } = await supabase.auth.getUser();

const { data, error } = await supabase
  .from("profiles")
  .update({ role: "admin", plan: "pro" })
  .eq("id", user.id)
  .select();

console.log(data, error);
// A row with role "admin" = any user can promote themselves. Fix it, then run this again.
// An error (permission denied / trigger exception) or unchanged values = locked.

Do the same for every column that decides access or money: is_admin, plan, subscription_status, credits. If the browser creates the profile row itself, also try an insert with role: 'admin' for a new test user. A column default doesn't help there, because the client can send its own value.

The fix

Option 1, recommended: keep roles, plans and credits in a table users can read but never write. Supabase recommends RLS plus a dedicated roles table for most apps (docs; see also custom claims and RBAC). Your Stripe webhook or admin route updates it server-side with the service_role key.

-- Option 1 (recommended): roles and plans live in a table users can't write
create table public.user_roles (
  user_id uuid primary key references auth.users(id) on delete cascade,
  role text not null default 'user',
  plan text not null default 'free'
);
alter table public.user_roles enable row level security;

create policy "read own role" on public.user_roles
  for select to authenticated using ((select auth.uid()) = user_id);
-- No insert/update/delete policies: only server code with the service_role key
-- (Stripe webhook, admin route) or SQL can change these rows.

insert into public.user_roles (user_id, role, plan)
  select id, role, plan from public.profiles;
alter table public.profiles drop column role, drop column plan;

Option 2: column privileges. The catch AI tools miss: Supabase tables normally carry a table-level UPDATE grant for authenticated, and revoking only the column leaves that table-level grant in effect. Revoke the table privilege, then grant the safe columns back (Postgres GRANT docs):

-- Option 2: keep the columns, but only let users update the safe ones.
-- Revoke the TABLE-level privilege first; revoking only the column does nothing
-- while the table-level UPDATE grant is still there.
revoke update on public.profiles from anon, authenticated;
grant update (full_name, avatar_url) on public.profiles to authenticated;

Option 3: a BEFORE UPDATE trigger that rejects changes to those columns from API users. Calls from your server with the service_role key run as service_role, so they still work:

-- Option 3: a trigger that refuses role/plan changes from API users
create or replace function public.protect_profile_authz()
returns trigger language plpgsql set search_path = '' as $$
begin
  if current_user in ('anon', 'authenticated')
     and (new.role is distinct from old.role or new.plan is distinct from old.plan) then
    raise exception 'role and plan can only be changed by the server';
  end if;
  return new;
end $$;

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

Then update every RLS policy, RPC and server check that reads the role or plan so it uses the trusted source, and re-run the test above: the update must fail and the value must stay the same, while editing full_name still works.

Tell your AI coding tool

Paste this into Lovable, Bolt, Cursor or Claude Code:

Audit this Supabase project for users being able to change their own authorization fields.
1. In supabase/migrations, list every table that has columns like role, is_admin, admin, plan, tier, subscription_status, is_pro or credits.
2. For each one, list the RLS policies that let a user UPDATE or INSERT their own row (auth.uid() = id / user_id), and the GRANTs on the table.
3. If users can write those columns, write a new migration that moves them to a separate table (user_roles or subscriptions) with a SELECT-own-row policy and no insert/update policies, changed only from server code with the service_role key. If they must stay, revoke table-level UPDATE from anon and authenticated and grant UPDATE only on the safe columns, or add a BEFORE UPDATE trigger that raises when they change and current_user is anon or authenticated.
4. If the browser inserts the profile row, move that into a signup trigger that always sets the default role and plan.
5. Update every policy, RPC and server check that reads role/plan to read the new trusted source. Never read roles from user_metadata.
6. Show me the migration and a test: as a normal user, supabase.from('profiles').update({ role: 'admin' }).eq('id', user.id) must fail and the value must stay unchanged, while editing full_name still works.

Check your repo automatically

RescueMyRepo's free scan reads your SQL migrations in order and flags user, profile, account and member tables where a role, admin, plan, tier, subscription or credits column sits next to a policy that lets users update (high) or insert (medium) their own row, with a fix prompt for each. It also checks tables with RLS off, using (true) policies, roles read from user_metadata, views that bypass RLS, leaked keys and unverified Stripe webhooks. It reads code, so policies created by hand in the dashboard only show up in the test above.

Scan my repo freePublic GitHub repos · no signup · about a minute

FAQ

My policy is using (auth.uid() = id). Why can a user still change their role?

Because a Row Level Security policy only decides which rows a user may update. Supabase's docs say it plainly: an owner UPDATE policy gives the owner full access to update the row, including all of the columns. If role, is_admin, plan or credits sit on that row, the user can change them with their own session and your public anon key.

Does hiding the role field in my settings form fix it?

No. The form is only one client. Anyone signed in can open the browser console or a script and call supabase.from('profiles').update({ role: 'admin' }).eq('id', theirId) directly against your project's Data API.

Can I just revoke update on the role column?

Not on its own. Supabase tables normally carry a table-level UPDATE grant for authenticated, and Supabase's column-level security docs note that if you have both and revoke the column-level privilege, the table-level privilege still applies. Revoke the table-level UPDATE first, then grant UPDATE only on the safe columns.

What is the safest fix?

Move roles, plans and credits out of the user-editable table into one users can read but never write (for example user_roles or subscriptions with a SELECT-own-row policy and no insert/update policies), and change it only from server code using the service_role key, such as your Stripe webhook or an admin route. Supabase's docs recommend RLS plus a dedicated roles table over column privileges for most apps.

Does the same problem apply to INSERT?

Yes. If the browser creates the profile row and an INSERT policy only checks auth.uid() = id, the user can insert their own row with role = 'admin' or credits = 999999. A column default does not stop it, because the client can send its own value. Create profile rows in a signup trigger, or force the values in a BEFORE INSERT trigger.

Does RescueMyRepo detect this?

Yes. The free scan reads your SQL migrations in order and flags user, profile, account and member tables that have role, admin, plan, tier, subscription or credits columns plus a policy that lets a user update (high) or insert (medium) their own row. It skips tables where the table-level privilege is revoked and only safe columns are granted, where a trigger compares the column with OLD, where the policy pins the column, and policies that are dropped later.

Sources