Skip to main content
Back to blog

DECEMBER 1, 2026

Supabase RLS: How to Check an AI-Built App

Your Supabase publishable key is in your JavaScript, and that is by design. What protects the data is row level security. Here is how RLS decides who sees which row, the seven ways AI-built apps get it wrong, and how to check and test your own project.

By Umar Abdullah · Cybersecurity

Light cover reading "The key is public. The rows should not be." beside a Supabase RLS table where each row is locked to its owner
December 1, 202610 min read

Short answer

In a Supabase app, the browser talks to the database through an API, using a key that anyone can read from your JavaScript. Row level security (RLS) is what decides which rows that key can reach. So checking an AI-built app comes down to three questions for every table: is RLS on, do the policies tie each row to its owner, and has someone tested them as the wrong user? In the 35+ audits we reported on in September 2026, 16 had database rules that were too open, on Supabase or Firebase.

Why does the database do the access control?

In a traditional app, the browser calls your server, and your server decides what to fetch. With Supabase, the browser can query tables directly through the Data API. The key it uses is public on purpose. Supabase's API keys documentation lists the publishable key as "Safe to expose online: web page, mobile or desktop app, GitHub actions, CLIs, source code", and gives the reason elsewhere on the same page: "Anyone can read it, so it only reaches what Row Level Security allows".

That sentence is the whole security model. If RLS is not doing its job on a table, the public key reaches everything in it. Supabase's own database advisor describes a public table without RLS this way: "Anyone with your project URL can read, edit, and delete all data in this table because Row-Level Security is not enabled."

A note on names. Supabase now calls the two keys the publishable key and the secret key. Older projects show them as anon and service_role, which the documentation calls the legacy versions, and it says those are being deprecated in early 2027. The roles inside the database are still called anon and authenticated.

How does RLS decide who sees a row?

Four rules cover most of it. They come from Supabase's Row Level Security guide and the PostgreSQL manual.

  • Every request becomes a role. Supabase maps a signed-out request to the anon role and a signed-in request to authenticated.
  • RLS on with no policy means no access. PostgreSQL says: "If no policy exists for the table, a default-deny policy is used, meaning that no rows are visible or can be modified."
  • A policy is a condition per row. using checks rows that already exist, for reads, updates and deletes. with check checks the row a write would create. In Supabase's words, for an update the using clause "decides which existing rows can be updated" and the with check clause "decides what the resulting row is allowed to look like".
  • Policies add up. PostgreSQL combines ordinary (permissive) policies with OR. One loose permissive policy opens the table for the operation and role it covers, however strict the other permissive policies are.
  • Here is a full set for a table where each row belongs to one user. The table is our example; the pattern follows Supabase's guide, which says to write a separate policy for each operation and to always name the role with to.

    alter table public.invoices enable row level security;
    
    create policy "Owners read their invoices" on public.invoices
      for select to authenticated
      using ( (select auth.uid()) = user_id );
    
    create policy "Owners create their invoices" on public.invoices
      for insert to authenticated
      with check ( (select auth.uid()) = user_id );
    
    create policy "Owners update their invoices" on public.invoices
      for update to authenticated
      using ( (select auth.uid()) = user_id )
      with check ( (select auth.uid()) = user_id );
    
    create policy "Owners delete their invoices" on public.invoices
      for delete to authenticated
      using ( (select auth.uid()) = user_id );
    

    auth.uid() returns the ID of the user making the request. Supabase recommends wrapping it in select, as above, and adding an index on every column your policies filter on.

    Diagram of a request to a Supabase table: the publishable key maps to the anon or authenticated role, then grants, then RLS and its policies decide which rows come back, while a secret key skips the policies
    Diagram of a request to a Supabase table: the publishable key maps to the anon or authenticated role, then grants, then RLS and its policies decide which rows come back, while a secret key skips the policies

    Why do AI-built apps get this wrong so often?

    Our view: because nothing looks broken. The app works in the demo whether RLS is on with correct policies or off entirely.

    UpGuard reported in September 2026 that it gathered about 300,000 domains showing signs of Supabase use, asked each one for a "users" table, and "found 16,326 Supabase databases exposing readable tables." From the table schemas, 55.8% of those had indicators of personal information. UpGuard notes its own bias: the data skews toward personal information partly because it asked for a users table.

    Its explanation of the cause is worth reading closely: "Tables created programmatically through the API, which is how coding agents interact with Supabase, do not enable RLS by default." Supabase's API security guide gives the other half: "Tables created through the Supabase Dashboard have RLS enabled by default." So a table a person clicks together starts protected, and a table an agent creates with SQL may not.

    Our own audits point the same way, with limits. Of the 35+ we reported on in September 2026, 16 had database rules that were too open: Supabase RLS off, or public Firebase rules. Only broken authorization, in 18, was a more frequent Critical finding. We did not break the 16 down by stack or by whether the code was AI-generated. As we wrote in that report, the code does what it was asked to do; nobody asked for the check.

    Ship faster with senior engineers

    Direct collaboration, AI-augmented delivery, and no agency markup.

    Get in touch

    Seven mistakes to look for

    The list and its order are ours. The mechanics behind each one are from the documentation linked above.

    Mistake What goes wrong How to spot it
    RLS is off on a table The public key reaches every row the role's grants allow Query 1 below; advisor lint 0013
    A policy exists but RLS is off The policy has no effect Advisor lint 0007
    A policy that is always true Everyone the policy applies to gets every row Query 2: a condition of true; advisor lint 0024
    A policy with no role named It applies to all roles, signed-out visitors included Query 2: read the roles column
    Roles or admin flags read from user metadata Users can edit that field and promote themselves Advisor lint 0015
    The secret key in client code It bypasses every policy Search the shipped bundle and the repository
    A view or security definer function that skips RLS Rows leak around the table's policies Advisor lint 0010 for views; review functions by hand

    Two of these deserve a few more words.

    The always-true policy. This is how a correct setup goes bad. RLS is on, there are no policies, so the app returns nothing. A likely next step, in our view, is to ask the AI tool to fix the empty list, and one easy fix is a policy with using (true). The list fills up, for everyone. A related trap from Supabase's guide: auth.uid() returns null for every signed-out request, and a condition with an or auth.uid() is null branch "returns every row to any request without a user ID."

    Views and functions. The guide says "Views bypass RLS by default because they are usually created with the postgres user." On Postgres 15 and above, create the view with security_invoker = true so the underlying policies apply. Functions are separate: the API security guide says "RLS doesn't apply to functions, so grant execute only to the roles that need to call them."

    How to check your own project

    1. Run the advisor. Supabase's database advisor checks for most of the table above. Treat every ERROR as a release blocker, and read the lower-level findings too: lints 0007 and 0024 are not reported as errors.

    2. Run two queries. These are ours, written against the standard PostgreSQL catalog views. The first lists public tables with RLS off. The second lists every policy so you can read them.

    select tablename
    from pg_tables
    where schemaname = 'public' and rowsecurity = false;
    
    select tablename, policyname, roles, cmd, qual, with_check
    from pg_policies
    where schemaname = 'public'
    order by tablename;
    

    In the second result, qual is the using condition and with_check is the write condition. Read both and ask: does this tie the row to the person asking? A condition of true, or a policy that names no specific role, on a table with private data needs a reason. If you expose schemas other than public, widen the filter.

    3. Try it as an outsider. Signed out, with only the publishable key, query each table from a small script using the same client library your app uses. You should get nothing back from any table that holds private data. Then sign in as one test user and ask for a row that belongs to another.

    4. Search for the secret key. Look in the shipped JavaScript bundle and the git history for sb_secret_ and for variable names containing service_role. A legacy key is a JWT, so decode any long eyJ string you find and check its role. Supabase's rule for a secret key is short: "Never put one in a browser, a shipped application, or source control."

    How to keep it from reopening

    A check you run once protects you until the next schema change. In two cases from the September report, the fix shipped with tests. In one, a SaaS product, we rewrote the database policies around ownership and added tests that try each route as the wrong user. In the other, on Firebase, we wrote a permissions test suite that runs the rules against every collection as an outsider, an ordinary user and an admin.

    Supabase documents the same idea for RLS in its testing guide. A pgTAP test switches role, sets the user ID, and asserts what that user can and cannot see. This sketch is ours, following that guide's pattern. It is shortened: the guide's full file first inserts test users and rows, and without a row for user 1 this assertion would pass even with RLS off.

    begin;
    create extension if not exists pgtap with schema extensions;
    select plan(1);
    
    -- insert test users and one invoice for user 1 here
    
    set local role authenticated;
    set local request.jwt.claim.sub = '22222222-2222-2222-2222-222222222222';
    
    select is_empty(
      $$ select * from public.invoices
         where user_id = '11111111-1111-1111-1111-111111111111' $$,
      'User 2 cannot read User 1 invoices'
    );
    
    select * from finish();
    rollback;
    

    You run it with supabase test db, and Supabase's testing overview shows that command in a GitHub Actions workflow. The overview adds advice we agree with: "Always test negative cases: what users should not be able to do".

    A checklist before you take real users

  • RLS is enabled on every table in an exposed schema. Query 1 returns no rows for each of them.
  • Every table with private data has policies for select, insert, update and delete, each naming its role.
  • No policy has a condition of true unless the data really is public.
  • No policy reads roles from user metadata.
  • The secret key exists only on the server. The bundle and git history are clean.
  • Views use security_invoker, and functions are granted only to the roles that need them.
  • There is a test for each table that tries to read and change another user's rows, and it runs on every change.
  • If you work with a coding agent, the rule "every new table gets RLS and owner policies" is written in its instructions file, so you do not have to ask each time.
  • RLS covers one layer. Routes that run on your server with the secret key need their own ownership checks, because that key skips every policy. Our AI code security audit tests every endpoint for broken access control and reviews secrets and dependencies.

    Sources: Supabase documentation as read on 1 December 2026: Row Level Security, API keys, Securing your API, database advisors testing RLS and the testing overview; PostgreSQL 19 documentation on row security policies and CREATE POLICY; UpGuard, Everything Everywhere: Systemic Data Exposure in Supabase Apps, 23 September 2026. Entalogics figures are from our own audit reports.

    COMMON QUESTIONS

    Straight answers.

    Eight questions we get on every first call. If yours isn't here, it'll be the first thing we cover.

    Row level security is a PostgreSQL feature that filters rows per request. You enable it on a table and write policies that say which rows each role may read or change. In a Supabase app the browser talks to the database through an API with a public key, so these policies are what keeps one user's rows away from another.
    Yes, it is designed to be public. Supabase's documentation lists it as safe to expose in a web page, a mobile app or source code, and says it only reaches what row level security allows. That makes the policies the real protection. The secret key is the opposite: it bypasses every policy and must stay on the server.
    It depends on how the table was created. Supabase's documentation says tables created through the dashboard have RLS enabled by default. UpGuard's research says tables created programmatically do not, which is how coding agents usually create them. Check every table instead of assuming.
    Nothing is readable or writable through the API with the publishable key. PostgreSQL applies a default-deny policy when a table has row security enabled and no policy exists. This is safe, but the app will look broken. The fix to avoid is a policy that allows everything.
    Yes. Supabase's documentation says a secret key bypasses every row level security policy you have, and that it must never be put in a browser, a shipped application or source control. Its RLS guide adds that the bypass applies only when the request carries no user access token. The older service_role key is the legacy version of the secret key and behaves the same way.
    Not user metadata. Supabase's documentation says raw_user_meta_data can be updated by the signed-in user and is not a good place to store authorization data. Its database advisor reports a policy that references it as an error. Use app metadata, which the user cannot change. A roles table that users cannot write to is another option we would accept.
    Test as different users, and test what they must not be able to do. Supabase documents two ways: pgTAP tests in the database, run with the supabase test db command, and application-level tests that sign in as two users through the same client your app uses. Run them on every schema change.

    Ready to Build Something Amazing?

    Let's discuss your project and see how we can help you achieve your goals with quality software at fair pricing.