Stop Supabase users from upgrading their own plan or making themselves admin
Updated · Applies to: Supabase, Lovable, Bolt, Cursor
TL;DR fix: Row Level Security decides which rows a user can touch, not which columns. The usual policy using ((select auth.uid()) = id) on profiles lets a user update every column of their own row, including plan, credits, role or is_admin. With your public key and their own login, they can run supabase.from('profiles').update({ plan: 'pro' }) from the browser console and skip your Stripe checkout. Fix: revoke table-wide UPDATE and grant UPDATE only on the columns users may edit, or add a BEFORE UPDATE trigger that rejects changes to protected columns. Best long term: keep billing and roles in a separate table that only your server writes.
Steps
- Find the columns that decide money or power. List columns like plan, tier, subscription_status, credits, balance, role and is_admin on any table that users can update (usually profiles or users).
- Check whether users can update them. Run the grants and policies query below. If authenticated has table-wide UPDATE on that table and an UPDATE policy scoped only to the row owner, every column is editable.
- Test it from a signed-in session. In your app, sign in as a normal user and run an update on your own plan or is_admin column from the browser console. If it succeeds, you have the bug.
- Lock the columns. Either revoke UPDATE on the table and grant UPDATE only on safe columns (Fix A), or add a BEFORE UPDATE trigger that rejects changes to protected columns from the anon and authenticated roles (Fix B).
- Write protected columns only from the server. Your Stripe webhook or server code sets plan and credits with the service role or secret key, which is never shipped to the browser.
- Retest and check INSERT too. Repeat the console test; it should now fail. Also make sure a user can't insert a new profile row with plan = 'pro' already set.
Why RLS doesn’t catch this
A policy like this is in almost every vibe-coded Supabase app:
create policy "Users can update own profile"
on public.profiles for update to authenticated
using ( (select auth.uid()) = id )
with check ( (select auth.uid()) = id );
It’s correct for rows: users can’t touch anyone else’s profile. But Postgres checks columns through privileges, not policies, and the default table-wide UPDATE grant covers every column. So a signed-in user can do this from the browser console of your live app:
await supabase.from('profiles')
.update({ plan: 'pro', credits: 999999, is_admin: true })
.eq('id', (await supabase.auth.getUser()).data.user.id)
No checkout, no webhook. If your app reads profiles.plan to unlock features, they now have them. As one builder put it on X, the classic holes are in config: “RLS off, a plan column any user can update, Stripe webhooks with no signature check.”
Step 1: find the exposure
-- Who can UPDATE or INSERT which tables (table-wide)?
select table_name, grantee, privilege_type
from information_schema.role_table_grants
where table_schema = 'public'
and grantee in ('anon', 'authenticated')
and privilege_type in ('UPDATE', 'INSERT')
order by table_name, grantee;
-- Which UPDATE policies exist, and what do they check?
select tablename, policyname, roles, qual, with_check
from pg_policies
where schemaname = 'public' and cmd in ('UPDATE', 'ALL');
If a table holds plan, credits, role, is_admin or similar, authenticated has table-wide UPDATE, and the policy only checks ownership, you have the bug.
Fix A: column privileges (only safe columns are editable)
revoke update on public.profiles from authenticated, anon;
grant update (display_name, avatar_url, bio) on public.profiles to authenticated;
Keep your RLS policy. Users still edit only their own row, and now only those columns. Any update that includes plan fails with permission denied for table profiles, even if the value didn’t change, so your app must send only the edited fields. Supabase also has a Dashboard UI for this under Feature Preview.
Fix B: a guard trigger (keeps full-row saves working)
create or replace function public.protect_profile_columns()
returns trigger language plpgsql as $$
begin
if current_user in ('authenticated', 'anon')
and (new.plan is distinct from old.plan
or new.is_admin is distinct from old.is_admin) then
raise exception 'plan and is_admin can only be changed by the server';
end if;
return new;
end $$;
create trigger protect_profile_columns
before update on public.profiles
for each row execute function public.protect_profile_columns();
Add every protected column to the check. Saving a row with the same plan value still works. Your server, using the service role, is not authenticated, so the trigger lets it through.
The long-term fix: move billing and roles off the profile
Supabase recommends RLS plus a dedicated table for user roles over column privileges. Put plan, credits and roles in something like public.subscriptions or public.user_roles, give users a SELECT policy on their own row and no INSERT, UPDATE or DELETE policy, and write it only from your Stripe webhook (after verifying the signature) or an Edge Function.
If your “admins can see everything” policy then checks user_roles or profiles from a policy on that same table, Postgres stops with infinite recursion detected in policy for relation (42P17). The fix is a small security definer helper or a JWT role claim: Fix Supabase “infinite recursion detected in policy for relation” (42P17).
Don’t forget INSERT
If the browser creates profile rows, a user can insert one with plan = 'pro' already set. Create profiles from a trigger on auth.users, or grant INSERT only on safe columns so protected ones take their defaults.
Paste this into Lovable, Bolt or Cursor
Users must not be able to change their own plan, credits, role or is_admin.
1. List every column on profiles (and any users table) that controls billing or permissions.
2. Revoke table-wide UPDATE on those tables from anon and authenticated, and grant UPDATE
only on the columns users may edit (name, avatar, bio). Keep the owner-only RLS policy.
3. Make the profile edit form send only the changed fields.
4. Make the Stripe webhook (signature-verified, service role) the only code that sets plan or credits.
5. Show me the final grants and policies, then test: as a normal signed-in user,
supabase.from('profiles').update({ plan: 'pro' }) must fail.
What we verified
- Reproduced on Postgres 17 (PGlite) with Supabase-style
anon/authenticatedroles and anauth.uid()stand-in: the owner-only policy let the user setplan = 'pro'andis_admin = true. Fix A blocked it withpermission denied for table profiles(also when the update repeated the sameplanvalue), andselect *still worked. Fix B blocked a real change, allowed a full-row save with an unchangedplan, and let the server role changeplan. - From the docs, not reproduced on a live Supabase project: the Dashboard Feature Preview UI, and the RBAC table pattern.
Related: rules that only live in the frontend, USING (true) policies, SECURITY DEFINER functions callable by anon, and views that skip RLS.
When to get help
Get help if your app saves the whole profile row on every edit, if you already have paying-looking users you didn't bill, or if roles are checked in several places.
Want us to look at your app?
VibeCPR Rescue Reports are launching soon: we scan your repo and live app, and a human verifies every critical finding. Join the waitlist for early access and founder pricing. You'll also get Patch Notes, our weekly fixes newsletter.
FAQ
My profiles table has RLS on. How can a user change their own plan?
RLS limits rows, not columns. Supabase's docs say an owner-only UPDATE policy "gives the post owner full access to update the row, including all of the columns." If plan or is_admin is on the profile row, an owner-only policy lets the owner change it. Anyone signed in can call your database directly with the public key that ships in your app, without using your UI.
How do I let users edit their name but not their plan?
Revoke the table-level privilege and grant only the safe columns: revoke update on public.profiles from authenticated, anon; grant update (display_name, avatar_url) on public.profiles to authenticated; Your RLS policy still limits them to their own row. An update that touches plan then fails with "permission denied for table profiles".
Column privileges broke my profile save. Why?
If your app sends the whole row on every save (including plan), the update touches a column the user no longer has rights to and fails, even when the value didn't change. Send only the edited fields, or use the trigger fix, which only rejects a real change to a protected column.
Who should change the plan column?
Only your server: a Stripe webhook handler or Edge Function using the service role or secret key, after it has verified the webhook signature. Never trust a plan value sent from the browser.
Is a separate table better than locking columns?
Usually, yes. Supabase calls column-level privileges an advanced feature and recommends RLS policies plus a dedicated table for user roles. Put plan, credits and roles in a table users can read but have no INSERT, UPDATE or DELETE policy on, and write it from the server.
Does this affect INSERT too?
Yes. If users create their own profile row from the browser and the insert policy only checks id = auth.uid(), they can insert plan = 'pro' on day one. Create profile rows with a server-side trigger on auth.users, or grant INSERT only on safe columns so plan takes its default.
Sources
- Supabase docs: Column Level Security
- Supabase docs: Custom Claims and Role-based Access Control (RBAC)
- PostgreSQL docs: GRANT (column privileges)
- @___rippa___ on X: "a plan column any user can update"
Related fixes
- AI agent pushed API keys to GitHub? git commit --no-verify skipped your pre-commit hook
- Fix a surprise AI API bill: rate limits and spend caps
- Your app is public to anyone with the link: a share link is not a login
- Triage Bolt's "RLS Policy Always True" warning: when it's fine and how to fix it
- Fix secrets leaked via Claude Code .claude/settings.local.json
- Fix "Your Cloud Firestore database has insecure rules" (Firebase email)
- Login lockout keyed only on email? Rate-limit by IP and account without locking users out
- Fix Lovable "Invalid API key" after rotating Supabase keys (anon, publishable, secret)
- Lovable won't publish because of security findings? What each finding means and how to fix it
- "Sign in with Google" lets anyone in: restrict who can use your app (allowlist, domain check, RLS)
- Fix Stripe sk_live keys left in MCP or agent config
- Fix Stripe webhook "No signatures found matching the expected signature for payload"
- Fix Supabase auth redirecting to localhost after deploy
- Fix Supabase Edge Function "blocked by CORS policy" (preflight)
- Fix Supabase "infinite recursion detected in policy for relation" (42P17) in RLS
- Form says success but no row in Supabase (or Stripe webhook returns 200 but writes nothing)
- Fix "new row violates row-level security policy for table" (Supabase)
- Supabase only returns 1,000 rows? Fix the silent max rows limit in Lovable and Bolt apps
- Fix Supabase "permission denied for table" (42501) on new tables after Oct 30, 2026
- Fix a Supabase public Storage bucket that lets anyone list or download your files
- Supabase Realtime leaking rows or not receiving changes: fix RLS and the publication
- Supabase RLS not working on the server? Your API uses the service_role or secret key
- Fix Supabase RLS policy USING (true) that makes a table publicly readable
- Your app's rules only live in the frontend: move them into Supabase
- Fix a Supabase SECURITY DEFINER function anyone can call through /rest/v1/rpc
- Fix Supabase .single() "JSON object requested, multiple (or no) rows returned" (PGRST116)
- Fix a Supabase view that bypasses RLS: security_invoker and revoking anon write grants
- Fix "404: NOT_FOUND" on refresh in a React/Vite app on Vercel (vercel.json rewrite)
- Fix "Module not found: Can't resolve" on Vercel (works locally)
- Is my Vite dev server exposed? Check --host / server.host and patch the RCE (GHSA-p4f5-76q4-ffq7)