PatchPaste · Guides
Last updated 15 November 2026
Supabase "RLS references user metadata": your users can make themselves admin
Supabase Security Advisor shows Security policy relies on user-editable data (0015_rls_references_user_metadata, level ERROR). It usually means your Lovable or Bolt app checks a role like is_admin or plan that lives in user_metadata, and every signed-in user can change their own user_metadata.
user_metadata. Move roles and plans to app_metadata, which users can't change, or to a separate table users can read but not write. Then rewrite the policy and test it by trying to promote yourself from the browser console.Why it is an ERROR
Supabase's lint 0015 docs say user_metadata "is designed to be manipulated by the user themselves" and can be changed "to any value (there is no validation)". Their example of an insecure policy:
create policy bad_policy on public.foo for select to authenticated using ( (( select auth.jwt() ) -> 'user_metadata' ->> 'is_admin' )::bool );
And the bypass, from the same page. Any signed-in user can run this in your app's browser console:
await supabase.auth.updateUser({ data: { is_admin: true } })Once their token refreshes, the policy reads is_admin: true and lets them in. If the policy guards an admin table, payments or other users' records, that is a full bypass.
1. Find the policies
Run this in the Supabase SQL editor:
select schemaname, tablename, policyname, cmd, roles, qual, with_check from pg_policies where qual ilike '%user_metadata%' or with_check ilike '%user_metadata%';
Also search your migrations and any security definer helper functions (such as an is_admin() function) for user_metadata or raw_user_meta_data. A function that reads it has the same problem even if the policy only calls the function.
Check your sign-up code too. If it passes role, plan or is_admin in options.data, that is where the value is coming from.
2. Choose a safe home for the role
Supabase's RLS docs draw the line: raw_user_meta_data "can be updated by the authenticated user" and "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." Two options:
- app_metadata. Good for a simple role or a list of team ids. Set it only from trusted server code that uses the service role (for example an Edge Function or your backend), never from the browser.
- A roles table. For example
user_roles (user_id, role)with RLS on, a select policy so users can read their own row, and no insert, update or delete policy for users. Only your server, webhooks or the service role write to it. This also avoids the stale-token delay below.
3. Rewrite the policy
With app_metadata:
drop policy if exists bad_policy on public.foo; create policy "admins read foo" on public.foo for select to authenticated using ( (( select auth.jwt() ) -> 'app_metadata' ->> 'is_admin' )::bool );
Or with a roles table:
create policy "admins read foo" on public.foo
for select
to authenticated
using (
exists (
select 1 from public.user_roles r
where r.user_id = (select auth.uid())
and r.role = 'admin'
)
);If two tables' policies end up reading each other, see RLS infinite recursion (42P17) for the security definer helper pattern. Give any such helper set search_path = '' and keep it out of exposed schemas, as Supabase advises (why).
The stale token catch
Supabase's RLS docs warn that a JWT "is not always up-to-date": after you change app_metadata, policies using auth.jwt() won't see it until the user's token is refreshed. That works both ways. Removing someone's admin flag takes effect only when their token refreshes, so a roles table is the better choice where revoking access quickly matters.
Fixes to refuse
- "Hide the admin button unless the user is an admin." The data is still reachable through the API with the anon key. The check has to be in the policy.
- "Validate the role in the sign-up form." The user can call
updateUserany time after sign-up, so a form check changes nothing. - "Put is_admin on the profiles table instead." Only safe if users can't update that column. A plain "update own profile" policy lets them. See trap two in RLS using (true).
- "Use the service_role key so the check passes." It bypasses every policy, and Supabase says never to use it in the browser. See exposed service_role key.
Check it worked
- Advisor: re-run Security Advisor. Lint 0015 should be gone.
- As a normal user: sign in as a test account, run
await supabase.auth.updateUser({ data: { is_admin: true } })in the console, sign out and in again, and try to read the admin data. It should still be refused. - As a real admin: confirm the admin can still do their job after a token refresh.
- Logged out: in a private window, confirm the same tables return nothing.
- From outside: scan the live URL to confirm common tables don't answer to your public key and no secret key is in your JavaScript. PatchPaste can't sign in or read your policies, so step 2 is the real test for this lint.
A prompt to paste into Lovable
Supabase Security Advisor reports 0015_rls_references_user_metadata. Fix it without disabling RLS, without adding using (true) policies and without using the service_role key in the client. 1) List every RLS policy and every database function that reads user_metadata or raw_user_meta_data, and every place the app writes role, plan or admin fields into user metadata (including sign-up options.data). 2) Create a public.user_roles table (user_id references auth.users, role text) with RLS enabled, a select policy so users can read only their own row, and no insert, update or delete policies for users. 3) Write a migration that copies existing role values from raw_user_meta_data into user_roles. 4) Rewrite each policy to check user_roles with exists (... where user_id = (select auth.uid()) ...) instead of user_metadata. 5) Stop writing roles into user metadata from the frontend. 6) Tell me how to test it: as a normal user, run supabase.auth.updateUser({ data: { is_admin: true } }) and confirm admin data is still refused.Related: Supabase RLS check, RLS Disabled in Public, Security Definer View and Is my Lovable app secure?
Supabase user_metadata and RLS FAQ
What does 0015_rls_references_user_metadata mean?
Supabase's Security Advisor lint 0015 (level ERROR) says a Row Level Security policy reads user_metadata. Supabase's summary is "Security policy relies on user-editable data": end users can change their own user_metadata to any value, with no validation, so a policy that trusts it can be bypassed.
Can a user really change their own user_metadata?
Yes. Supabase's docs give the example updateUser({ data: { is_admin: true } }) in supabase-js. Any signed-in user can run that from the browser console of your app, using the public anon key that is already in your JavaScript.
What is the difference between user_metadata and app_metadata?
Supabase's RLS docs say raw_user_meta_data can be updated by the authenticated user, so it is not a good place for authorisation data, while raw_app_meta_data cannot be updated by the user, so it is a good place for it. Both are readable in policies through auth.jwt().
My Lovable app stores the role at sign-up. Is that the problem?
Often, yes. Sign-up forms commonly pass extra fields such as role, plan or company through options.data, which lands in user_metadata. That is fine for a display name. It is not fine for anything a policy uses to decide access.
I moved the role to app_metadata but the change doesn't show up. Why?
auth.jwt() reads the user's current token. Supabase's docs warn that a JWT is not always up to date: a change to app_metadata is not seen by policies until the user's JWT is refreshed, for example after signing out and in again.
Can PatchPaste find this?
No. PatchPaste's free scan checks a live app from outside and cannot read your policies or sign in as a user. It checks whether common Supabase tables answer to the public anon key without a login, secret keys in your shipped JavaScript, exposed .env, .git and source maps, and security headers. Use Security Advisor and the test on this page for lint 0015.
Policies fixed? Check the rest of the live app for free
Paste your live URL for a free A to F report. PatchPaste checks whether common Supabase tables answer to your public anon key without a login (read-only, at most one row, discarded), searches the JavaScript your site sends for secret keys, and flags exposed .env/.git/source maps and missing headers. It does not sign in or read your policies. Fix prompts for that report are a one-off £9 (or £29 for 10). Scans are free to rerun after each change.
Want to see one first? View a sample report.
Sources (checked 15 Nov 2026): Supabase Database Advisors, lint 0015_rls_references_user_metadata (level ERROR, summary, the insecure policy and the updateUser bypass); Supabase Row Level Security (auth.jwt(), raw_user_meta_data versus raw_app_meta_data, JWTs not always up to date, security definer functions). Screen wording varies between Supabase Studio and Lovable.