Skip to content

All posts

Supabase row level security, tested in seven cases

We ran seven Supabase row level security setups on a local Postgres 17 stand-in and pasted the real output. What leaked, what held, and each fix.

· Styver Solutions

Supabase row level security (RLS) is a set of Postgres policies that decide which rows each request may read or write. We ran seven common setups, and four let another user or an anonymous visitor reach rows they should not.

We built Styver, so we are not neutral. Checking these rules is part of every production check with a written report we run on AI-built apps.

The output blocks below are real psql output from a run on 23 November 2026, trimmed to the lines that matter. It ran in a throwaway Docker container on PostgreSQL 17.11. That is a Postgres stand-in for Supabase, and no Supabase project was involved.

How we tested it

We created the three roles Supabase's API uses: anon, authenticated and service_role. The service_role got the bypassrls attribute, as the Supabase docs describe it. A stand-in auth.uid() function reads the user id from the request.jwt.claims setting.

One table, notes, holds two rows. Alice owns "Alice private note" and Bob owns "Bob private note". Each case switches role and user, then runs one query.

The script is 67 lines of SQL. We ran it a second time in a fresh container the same day and got the same output.

What happens if RLS is off?

Anyone with a grant on the table reads every row. Our anon role read both private notes:

=== CASE 0: RLS off (a table created in SQL with no ALTER ... ENABLE). anon reads everything ===
 id |        body        
----+--------------------
  1 | Alice private note
  2 | Bob private note
(2 rows)

This happens most with tables made in SQL. Supabase says "Tables created through the Supabase Dashboard have RLS enabled by default". It also asks you to "Enable RLS explicitly for tables created in the SQL Editor or through another tool".

The fix is one line: alter table notes enable row level security;

Why does my Supabase query return no rows after enabling RLS?

Because RLS with no policy denies everything, and it does so without an error. The Postgres docs call this a "default deny" policy. Both anon and Alice counted zero rows:

 anon_rows 
-----------
         0
 alice_rows 
------------
          0

Writes fail just as quietly. We gave owners a select policy and no update policy. Bob then tried to overwrite Alice's note. Postgres replied UPDATE 0, and her note was unchanged.

This is the safe way to fail. The danger is the shortcut people reach for to make the empty screen go away, which is the using (true) case further down.

Does with check (true) let users write rows as someone else?

Yes. An insert policy with with check (true) accepts any row from any signed-in user. Bob inserted a note carrying Alice's user_id, and it landed as hers.

 id |               user_id                |               body               
----+--------------------------------------+----------------------------------
  3 | aaaaaaaa-0000-0000-0000-000000000001 | Forged by Bob, shows up as Alice

The fix ties the new row to the caller, with with check (user_id = auth.uid()). Bob's second attempt then failed:

ERROR:  new row violates row-level security policy for table "notes"

Supabase's RLS page describes the same guard. A with check expression means "a user cannot create a row that belongs to someone else".

GuardLayer's guide (dated July 1, 2026) applies this to updates: "The real footgun is appending with check (true) to make a write work". We tested the insert form only.

Does an update policy need WITH CHECK?

In our run, a policy with only USING was enough to stop an owner giving a row away. Alice's update policy was using (user_id = auth.uid()). She tried to set her note's user_id to Bob's, and Postgres refused.

ERROR:  new row violates row-level security policy for table "notes"

The Postgres docs explain why: "If only a USING clause is specified, then that clause will be used for both USING and WITH CHECK cases." Supabase's RLS page says the same.

Some guides read differently. SprintX (29 Jul 2026) covers policies that omit WITH CHECK. It says "a user can update a record they legitimately own and reassign its owner column to somebody else". Our USING-only run did not reproduce that.

Our rule of thumb is to write WITH CHECK out anyway. A reviewer can then see what the new row must look like without knowing the default.

Do Supabase views bypass row level security?

Yes, by default. Bob saw one row in the table and all three through a plain view over it.

 bob_sees_through_plain_view 
-----------------------------
                           3
 bob_sees_table_directly 
-------------------------
                       1

Supabase warns that "Views bypass RLS by default because they are usually created with the postgres user." Our view was owned by the container's postgres superuser, and RLS does not filter a superuser.

Supabase's fix for Postgres 15 and above is security_invoker = true. Per the Postgres docs, "the policies and permissions of the invoking user are used instead". After alter view notes_view set (security_invoker = true); Bob saw one row again:

 bob_sees_through_invoker_view 
-------------------------------
                             1

What does using (true) expose to anonymous users?

Every row the anon role has a grant on. After we added using (true) for anon and authenticated, an anonymous request counted all three notes.

 anon_rows_after_using_true 
----------------------------
                          3

Supabase says such a policy "grants every unauthenticated visitor read access to every row the role can already reach through grants. Use it only for data that is meant to be public."

The same case showed what an anonymous request looks like to a policy. With no JWT, auth.uid() returned null (uid_is_null = t), so user_id = auth.uid() matches nothing. Supabase recommends auth.uid() IS NOT NULL AND auth.uid() = user_id "to avoid confusion and make your intention clear".

Does the service role key bypass RLS?

Yes. The service_role read all three notes with RLS on and every policy in place.

 service_role_rows 
-------------------
                 3

Supabase's docs say a secret key "authorizes access through the service_role Postgres role, which has the bypassrls attribute." They add one limit: "A secret key bypasses RLS only when the request carries no user access token."

Their advice is plain: "Never use a secret key in the browser or expose it to customers." Keep it in server code and environment variables.

How do I audit my own Supabase project?

Run these three read-only queries in the SQL Editor. We tested them on PostgreSQL 17.11 against a schema built to trip each one, and not on a live Supabase project.

-- 1. Tables in public with RLS off
select relname as rls_off from pg_class
where relnamespace = 'public'::regnamespace and relkind in ('r', 'p') and not relrowsecurity;

-- 2. Policies that let every row through
select tablename, policyname, cmd, qual, with_check from pg_policies
where schemaname = 'public' and (qual = 'true' or with_check = 'true');

-- 3. Views that run as their owner (no security_invoker)
select relname as owner_rights_view from pg_class c
where relnamespace = 'public'::regnamespace and relkind = 'v'
  and not exists (select 1 from pg_options_to_table(c.reloptions)
                  where option_name = 'security_invoker' and lower(option_value) in ('true', 'on', '1', 'yes'));

Each row they return deserves a look. A true policy can be right for data meant to be public, such as published blog posts.

The queries cannot see a secret key in your front-end bundle. Our free 10-point launch checklist covers that check and the RLS one, with a source for each.

If you would rather hand it over, see what the production check covers. It is $490 for a written report in 3 to 5 working days, and fixes are priced in writing before any work.

Book the production check

Tested by the Styver team on 23 November 2026 on PostgreSQL 17.11.

Report in 3 to 5 working days. A personal reply within one working day.

Book the production check$490