Supabase RLS mistakes that still leak data

Published 2026-11-29 by Nordik. Written with AI from the sources listed at the end.

The short version

The risk
Row Level Security can be on, with policies in place, and data can still leak because a policy says something other than what you meant.
Does it affect you?
Yes, if your app keeps data in Supabase and an AI builder wrote or changed its policies.
What to do
Read Supabase's advisors, check your policies for the six mistakes below, paste the fix prompt for each one you find, then test with two accounts.

Rather not read it all? Copy this for your AI tool. Paste it into the tool you build with. It asks the tool to check your app for the problems in this guide and explain what it finds in plain words. Nothing is changed.

See the prompt
Check my Supabase Row Level Security policies for these six mistakes and do not change anything yet. 1. A condition of "true" on a table that holds user data. 2. A policy with no "to" clause, or one that targets the public role. 3. A condition with "or auth.uid() is null". 4. A rule that reads a role or permission from user_metadata or raw_user_meta_data. 5. A view over user data that ignores the policies (no security_invoker). 6. An UPDATE policy on an owned table without a "with check" on the owner column. For each, list the table and policy, say Pass or Fail, and explain it in plain words.
Jump to a part (10)
  1. Let Supabase point at the obvious ones first
  2. Mistake 1: a condition of true on private data
  3. Mistake 2: no "to" clause, so the rule covers visitors too
  4. Mistake 3: a branch that lets signed-out requests through
  5. Mistake 4: rules that trust user metadata
  6. Mistake 5: a view that ignores your rules
  7. Mistake 6: an update rule that lets a row change owner
  8. A note on speed
  9. Test every fix with two accounts
  10. Going further

Turning on Row Level Security (RLS) is the first step, and our plain-English RLS guide covers it. This page is for the next step: RLS is on, the policies are there, and data can still leak because a policy says something other than what you meant.

A policy is one rule that Postgres, the database software behind Supabase, adds to every request to a table. Each mistake below is described in Supabase's own documentation, with a way to spot it and a prompt you can paste into your AI builder, such as Lovable, Bolt or Cursor, to fix it.

Let Supabase point at the obvious ones first

Supabase's dashboard has advisors that check your database for known problems. Its documentation lists these checks, among others:

The advisor checks, by name (7)
  • rls_disabled_in_public
  • policy_exists_rls_disabled
  • rls_enabled_no_policy
  • rls_references_user_metadata
  • permissive_rls_policy
  • security_definer_view
  • auth_users_exposed

Open your project, find the advisors, and read every finding. The documentation also says some findings may be intentional, so check each one against what you meant before you change anything.

Mistake 1: a condition of true on private data

Supabase's documentation shows a policy for the anon role (visitors who are not signed in) with the condition true, and says it grants every unauthenticated visitor read access to every row. That is right for a table of public posts and wrong for profiles, orders or messages.

The same condition for the authenticated role lets every signed-in user read every row, which is how one customer ends up seeing another's data.

How to spot it: in the dashboard, open Authentication, then Policies, and look for any policy whose condition is just true on a table that holds private data.

Fix prompt

Review every Row Level Security policy that uses the condition "true". For any table that holds user data, replace it with a policy that only allows access when the row's owner column equals (select auth.uid()). Keep "true" only on tables that are meant to be public, and list those tables for me to confirm.

Mistake 2: no "to" clause, so the rule covers visitors too

Supabase's documentation says a policy with no "to" clause applies to the public role, which every role is a member of, including anon. A rule you wrote with signed-in users in mind can then also apply to visitors who never signed in. Adding "to authenticated" keeps anon requests out.

How to spot it: read each policy's target roles. If it says public, or names no role, ask whether visitors who are not signed in should really be covered.

Fix prompt

For every Row Level Security policy that has no "to" clause or targets the public role, add "to authenticated" unless the policy is meant for visitors who are not signed in. Show me each policy before and after.

Mistake 3: a branch that lets signed-out requests through

Supabase's documentation says auth.uid() returns null for any request without a user id, which includes every anon request, so a condition with an "or auth.uid() is null" branch returns every row to any request without a user id. It says plainly not to add that branch to let such requests through. AI builders sometimes add it to make an error go away.

How to spot it: search your policies and your migration files (the saved changes to your database, often in a folder named supabase/migrations) for "is null".

Fix prompt

Find every Row Level Security policy whose condition contains "auth.uid() is null" and remove that branch. If a page breaks because a visitor who is not signed in can no longer read something, tell me which page and table so I can decide whether that data should be public.

Mistake 4: rules that trust user metadata

Supabase keeps two kinds of extra data on each user. Its documentation says raw_user_meta_data can be changed by the signed-in user and is not a good place for authorization data, and that a policy relying on the user_metadata claim can create security issues. raw_app_meta_data cannot be changed by the user.

A policy that checks a role such as "admin" in user metadata lets any user make themselves an admin.

How to spot it: search your policies and migration files for user_metadata and raw_user_meta_data.

Fix prompt

Find every Row Level Security policy, function or check that reads a role or permission from user_metadata or raw_user_meta_data. Move that role or permission to app_metadata (which users cannot change) or to a separate table that only the server can write, and update the policies to read it from there.

Mistake 5: a view that ignores your rules

A view is a saved query that looks like a table. Supabase's documentation says views bypass RLS by default, because they are usually created with the postgres user, and that a view over a protected table hands out the rows its policies were meant to withhold.

On Postgres 15 and above, a view created with security_invoker = true obeys the policies of the tables underneath. On older versions, the documentation says to revoke access from anon and authenticated or move the view to a schema the API does not expose.

How to spot it: look for views in the Table Editor, or for "create view" in your migration files. The advisors' "security definer view" and "auth users exposed" checks point at the same problem.

Fix prompt

List every view in the public schema and the tables it reads. Recreate each view that reads user data with security_invoker = true so it follows the Row Level Security policies of those tables, or remove it if no page uses it. Tell me which views you changed.

Mistake 6: an update rule that lets a row change owner

Supabase's documentation explains that for an update, the "using" part decides which existing rows a user may change, and the "with check" part decides what the changed row may look like, which stops a user from reassigning the row's user_id to someone else. It also says an update needs a matching select policy to work as expected.

A policy with only "using" lets a user hand their row to another account, or take a value they should not set.

How to spot it: for every update policy on a table with an owner column, check that it has a "with check" condition on that column too.

Fix prompt

For every UPDATE Row Level Security policy on a table that has an owner column, make sure it has both a "using" and a "with check" condition requiring the owner column to equal (select auth.uid()), and that a matching SELECT policy exists. List the policies you changed.

A note on speed

Supabase's documentation also recommends writing auth.uid() as (select auth.uid()) inside policies and indexing every column your policies filter on, so rules stay fast as a table grows. The fix prompts above already use that form.

Test every fix with two accounts

  1. Make two test accounts and create a record with one.
  2. Try to read and change it with the other.
  3. Try again while signed out.

Supabase's documentation notes that a rule that filters rows raises no error and simply returns nothing, so an empty page after a fix is often the rule working, not a bug.

Going further

For a full routine for apps built with Lovable, see six checks for Lovable apps.

Sources

Each source below was accessed on the date shown. Documentation changes over time, so check the source for the current wording.

  • Supabase documentation, Row Level Security, accessed 2026-11-29
  • Supabase documentation, Advisors, accessed 2026-11-29

See what your live app shows strangers

Paste the link to your app: in under a minute the free scan shows what your live app hands to any visitor, and where to look first. No sign-up, and it never signs in or changes anything.

Run a free scan

Want the code itself read? Order the $49 audit or see a sample report. Your card is held and charged only when your report is delivered. It is not a pentest: the audit is done by AI, and a second AI checks each serious finding.