LatchDog

← Guides

Can a Supabase user make themselves admin? Protecting is_admin, role and credits columns

Short answer: yes, if your profiles table lets signed-in users update their own row. Row Level Security (RLS) decides which rows a user can change, not which columns, so an owner-only update policy also lets them set is_admin, role, plan or credits on their own row, straight from the browser with your public key. The fix is to stop trusting the row policy for those columns: keep roles in a table users cannot write, or take table-wide UPDATE away from authenticated and grant it back for the safe columns only, then test as an ordinary user. Our outside scan cannot detect this problem, so the test below is yours to run.

Why an owner-only policy is not enough

Here is the policy most AI-built apps end up with, and it is a reasonable one for rows:

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

It answers "which row?", and the answer is "your own". It says nothing about "which column?". Supabase's column-level security page puts it this way: "Postgres's Row Level Security (RLS) gives you granular control over who can access rows of data. However, it doesn't give you control over which columns they can access within rows" (Supabase: Column Level Security). On the same page, about an owner who can update a post: "this gives the post owner full access to update the row, including all of the columns."

with check does not close the gap either. In the Postgres docs, "the check_expression is evaluated against the proposed new contents of the row, not the original contents", and when a policy has no with check, its using expression is reused (PostgreSQL: CREATE POLICY). For the policy above, a row with is_admin = true and the right id passes both. A check that compares the new value with the stored one by running a subquery on the same table is possible, but it is easy to get wrong; the options below say what they mean.

So this call, made with the public key and a normal user's session, succeeds:

await supabase.from('profiles').update({ is_admin: true, credits: 9999 }).eq('id', user.id)

Your own admin screen never sends that, but anyone who opens DevTools can. We ran the SQL in this guide on a local Postgres 17 (PGlite) with stand-in anon and authenticated roles and a stand-in auth.uid(), not on a live Supabase project. There, the update above changed both columns on the caller's own row, an update of someone else's row matched nothing, and an insert of a new row with is_admin = true also went through, because the insert policy only checked id.

Which columns this applies to

Any column where the value decides what the user is allowed to do, rather than describing them:

There are three ways in: updating your own row, inserting your own row with extra fields (common when the app creates the profile from the browser after sign-up), and the auth user's own metadata. The last one is covered in its own section below.

Fix 1: keep roles in a table users cannot write

This is the approach Supabase recommends. Their column page says: "We do not recommend using column-level privileges for most users. Instead, we recommend using RLS policies in combination with a dedicated table for handling user roles." Move the flag out of profiles, give signed-in users read access to their own entries only, and give them no write access at all:

create type public.app_role as enum ('admin', 'user');

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

alter table public.user_roles enable row level security;
revoke all on table public.user_roles from anon, authenticated;
grant select on table public.user_roles to authenticated;

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

Now a policy on any other table can ask whether the caller is an admin:

create policy "admins read reports" on public.reports
  for select to authenticated
  using (exists (
    select 1 from public.user_roles r
    where r.user_id = (select auth.uid()) and r.role = 'admin'
  ));

The select grant and the own-row policy on user_roles are needed because, per the Postgres docs, "users who are using a given policy must be able to access any tables or functions referenced in the expression or they will simply receive a permission denied error". In our local test, the admin saw the report, a second user saw no rows, and that second user's attempts to insert or update a role failed with 42501 (permission denied). To change a role, use the SQL editor, a migration, or server code that calls Supabase with the secret key (sb_secret_...), which bypasses RLS and must never be in a browser. Supabase's role-based access guide goes a step further and copies the role into the user's token with a Custom Access Token Auth Hook (Supabase: Custom Claims & RBAC).

Fix 2: column privileges, when the column has to stay on the row

If you would rather keep is_admin or credits on profiles, Postgres lets you grant UPDATE per column. The order matters, because you must remove the table-wide privilege first:

-- UPDATE: only these columns can be changed by signed-in users
revoke update on table public.profiles from anon, authenticated;
grant update (display_name, avatar_url) on table public.profiles to authenticated;

-- INSERT: the same idea, so a new row cannot arrive with is_admin = true
revoke insert on table public.profiles from anon, authenticated;
grant insert (id, display_name, avatar_url) on table public.profiles to authenticated;

Why not just revoke the one column? The Postgres docs warn: "Granting the privilege at the table level and then revoking it for one column will not do what one might wish: the table-level grant is unaffected by a column-level operation" (PostgreSQL: GRANT). Supabase's page says the same: "If you have both, and you revoke the column-level privilege, the table-level privilege will still be in effect", and "By default, our table will have a table-level UPDATE privilege, which means that the authenticated role can update all the columns in the table." In our test, revoke update (is_admin) on public.profiles from authenticated alone changed nothing; the promotion still worked.

After the two statements above, in our local test, setting is_admin or credits as a signed-in user failed with 42501, renaming yourself still worked, and the app's existing select * still worked. The service role and the SQL editor can still change everything, which is what your server-side admin code should use.

Things to know before you ship it:

Where the October 30 grants change fits

Supabase's changelog says the "not exposed by default" setting would be applied to all existing projects on October 30, 2026, and that "Existing tables are not affected in your project, they keep their current grants and stay reachable", and that "Grants are a separate layer: they control whether a role can access a table at all, while RLS controls which rows that role can see" (Supabase changelog: tables not exposed to the Data API automatically). Two consequences for this problem. A profiles table you created last year still has its table-wide UPDATE grant, so the change does not fix it. And on a project where the new default applies, a new table needs an explicit grant before the API can use it, which is a good moment to write grant update (display_name, avatar_url) instead of a table-wide grant.

Fix 3: a trigger as a backstop

A trigger can refuse changes to the protected columns whoever wrote the query. This is useful if you cannot change grants yet, or as a second layer. PostgREST runs each request as the role named in the user's token (its docs: PostgREST "will switch to the database role with that name for the duration of the HTTP request", using SET LOCAL ROLE; see PostgREST: Authentication), so current_user is authenticated for a signed-in browser request. The SQL editor and server code using the secret key run as other roles, so they are not blocked:

create or replace function public.protect_profile_columns()
returns trigger
language plpgsql
set search_path = ''
as $$
begin
  if current_user in ('anon', 'authenticated') then
    if tg_op = 'INSERT' then
      if new.is_admin is distinct from false or new.credits is distinct from 0 then
        raise exception 'is_admin and credits cannot be set from the client' using errcode = '42501';
      end if;
    elsif new.is_admin is distinct from old.is_admin or new.credits is distinct from old.credits then
      raise exception 'is_admin and credits cannot be changed from the client' using errcode = '42501';
    end if;
  end if;
  return new;
end;
$$;

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

Details that matter: do not mark the function security definer, because inside one current_user is the function's owner, not the caller. We used a plain before insert or update trigger, not update of is_admin: the Postgres docs note that for a column-specific trigger "it is possible for a column's value to change even when the trigger is not fired, because changes made to the row's contents by BEFORE UPDATE triggers are not considered" (PostgreSQL: CREATE TRIGGER). In our local test the trigger blocked promotion, credits changes, an insert with is_admin = true and an upsert that set it, and allowed a rename. Edit the column list to match yours, and do not rely on the trigger alone if grants are easy to fix.

Do not use user_metadata for roles

Supabase Auth keeps two metadata blobs on each user, and one is writable by that user. Supabase's RLS page says: "creating an RLS policy that relies on the user_metadata claim can create security issues in your application as this information can be modified by authenticated end users." Of the two stored fields it says raw_user_meta_data "is not a good place to store authorization data", while raw_app_meta_data "cannot be updated by the user, so it's a good place to store authorization data." So a policy that checks auth.jwt() -> 'user_metadata' ->> 'role' has the same hole as an editable column. Put roles in a table (Fix 1) or in app_metadata set from server code with the secret key.

How to test it

1. List which columns signed-in users can update. This reads privileges only and changes nothing. It checks the columns whose names look like roles, flags, money or ownership; edit the pattern for your naming:

select c.table_name, c.column_name,
  has_column_privilege('authenticated', format('%I.%I', c.table_schema, c.table_name), c.column_name, 'UPDATE') as authenticated_can_update,
  has_column_privilege('anon', format('%I.%I', c.table_schema, c.table_name), c.column_name, 'UPDATE') as anon_can_update
from information_schema.columns c
join information_schema.tables t
  on t.table_schema = c.table_schema and t.table_name = c.table_name and t.table_type = 'BASE TABLE'
where c.table_schema = 'public'
  and c.column_name ~* '(admin|role|credit|balance|plan|tier|premium|verified|banned|owner|tenant|org|stripe|permission)'
order by c.table_name, c.ordinal_position;

Every protected column should show false for both roles. A true is the problem. This lists tables, not views, and it cannot see a trigger or a security definer function that changes a column on a user's behalf, so also read your functions.

2. Try it as a user, inside a transaction you roll back. Supabase's RLS page switches identity with set local role and set local request.jwt.claim.sub. Use a real user id from auth.users:

begin;
set local role authenticated;
set local request.jwt.claim.sub = 'USER-UUID-HERE';
update public.profiles set is_admin = true where id = 'USER-UUID-HERE';
rollback;

You want an error with code 42501. Seeing UPDATE 1 means any signed-in user can do the same. (With the trigger from Fix 3 you will see its message instead.)

3. Try it from the browser with a throwaway account on your own project. Sign in as a normal test user, then run supabase.from('profiles').update({ is_admin: true }).eq('id', user.id) with your publishable key. The response should be an error, not success. We tested the Postgres side locally and have not run this exact browser call against a live Supabase project, so confirm it on yours. Do it on a test account and set the flag back if it did go through.

4. Keep it from coming back. Add an assertion to your supabase test db suite (pgTAP, described in Supabase's RLS guide), so a later migration that re-grants table-wide UPDATE fails the build:

select ok(
  not has_column_privilege('authenticated', 'public.profiles', 'is_admin', 'update'),
  'signed-in users cannot update is_admin'
);

Paste-in fix prompt for your AI coding tool

Audit my Supabase database for privilege-escalation columns. Please:
1. List every table in the public schema with a column that controls authority or money, such as is_admin, role, plan, tier, credits, balance, verified, banned, owner_id, org_id or tenant_id, and tell me which of them signed-in users can currently update or insert. Use has_column_privilege for the authenticated role, not just the policies.
2. Move roles and admin flags into a dedicated user_roles table with RLS on, no insert, update or delete grant for anon or authenticated, and a select policy "to authenticated using ((select auth.uid()) = user_id)". Update my RLS policies and code to read roles from there. Do not read roles from user_metadata.
3. For any other protected column that has to stay on its table, revoke table-wide UPDATE and INSERT from anon and authenticated, then grant UPDATE and INSERT back for only the columns users may write. Revoking one column while the table-level grant remains does nothing.
4. Make sure my app code only sends allowed columns in updates and upserts, and that anything that changes a role or credits runs on the server with the secret key (sb_secret_), never in the browser.
5. Add a pgTAP test with has_column_privilege that fails if authenticated or anon can update a protected column.
6. Do not disable RLS, do not use the secret or service_role key in the browser, and do not change unrelated code.
Show me the SQL and the list of columns first, then explain what a signed-in user can change afterwards.

Review the SQL before you run it, then repeat tests 1 and 2 above. Related reading: Supabase RLS for vibe-coded apps, fixing rls_disabled_in_public, Supabase views bypass RLS and is the Supabase anon key safe to expose?

Check yours

Run test 1 on your project now; it takes a minute. Then run the free LatchDog check on your live URL: it will not find this problem, but it does look for the leaked secret key that would make all of the above irrelevant, because a service_role or sb_secret_ key in your JavaScript bypasses RLS entirely (see monitoring for leaked Supabase keys).

What LatchDog does here (and doesn't)

An outside scan cannot detect a writable role column. LatchDog's Supabase check sends only SELECT requests. It never writes, never signs in and does not call /rest/v1/rpc/ functions, so it cannot see your grants, column privileges, policies or triggers, and it cannot try an update as a user. It will not tell you that is_admin is editable, and it will not alert you if a later migration makes it editable. Use the SQL above, Supabase's Security Advisor and a pgTAP test for that. What it can tell you is whether a table or view is readable by your public key, and whether a secret key is in your live JavaScript.

LatchDog keeps watching your live app after launch. Starter ($19/month, up to 3 apps) and Pro ($39/month, up to 10 apps) re-scan it automatically every day and after every deploy (triggered by a deploy hook from your host or CI), and email you only when something changes. Nothing to install: you verify your domain once.

Keep watching your app, not just checking it once

LatchDog keeps watching your live app after launch. Starter ($19/month, up to 3 apps) and Pro ($39/month, up to 10 apps) re-scan it automatically every day and after every deploy (triggered by a deploy hook from your host or CI), and email you only when something changes. Nothing to install: you verify your domain once.

Start with the free check (headers, HTTPS, leaked keys in your JavaScript, source maps, .env/.git). Open-table checks run after you verify your domain. See plans

Free, read-only public check: no sign-up, no card. Headers, HTTPS, leaked keys in your JavaScript (always masked), public source maps and exposed .env/.git files. Supabase table checks run after you verify you own the domain.

Want the open-table check too? Get my free deep scan: sign in with your email (no password) and verify you own the domain. Your first deep scan is free and adds CORS, more of your JavaScript and, if your app uses Supabase, whether anyone can read its tables and views with your public key.