PatchPaste · Guides
Last updated 30 October 2026
Supabase RLS using (true): why your AI fix made your data public
A common story: your app shows new row violates row-level security policy. You ask your AI editor to fix it, and it writes a policy like the one below. The error goes away. So does your privacy.
create policy "allow all" on notes for select using (true);
using (true) means every row passes the check. Anyone with your public anon key can read the whole table, and that key is in your site's JavaScript. RLS still shows as “enabled”, so things look fine, but it isn't protecting anything.
true policy and write policies that compare auth.uid() to an owner column like user_id. Also check your views and any is_admin or plan columns. Or scan your live app free to see which common tables strangers can read.1. Find permissive policies
Run this in the Supabase SQL editor:
select schemaname, tablename, policyname, cmd, roles, qual, with_check from pg_policies where schemaname = 'public' and (qual = 'true' or with_check = 'true');
Any table with user data that shows up here needs a fix. Also look in the Table Editor for tables marked RLS disabled. Supabase's Security Advisor flags many of these too.
using (true) is fine for data that is meant to be public, like a list of published blog posts, when it is on select only.
2. The real fix: limit rows to their owner
Make sure the table has an owner column, such as user_id uuid references auth.users. Then:
alter table notes enable row level security; drop policy if exists "allow all" on notes; create policy "read own notes" on notes for select to authenticated using ((select auth.uid()) = user_id); create policy "insert own notes" on notes for insert to authenticated with check ((select auth.uid()) = user_id); create policy "update own notes" on notes for update to authenticated using ((select auth.uid()) = user_id) with check ((select auth.uid()) = user_id);
Only add a delete policy if users really need to delete rows. Once RLS is on, nothing is allowed through the API with the public key until a policy allows it (Supabase docs: Row Level Security).
The first insert error usually happened because user_id wasn't being set. Fix that by sending user_id from the app, or by setting default auth.uid() on the column. Don't fix it by loosening the policy.
New table getting permission denied for table (error 42501) instead? That's a missing grant, not RLS. See the 42501 fix.
3. Trap one: views can skip RLS
By default, a Postgres view runs with the rights of the user who created it. In Supabase that is usually postgres, which skips RLS. So a view over your profiles table in the public schema can show every row, even when the table's own policies are right.
On Postgres 15 and above, Supabase says to set security_invoker = true so the view follows the table's policies:
alter view public.my_view set (security_invoker = true); -- or when you create it: create view public.my_view with (security_invoker = true) as select ...;
Another option is to move the view to a schema your API doesn't expose.
4. Trap two: users making themselves admin
This policy looks safe:
create policy "update own profile" on profiles for update using ((select auth.uid()) = id);
It limits which row a user can change, not which columns. If profiles also holds is_admin, plan or credits, a signed-in user can run this in the browser console:
await supabase.from('profiles').update({ is_admin: true }).eq('id', myId)Fixes, best first:
- Move privileged fields to their own table (for example
user_rolesorsubscriptions). Users can read their own row but have no insert or update policy. Only your server, webhooks or the service role write to it. This is what Supabase recommends for most apps. - Limit which columns can be updated. Supabase calls this an advanced feature (Supabase docs: column level security):
revoke update on table public.profiles from authenticated; grant update (display_name, avatar_url) on table public.profiles to authenticated;
- Add a trigger that rejects changes to privileged columns unless they come from a trusted role.
The same trap applies to roles kept in a user's user_metadata, which users can change themselves. Keep roles in app_metadata or in a protected table.
Quick checklist
- RLS is on for every table in exposed schemas
- No
using (true)orwith check (true)on private data - Every user-data policy checks
auth.uid() - Views use
security_invoker = trueor aren't exposed - Roles, plans and credits live where users can't write
- No
deletepolicies you don't need
using (true) FAQ
What does using (true) mean in a Supabase RLS policy?
It means every row passes the check. For a select policy, anyone the policy applies to can read the whole table. If it applies to the anon role, that is anyone holding your public anon key, which is in your site's JavaScript.
Is having RLS enabled enough?
No. RLS that is on but has a true policy is the same as no RLS for that action. What matters is what each policy allows.
Is using (true) ever OK?
Yes, for data that is meant to be public, like published blog posts, and only on select. Never use it on user data, or on insert, update or delete.
Does the service_role key follow these policies?
No. The service_role role has BYPASSRLS, so it skips every policy. Keep that key on the server only.
How do I test my policies?
Sign in as a normal test user. From the browser console, try to read another user's rows and to change a privileged column like is_admin. Both should fail. Also try reading the table while logged out.
My AI editor keeps writing true again. What should I do?
Tell it plainly: never use using (true) or with check (true) on user data, and scope every policy to auth.uid(). Then re-run the query on this page after every change.
Check your live app free
Paste your URL. We find your Supabase public key, test a short list of common tables read-only (at most one row, never stored), and check for leaked secret keys, exposed files and missing headers. We can't see your policies, so use this together with the query above. The report is free. Scans are free, so you can scan again after each AI edit.
Want to see one first? View a sample report.