Thomas Osayi

November 17, 2026 · 9 min read · Thomas Osayi

Is your Lovable or Bolt app leaking data? Check Supabase row level security

How to check whether your AI-built Supabase app exposes other users' data, what row level security does, and how to fix it before launch.

AI builders connect apps to Supabase quickly. They do not always lock the data down, and the app looks fine because you only ever test it as yourself. You sign in, you see your own records, everything works. What you never see is what a stranger can pull out of the database with nothing but the public key that ships in your page.

This is the security problem I check first on every Lovable, Bolt or Cursor app that reaches me, because it is invisible in normal use and serious once real customers are in the tables. Here is how it happens, how to check your own app, and what a correct setup looks like.

Why do AI-built Supabase apps leak data?

They leak because the browser talks straight to the database with a public key, and the only guard on each table is a set of policies that the AI builder may not have written.

In a traditional app, the browser calls your server and your server decides what to return. A Supabase frontend skips that step. The Supabase client in your JavaScript sends queries directly to an API in front of your Postgres database, signed with the anon key. Newer projects call it the publishable key. Either way it sits in your JavaScript bundle by design, and anyone can copy it from the browser's developer tools in a few seconds.

That is safe only when row level security, usually shortened to RLS, is switched on. RLS is a Postgres feature: each table carries policies that decide, for every request, which rows may be read, inserted, changed or deleted. With RLS off, the anon key can read and write the whole table.

AI builders tend to create tables by running SQL, and a table created with SQL does not get RLS unless the statement turns it on. When a prompt hits a permission error, the fastest way for the tool to make the error go away is often a policy that allows everything. The app starts working, and the hole stays.

How can you check your app in five minutes?

You can check it from the Supabase dashboard and a second test account, with no code.

Look at every table

Open the Table Editor and click through each table in the public schema. A table without RLS is labelled as unrestricted. Any table holding user data, such as profiles, orders, messages or uploads, must have RLS enabled.

Read the policies

Open Authentication, then Policies. For each table, read the condition on each policy. A condition that is just the word true lets everyone through. A select policy for the anon role on a table of private data is the same problem in different words.

Run the Security Advisor

The dashboard has an Advisors section with a Security Advisor. It lists tables in the public schema with RLS disabled, tables with RLS enabled and no policies, and several other risks. Fix what it reports, starting with errors.

Try to read someone else's data

Create a second account in your app. Sign in as that user and try to open the first user's records, for example by changing an ID in the URL. Then sign out and load the app's main data pages. If anything belonging to another person appears, the policies are wrong.

What does a good RLS policy look like?

A good policy ties every row to its owner and checks that owner against the signed-in user, separately for each kind of action.

The usual pattern has three parts. First, the table has a user_id column that references the auth users table and defaults to auth.uid(), the ID of whoever is making the request. Second, RLS is enabled with a statement like this:

alter table public.notes enable row level security;

Third, there is one policy per action. For reading:

create policy "Users read their own notes" on public.notes for select to authenticated using ((select auth.uid()) = user_id);

For inserting, the check goes in a with check clause, which validates the new row instead of filtering existing ones:

create policy "Users add their own notes" on public.notes for insert to authenticated with check ((select auth.uid()) = user_id);

Update policies need both clauses: using decides which rows the user may touch, and with check decides what the row may look like afterwards. Without the second clause, a user can edit their own row and reassign it to someone else. Delete needs only using.

Two details matter. The policies name the authenticated role, so logged-out requests get nothing. And the user ID comes from the session, never from the request body, because the body is whatever the sender wants it to be.

Which policy mistakes do AI builders make most often?

The mistakes I see most are permissive placeholder policies, missing actions, and trust placed in data the user controls.

  • A policy with using (true) that was added to clear an error and never tightened
  • A select policy done correctly, with update and delete left wide open or missing entirely
  • An update policy without with check, so rows can be reassigned
  • Policies that read a role from user metadata. A signed-in user can edit their own user_metadata, so a rule like "admins can see everything" based on it lets anyone promote themselves
  • A profiles table where the user may update every column, including is_admin or plan
  • Shared data, such as team records, handled by letting every authenticated user read the whole table

The profiles case deserves attention because it turns a small gap into a full one. If your app decides who is an admin or who has paid from a column on the user's own row, and the user can update that row, they can grant themselves anything. Keep those columns in a table users cannot write to, and change them only from server code.

Does turning on RLS break the app?

Yes, briefly: enabling RLS with no policies blocks every request from the browser, so plan the order of work.

With RLS on and no matching policy, a select returns an empty list with no error. Pages render as if the user simply had no data. An insert fails with the message "new row violates row-level security policy". An update or delete quietly changes zero rows. Knowing these three symptoms saves a lot of confused prompting, because the empty-list case looks like a frontend bug.

The order I follow:

  • List every table and what each kind of user needs to do with it
  • Write the policies for one table, enable RLS on it, and test that feature as two different users
  • Move to the next table
  • Finish with the Security Advisor and a logged-out pass through the app

Do this on a staging project or a branch if real users are already live. If the data is already exposed in production, turn RLS on first and accept a few broken screens for an hour. A broken page is a smaller problem than an open table.

Where else can a Supabase app leak data?

Table policies are the main gate, but storage, server keys, views and database functions each have their own.

Storage buckets

Files are governed by policies on the storage.objects table, not by your table policies. A bucket marked public serves every file to anyone with the URL. That suits logos and product photos. It does not suit invoices, ID documents or anything a user uploaded privately. Use a private bucket and signed URLs for those.

The service role key

This key bypasses RLS completely. It belongs only in server code: an edge function, a route handler or a backend job. In a Vite app, which is what Lovable generates, any variable starting with VITE_ is bundled into the browser. In Next.js the same is true of NEXT_PUBLIC_. If the service role key has either prefix, treat it as leaked, rotate it in the dashboard, and move the code that used it to the server.

Views and functions

A view runs with the permissions of whoever created it unless it is defined with security_invoker set to true, so a view over a protected table can expose the whole table. Database functions marked security definer do the same, and they are callable from the browser through RPC.

Edge functions

An edge function that uses the service role key has to check who is calling before it acts. Read the user from the request's authorization header and confirm they are allowed to do what the function does.

How do you handle admins and team access?

Handle them with a membership or roles table that users cannot edit, and policies that look the user up in it.

For team data, add a table that links user IDs to team IDs. A policy on the shared table then allows access when a membership row exists for the signed-in user and the row's team. For admins, keep a separate roles table writable only from the server, or put the role in app_metadata, which users cannot change from the client.

The principle is the same on any backend. Guardian MindCare, a therapy practice platform I built on Firebase, has five roles: therapists, supervisors, trainees, clients and admins. Each sees only what it should, and those rules are enforced by the database's security rules, not by hiding buttons in the interface. Hiding a button stops honest users. It does nothing against someone calling the API directly.

Guardian MindCare: a therapy practice platform I built where therapists, supervisors, trainees, clients and admins each see only their own data.
Guardian MindCare: a therapy practice platform I built where therapists, supervisors, trainees, clients and admins each see only their own data.

Heavy admin actions, such as deleting a user or exporting everything, are better done in server code with the service role key after checking the caller's role, instead of through ever more complicated policies.

How do you confirm the fix worked?

Confirm it by attacking your own app the way a stranger would: with only the URL and the public key.

Repeat the second-account test on every feature. Then test as nobody. Your project's REST endpoint is your project URL followed by /rest/v1/ and a table name. A request to it with only the anon key in the apikey header should return an empty list or an error for every private table. If it returns rows, that table is still open.

Check writes too. Signed in as user B, try to update and delete a record belonging to user A, and try to insert a record with user A's ID. All three should fail. Finally, run the Security Advisor again and search your built frontend files for the first characters of your service role key.

When should you bring in a developer?

Bring one in when real users' data is involved and you cannot say with confidence what each policy allows.

Security is the one area where I would not keep prompting and hoping. An AI tool will happily report that the policies are fixed, and you have no way to verify that without reading SQL. A developer can read the policies directly, test them as different users, and fix most apps in a few hours.

For scale: a single issue, such as one open table or a leaked key, fits my Quick Fix package from $60 in about 2 days. A wider pass over policies plus a feature or integration fits Fix Plus Features from $200. Taking an app that is stuck before launch through security, payments and a production deploy is Finish and Launch from $600. You get a short write-up of what was wrong and what changed, so you understand your own app afterwards.

The bottom line

Your Supabase anon key is public, so your policies are your security. Enable RLS on every table, write a policy for each action that checks auth.uid() against the row's owner, keep the service role key on the server, and lock down storage, views and functions as well. Then test as a second user and as a logged-out stranger before you invite anyone in. If any of those tests shows data it should not, fix that before you launch, not after.

Questions, answered in one line

Is the Supabase anon key a secret?

No. It is meant to be public, which is exactly why row level security has to protect every table.

How do I know if RLS is enabled?

In the Supabase dashboard, each table shows whether RLS is enabled, and the Security Advisor flags tables without it.

Does turning on RLS break my app?

It blocks all access until you add policies, so add policies for each action your app needs, then test while signed in as different users.

What is the difference between the anon key and the service role key?

The anon key is public and obeys row level security, while the service role key bypasses every policy and must only ever be used in server code.

Are Supabase storage buckets covered by table policies?

No. Files are protected by separate policies on storage.objects, and a bucket marked public serves its files to anyone who has the URL.

How much does it cost to have a developer fix Supabase security?

Thomas Osayi fixes a single issue from $60 in about 2 days, and a full pass that takes a stuck app to a safe production launch starts from $600.

Sources

About the author

Thomas Osayi is a full-stack developer in Los Angeles studying computer science at Loyola Marymount University. He founded and built SQWAD, a SaaS platform Shopify brands use to run creator programs, and builds custom Next.js websites, SaaS MVPs and fixes for AI-built apps for businesses and founders.

See his work · Services and prices

Related articles

Fix, finish and launch your AI-built app

Built your app with Lovable, Bolt, v0, Replit or Cursor and got stuck? I fix the bugs, connect auth and payments, clean up the code and deploy it to production.

See the service