Your first check is free. No card needed.Run your free check

Why is my Supabase row level security not working?

Usually for one of two opposite reasons. Either it blocks what it should allow, with an empty list or a "new row violates row-level security policy" error, because no policy matches the role and user the request really carries. Or it allows what it should block, because a table has no row level security, a policy is too broad, or the request goes through something that skips policies, such as a view, a secret key or a direct database connection. The checks below tell the two apart.

Saqr (usesaqr.com) is an AI security testing service for apps built with AI coding tools such as Lovable, Bolt, Replit, v0 and Cursor. From $19 a month, cancel any time. Tests only apps you have shown are yours.

Why do I get an empty list instead of an error?

Because a policy that matches no rows filters them out quietly. Supabase's own troubleshooting page says an empty result "usually" means row level security is on with no policy, or the request does not meet the policy (Supabase). The most common reason a request does not meet a policy is that it carries no signed-in user: auth.uid() returns null for any request whose token has no user in it, so a condition like auth.uid() = user_id never matches (row level security).

That is often a timing problem in the app, not a policy problem: the query runs before the session has loaded, so it goes out as anon.

What skips row level security altogether?

Three things, and each one makes policies look broken in the other direction:

  • A secret key with no user token. The secret key, like the legacy service_role key, uses a Postgres role with the bypassrls attribute, so a request made with it and no user token skips every policy (row level security).
  • A view. Views bypass row level security by default, because they are usually created by the postgres user. On Postgres 15 and above, security_invoker = true makes a view obey its tables' policies (row level security).
  • A direct database connection as a superuser or the table's owner. PostgreSQL applies no policies to superusers and roles with BYPASSRLS, and table owners skip them too unless the table is set to FORCE ROW LEVEL SECURITY (PostgreSQL). Server code that connects with the database connection string, for example through an ORM, is in this position, so it has to check permissions itself.

How do I find which cause it is?

Seven checks on your own project, the first four for "it blocks too much" and the last three for "it allows too much". Do these checks only on an app you own or have written permission to test, with test accounts you created.

  1. Confirm the request carries a signed-in user

    Supabase suggests a small SQL function that returns auth.jwt(), called with supabase.rpc() at the same point in your app as the failing query. If the role it shows is anon or service_role, there is no user session at the time of the call (Supabase). Fix the app so it waits for the session, then drop the function.

  2. Name the role in every policy

    A policy with no to clause applies to public, a role every role belongs to, including anon. Supabase recommends always naming the role, for example to authenticated (row level security). Read each policy's roles with the pg_policies query in the row level security test.

    If it fails: Make each user see only their own rows

  3. Give inserts and updates a WITH CHECK, and updates a SELECT policy

    using decides which existing rows a request can touch; with check decides whether the row it writes is allowed (row level security). An insert that does not set the owner column to the signed-in user fails the check, which is the "new row violates row-level security policy" error. An update also needs a matching select policy, or it changes nothing (row level security).

    If it fails: Make each user see only their own rows

  4. If Realtime stopped, check the SELECT policy

    Postgres Changes authorizes every event against each subscriber, so a user who cannot select a row does not receive its changes. Supabase also notes that delete events are not filtered by your policies, because Postgres cannot check access to a row that no longer exists (Postgres Changes). Do not put private data in what a delete event carries.

  5. Find tables that are open to everyone

    Run select tablename, rowsecurity from pg_tables where schemaname = 'public'; and look for false; a table in an exposed schema without row level security is readable and writable by any role with a grant on it (row level security). Then run the Security Advisor, which flags tables without row level security and policies that are always true (Advisors).

    If it fails: Turn on row-level security for every table

  6. Look for what skips policies

    List the views in exposed schemas and recreate them with security_invoker = true, or move them out. Search the code for the secret key and for the database connection string, and confirm both are used only on the server, in code that checks who is asking before it reads or writes. A secret key anywhere in the browser's scripts is a leak: rotate it first.

    If it fails: Rotate an exposed service key and move it to the server

  7. Test both directions with two accounts

    Do not settle it by turning row level security off: Supabase's own troubleshooting suggests that only briefly, to diagnose. Once policies are fixed, call each table signed out with only the publishable key, then as a second test account asking for the first account's rows. The row level security test has the requests.

    If it fails: Make each user see only their own rows

What should I do after fixing it?

Write the fixed behaviour down as tests, so the next change cannot quietly undo it: the row level security test explains Supabase's database tests. If your AI coding tool wrote the policies, paste the fix prompt for owner-only rows and check the result on the running app, not by asking the tool.

Facts worth knowing, with sources

  • auth.uid() returns null for any request whose token has no user, so owner checks never match signed-out requests. Source
  • A policy with no to clause applies to public, which includes the anon role. Source
  • An UPDATE needs a matching SELECT policy. Source
  • Superusers and roles with BYPASSRLS skip row level security, and table owners skip it unless the table forces it. Source
  • Row level security policies are not applied to Realtime DELETE events. Source

Questions

Why does my Supabase query return an empty array when the table has data?

Usually because row level security is on and no policy matches the request. The most common case is a request with no signed-in user: auth.uid() is null, so an owner check never matches. Check the role the request carries before changing the policy.

Why do I get "new row violates row-level security policy"?

The row you are inserting or updating fails the policy's with check condition. Most often the owner column is not set to the signed-in user's id, or there is no insert policy for the role the request uses.

Should I turn off row level security to make my app work?

No. A table in an exposed schema without row level security is readable and writable by any role with a grant on it, which includes visitors using your public key. Write the policy that allows the legitimate request instead.

Why can my server read everything even with policies on?

Because it probably uses the secret key without a user token, or connects to the database directly as a superuser or the table's owner. Both skip row level security, so that server code must check who is asking itself.

Where does Saqr fit?

These checks cover what is on the list, on the pages you think to try. Saqr runs this kind of test on the live app for you, in a real browser and including signed-in pages, and shows the proof for each finding with a fix prompt for your AI coding tool. After you fix something, ask it to recheck. Plans are Starter at $19 a month and Pro at $49 a month, and you can cancel any time.

Every task ends in three PDFs. These are the ones from a task on a demo shop, unedited:

No test can promise an app is secure. A task tells you what Saqr found that day, with proof.

To see what a finished test looks like, open the sample reports.

Sources

The statements above were checked against these pages on 25 November 2026. Products change; follow the links for the current wording.

  1. Supabase documentation: Row Level Security
  2. Supabase troubleshooting: Why is my select returning an empty data array?
  3. Supabase documentation: Postgres Changes
  4. Supabase documentation: Advisors
  5. PostgreSQL documentation: Row Security Policies

Saqr is independent and is not affiliated with Supabase or PostgreSQL. Each name is a trademark of its owner.