Skip to main content
Sealgap
App security checks 6 min read Daniel Nielsen

RLS Is On and the Table Is Still Open: Five Policies to Look For

Five Supabase policies that leave a table open while RLS counts as enabled: using (true), no role, an editable role column, unchecked inserts, and views.

A table in Supabase can show the green "RLS enabled" label and hand every row to anyone who asks. The label says that policies decide. It does not say what they decide, and an AI app builder writes policies to make the app work, not to keep two customers apart.

These are the five policies that most often leave a table open in a delivered app, how each one looks in the database, and how to tell whether it is a mistake or the intention. They apply to apps where the browser talks to Supabase directly, which is how Lovable and Bolt build by default.

1. A condition that is always true

The shortest policy that makes an app work is the one that lets everything through:

create policy "Users can read orders"
  on orders for select
  to authenticated
  using (true);

The name sounds right and the app behaves. Each user sees their own orders, because the screen asks for them with a filter. The filter is in the browser. Anyone with an account can send the same request without it and receive every order in the table.

A condition of true is correct for data that is meant to be shared, such as a product list or the opening hours of a shop. On a table with a column that points to an owner, it is almost always a leftover from getting the first screen to load. The fix is to compare that column with the person asking:

using (user_id = (select auth.uid()))

2. A policy that does not say who it is for

A policy can name the roles it applies to. When it names none, PostgreSQL applies it to everyone, as its documentation for CREATE POLICY describes. In Supabase "everyone" includes the role used for visitors who have not signed in.

Combined with a condition of true, this opens the table to the whole internet: the app's public key is in its JavaScript, and that key is all a request needs. Read the list of policies in the dashboard and look at the role column. A policy for "public" on a table with customer data deserves a second look, however harmless its name is.

3. A user may change their own row, and the row says what they are

Row Level Security works on rows. It does not work on columns. A common policy lets each user update their own profile:

create policy "Users can update own profile"
  on profiles for update
  to authenticated
  using (id = (select auth.uid()));

That is reasonable until the profile table also holds a column such as role, plan or is_admin. The policy lets the user change any column in their row, including that one. A request from the browser's console is enough to turn an ordinary account into an administrator, and every other policy that trusts the column then lets that account in.

Keep what a user is in a table the user cannot write to, or take away the right to update that column with a column-level grant. The test is simple: sign in as an ordinary test user and try to change the column.

4. An insert that does not check whose row it is

For new rows, the condition that counts is the one after "with check". A policy that says with check (true) lets a signed-in user add a row with any owner they like:

create policy "Users can add notes"
  on notes for insert
  to authenticated
  with check (true);

The app always sends the current user's ID, so nothing looks wrong. A request written by hand can put another customer's ID in the owner column, and the note then appears in that customer's account. For most tables the check should be the same comparison as in the first section.

There is one case where an open insert is the intention: a contact form or a waiting list that visitors fill in without an account. That is fine as long as nobody can read the table back, and as long as you have thought about what happens when someone fills it with junk.

5. A view on top of a protected table

This one surprises experienced developers too. A view in PostgreSQL reads its tables with the rights of the person who created it, not of the person who asks. The policies on the table underneath are therefore skipped. A view made to simplify one screen, such as a list of order totals, can hand out every row of a table whose own policies are correct.

PostgreSQL 15 added a setting that makes a view follow the caller's rights instead, described under security_invoker in the documentation for CREATE VIEW:

alter view order_totals set (security_invoker = true);

Views are easy to overlook because they are not in the list of tables. Ask for each one without signing in. If rows come back and the table underneath is protected, this is the reason.

"Signed in" is wider than it sounds

Three of the five policies above are written for signed-in users, and it is tempting to file them under small risk: at least the person has an account. How much that is worth depends on the sign-up in front of it.

If the project lets anyone create an account without confirming an email address, "signed in" means "filled in a form with a made-up address". If anonymous sign-in is switched on, a visitor gets a signed-in session without creating an account at all, and according to the Supabase guide to anonymous sign-ins that session uses the same role as a real user. A policy that says "to authenticated using (true)" is then one click away from public.

How to find them without reading every policy

Reading policies helps, and in a large project it is slow and easy to get wrong. Behaving like a user is faster and harder to fool. Create two test accounts and give each some data. Then, with the app's public key and nothing else:

  • ask for each table and view without signing in
  • sign in as the first user and ask for the second user's rows
  • on a copy of the project, as the first user, try to change a row that belongs to the second, and a column that says what the first user is

Whatever comes back is what a stranger would get. How to test whether one user can read another user's data has the exact requests. The two-user test is the same idea as a routine, and the handover checklist puts it next to the other checks worth doing before a client takes over.

Do it again after every round of prompts. An AI app builder adds a table in seconds, and the new table gets whatever policy made the new screen work. Row Level Security that passed in March says nothing about the table added in April.

Keep reading

See what one of your own apps answers.

The free check looks at an app from the outside: whether it answers, its certificate, its browser protections and keys in its public code.