Skip to content
← All guides

Security

Are your Supabase tables open? How to check RLS in a Lovable app and fix it

By Jan Lipmann, appienceChecked against sources on 9 min read

Every Lovable app ships its Supabase URL and public key to the browser. That is by design - the only thing standing between that key and your data is Row Level Security (RLS) and the grants on each table. Below: three checks you can run in ten minutes, what usually goes wrong in generated policies, and the SQL that fixes it.

LovableSupabasePostgreSQL

What you are seeing

Usually there is no visible symptom until someone else finds it. The signals that should make you check:

  • Supabase's Security Advisor or a weekly security email lists RLS Disabled in Public (lint 0013), Security Definer View (0010) or Permissive RLS Policy (0024).
  • The Table Editor shows a warning label next to a table - Supabase added it for tables with RLS disabled (Supabase security retro).
  • Lovable's security scan flags tables without per-record access control or rules that let everyone through.
  • A user reports seeing someone else's data, or a researcher emails you a sample of your own users table.
  • You never wrote a policy yourself and do not know what the AI generated.

How to check it yourself

Run these against your own project only. All of them are read-only.

Note: The steps assume a Supabase project you can open in the Supabase dashboard. If your app runs on Lovable's built-in backend instead, the database is still PostgreSQL and the same rules apply, but where you run SQL and read the advisors is different - see Lovable's FAQ.

1. List tables with RLS off

In the Supabase dashboard open SQL Editor and run:

select schemaname, tablename, rowsecurity
from pg_tables
where schemaname = 'public'
order by rowsecurity, tablename;
Any row with rowsecurity = false is a table whose rows are not filtered by RLS at all.

A table with RLS off is not automatically readable - the anon and authenticated roles also need grants on it. But for most existing projects those grants were added automatically: until the 2026 change to default grants, Supabase granted select, insert, update and delete on every new public table to anon, authenticated and service_role. Existing tables kept those grants. Treat RLS off as open until the curl test below says otherwise.

2. Read the policies that exist

select tablename, policyname, cmd, roles, qual, with_check
from pg_policies
where schemaname = 'public'
order by tablename, cmd;
  • qual or with_check equal to true means the policy lets every row through for those roles. Supabase flags this as lint 0024 (permissive RLS policy).
  • roles of {public} means the policy applies to every role, including anonymous visitors. Supabase's docs say to always name the role with a to clause (Row Level Security).
  • A select policy for authenticated with no reference to auth.uid() usually means any signed-in user can read every row - fine for a public catalogue, not for orders, messages or profiles.
  • An update policy whose with_check is looser than its using - or is plain true - lets a user rewrite a row they may edit into one they should not own, for example by changing user_id to someone else's id. An empty with_check is not the problem on its own: Postgres then reuses the using expression to check the new row (PostgreSQL: CREATE POLICY).
  • Policies that read auth.jwt() -> 'user_metadata' rely on data the user can edit themselves (lint 0015).

3. Try to read the data the way a stranger would

Your project URL and public key are in your app's front-end code (search the repository for createClient(, or open the browser's Network tab and look at any request to /rest/v1/ - the key is in the apikey header). The public key is the anon key on older projects or a key starting with sb_publishable_ on newer ones. From a terminal:

curl "https://YOUR-PROJECT-REF.supabase.co/rest/v1/profiles?select=*&limit=3" \
  -H "apikey: YOUR_PUBLIC_KEY"
Replace profiles with each table from step 1. No user token is sent, so this is exactly what an anonymous visitor can do.
  • Rows come back from a table that should be private: the table is open. Fix it before anything else.
  • An empty array []: RLS is filtering everything for anonymous users (or the table is empty - check the row count in the Table Editor).
  • permission denied with code 42501: the role has no grant on the table, so the Data API cannot reach it at all.

Then repeat the test as a signed-in user. Sign in with a test account, copy its access_token from the browser's Local Storage (key sb-YOUR-PROJECT-REF-auth-token), and ask for rows that belong to someone else:

curl "https://YOUR-PROJECT-REF.supabase.co/rest/v1/orders?select=*&user_id=neq.YOUR_TEST_USER_ID&limit=3" \
  -H "apikey: YOUR_PUBLIC_KEY" \
  -H "Authorization: Bearer ACCESS_TOKEN_OF_TEST_USER"
If this returns other users' rows, every customer of yours can read every other customer's data.

4. Make sure no secret key reaches the browser

A secret key (sb_secret_...) or the legacy service_role key bypasses every policy. Supabase's docs are explicit: never put one in a browser, a shipped application or source control (API keys). The name of the variable proves nothing: a legacy key is a long JWT starting with eyJ, and a service_role key stored as VITE_SUPABASE_KEY looks exactly like the public one. Anything prefixed VITE_ is inlined into the browser bundle. So search the repository Lovable synced to GitHub and the built output that actually ships:

npm run build
grep -rnoE "sb_secret_[A-Za-z0-9_-]+|service_role|eyJ[A-Za-z0-9_-]+\.eyJ[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+" \
  --exclude-dir=node_modules --exclude-dir=.git .
Run it from the project root after the build, so it covers the source, .env files and the build output (dist, .output or similar). Matches inside supabase/functions/ (Edge Functions run on the server) are expected. Any sb_secret_ key in front-end code, in an .env file the front end reads, or in the build output is a leak.

Every eyJ... match is a JWT, so decode its middle part to see which role it carries. The payload is not encrypted, only base64url-encoded:

node -e 'console.log(Buffer.from(process.argv[1].split(".")[1], "base64url").toString())' "PASTE.THE.JWT"
"role":"anon" is the public key and may ship. "role":"service_role" is a secret key in your front end - treat it as leaked. User access tokens ("role":"authenticated") should not be hardcoded either. Decode locally rather than pasting the key into a website.

Finally, open Advisors > Security Advisor in the dashboard. It runs the same checks as above plus a few more (exposed auth.users, security definer views, functions callable by anonymous users) - see the lint reference.

Why it happens

Supabase exposes your Postgres tables through an HTTP API, and the key that calls it is public on purpose. In Supabase's words, the publishable key is safe to put in a web page or mobile app because it "only reaches what Row Level Security allows" (API keys). So the database itself has to enforce who sees what. When it does not, nothing else will.

  • Tables created in the dashboard get RLS turned on by default. Tables created with SQL - which is how AI tools and migrations create them - only get it if the SQL says enable row level security.
  • Lovable sets up basic RLS policies automatically, and its own docs tell you to review and adjust them (Lovable docs). Generated policies are written to make the feature work, which is not the same as making it private.
  • Policies drift. The AI adds a column, a table or a view to fix a bug, and the new object does not get the same care as the original schema.
  • Views are created by the postgres role and bypass RLS by default unless created with security_invoker (Postgres 15+) (Row Level Security).
  • Lovable's scanners help but do not settle it: Lovable says they "cannot guarantee complete security" and do not replace a security review (Lovable security).

How to fix it

Warning: Enabling RLS on a table with no policies blocks all access through the API with the public key. Write the policies in the same change, and test on a Supabase branch or a copy of the project before production.

Turn RLS on and write one policy per operation

For a table where each row belongs to one user (with a user_id uuid column referencing auth.users), this follows the pattern in Supabase's own docs: one policy per operation, scoped to authenticated, with auth.uid() wrapped in select so Postgres evaluates it once per statement instead of once per row.

alter table public.orders enable row level security;

create policy "Owners can read their orders"
on public.orders for select
to authenticated
using ( (select auth.uid()) = user_id );

create policy "Owners can create their orders"
on public.orders for insert
to authenticated
with check ( (select auth.uid()) = user_id );

create policy "Owners can update their orders"
on public.orders for update
to authenticated
using ( (select auth.uid()) = user_id )
with check ( (select auth.uid()) = user_id );

create policy "Owners can delete their orders"
on public.orders for delete
to authenticated
using ( (select auth.uid()) = user_id );

Then drop the permissive policies you found in step 2 (drop policy "name" on public.orders;). Leave out operations users should never do - if customers must not delete orders, do not create a delete policy.

Protect columns users must not edit

RLS works on rows, not columns. If profiles has a role or is_admin column and users may update their own profile, they can also promote themselves. Either move such columns to a table users cannot write to, or replace the table-wide update grant with a column list:

revoke update on public.profiles from authenticated;
grant update (display_name, avatar_url) on public.profiles to authenticated;

Fix views, storage and keys

  • Views: recreate them with with (security_invoker = on) so they respect the caller's RLS, or move them out of the exposed schema.
  • Storage: keep user files in private buckets and add policies on storage.objects that check the folder, e.g. (storage.foldername(name))[1] = (select auth.jwt()->>'sub'), as in the Storage access control docs. A public bucket is readable by anyone with the file URL.
  • Secret or service_role key found in client code: treat it as compromised. First move the code that needed it into an Edge Function, then replace and retire the leaked key - Supabase's API keys guide links to the rotation steps. Legacy keys stay valid until you disable them under Settings > API Keys.
  • New tables: Supabase documents an event trigger that enables RLS automatically on every new table (Row Level Security) - worth adding if an AI tool keeps creating tables for you.

Verify

Rerun the two curl tests and the Security Advisor. The anonymous request should return [] or 42501 for private tables, and the signed-in request should return only the test user's own rows. Then click through the app as a normal user: anything that now shows empty lists needs a policy you have not written yet.

When to get help

The single-owner pattern above covers simple apps. Get a second pair of eyes when:

  • Data is shared between users - teams, organisations, workspaces, invitations. Multi-tenant policies are where generated code fails most quietly.
  • You have roles (admin, staff, customer) or the app handles payments, health or children's data.
  • The curl test already returned other people's data on a live app. If you are subject to the GDPR, a personal data breach generally has to be reported to the supervisory authority within 72 hours of becoming aware of it, unless it is unlikely to result in a risk to people (GDPR, Article 33). Get legal advice on that part.
  • You fixed the policies and the app broke in ways you cannot trace.

Sources

Primary documentation this guide was checked against. Platforms change - if something here no longer matches, the source wins.

Frequently asked questions

Is it a problem that my Supabase anon or publishable key is visible in the browser?
No, that key is meant to be public. Supabase states it only reaches what Row Level Security allows. The problem is a table without RLS, or with policies that let everyone through. A secret or service_role key in the browser is a different matter: it bypasses RLS and must be rotated.
Does Lovable's security scan catch open tables?
Lovable's scan reviews the database for tables without per-record access control and for rules that let everyone through, which covers the most common case. Lovable's own documentation says the tools cannot guarantee complete security and do not replace a security review, so run the curl tests yourself as well.
Will enabling RLS break my app?
It can. With RLS on and no policies, the public key gets no rows at all, so screens go empty. Write the policies in the same change and test on a branch or a copy of the project first.
My curl test returns permission denied (42501). Is that secure?
It means the role has no grant on that table, so the Data API cannot reach it. That is safe, but if the app needs the table, add the grant and an RLS policy together rather than granting access without RLS.

Related guides

Fixed-price audit

Want someone to check the whole app, not just this?

A review of data security, production readiness and App Store readiness for apps built with AI tools. 900 USD, a ranked list of fixes within 5 business days.