Search Psychevus

12 results available.
↑ ↓ to navigate ↵ to open · esc to close

Supabase · Lovable · Bolt · PostgreSQL

Supabase RLS is enabled, but my data is still public. Why?

Row Level Security can be on and still let anyone read every row. How using (true), PUBLIC role defaults and OR-ed permissive policies leak data, and the exact policies that fix it.

Short answerBecause RLS only applies the policies you wrote, and one permissive policy with using (true) lets every caller it applies to see every row. Policies are combined with OR, so a single broad policy overrides every careful one. Policies without a TO clause apply to PUBLIC, which includes the anon role whose key ships in your app. Replace using (true) with a condition that ties the row to the caller, such as (select auth.uid()) = user_id.

What RLS actually does

Supabase exposes your public schema through its Data API, and the anon and authenticated roles can query those tables. Enabling Row Level Security doesn't hide anything by itself: it switches each table from "every row" to "only the rows a policy allows". The safety is entirely in the policies.

AI builders and dashboard templates often generate a policy named "Enable read access for all users" or "Enable read access for authenticated users" with using (true). Both look reasonable in a list of policies. Both mean the row is visible to everyone the policy applies to.

The policy that leaks
create policy "Enable read access for authenticated users"
  on public.invoices for select
  to authenticated
  using (true);   -- every signed-in user, every row

Three rules that cause most leaks

  • Permissive policies are OR-ed. If one SELECT policy says true, it doesn't matter how strict the others are.
  • No TO clause means PUBLIC, and PUBLIC includes anon: anyone holding the public key in your JavaScript.
  • FOR ALL covers select, insert, update and delete. A broad FOR ALL policy is a broad write policy too.

The fix

Scope every policy to the caller. For per-user data compare the owner column; for teams, check membership through a helper function in a private schema, so the policy stays readable and fast.

Owner and team policies
drop policy "Enable read access for authenticated users" on public.invoices;

-- one user owns the row
create policy "Owners read their invoices" on public.invoices
  for select to authenticated
  using ((select auth.uid()) = user_id);

-- or: a team owns the row
create function private.my_workspaces() returns setof uuid
  language sql stable security definer set search_path = ''
as $$ select workspace_id from public.workspace_members
      where user_id = (select auth.uid()) $$;

create policy "Members read workspace invoices" on public.invoices
  for select to authenticated
  using (workspace_id in (select private.my_workspaces()));

Wrapping auth.uid() in (select …) lets Postgres evaluate it once per query instead of once per row, which Supabase recommends for performance. Add matching INSERT, UPDATE and DELETE policies, and give UPDATE a WITH CHECK so a user can't move a row to someone else.

Check it yourself

Sign in as one test user and, in the browser console, query another user's rows: await supabase.from('invoices').select('id').eq('user_id', '<other user id>'). The result must be empty. Then paste your schema into the RLS simulator below: it shows, table by table, whether a stranger, any signed-in user or only the owner can read, create, change and delete.

Simulate your RLS policies (free, in your browser)

Questions

Does the Supabase Security Advisor catch this?

The advisor warns when RLS is disabled on an exposed table. A policy with using (true) is valid SQL, so a table can pass the "RLS enabled" check and still be readable by everyone.

Is using (true) ever fine?

For SELECT on genuinely public content, like published blog posts, yes, preferably with a condition such as published = true. Never for writes, and never on tables holding personal or business data.

Updated 18 November 2026 · by

Reading about a flaw is the easy part. A Launch Check finds every one of these in your app, with evidence and a fix prompt for each, in two business days.

Get a fixed quote

Related

YOUR VISIT, YOUR CHOICE

Privacy, by intention.

You decide what stays on your device. You can change your choice at any time.

Essential

Saves your privacy choice. Administrator sign-in uses a secure session cookie.

Always on
Full privacy notice ↗