# Supabase RLS for vibe coders: is your data leaking?

> How to check that your Lovable, Bolt or Cursor-built Supabase app has Row Level Security that actually works, with SQL you can run in five minutes.

By Tommy Pham · 2026-11-14 · https://tommydev.web.app/blog/supabase-rls-vibe-coding

**Short answer:** if your app talks to Supabase from the browser, every table in the `public` schema needs Row Level Security (RLS) turned on *and* a policy that limits rows to the right user. "RLS enabled" is not enough. A policy like `using (true)` is the same as no protection. You can check both in the Supabase SQL editor in a few minutes with the queries below.

This is part of my [production checklist for vibe-coded apps](/blog/vibe-coded-app-production-checklist).

## Why do AI-built Supabase apps leak data?

A Supabase app usually ships its *anon* (or new *publishable*) key inside the frontend. That is by design: the key is public, and RLS is what stops a stranger from using it to read your whole database. Supabase's own docs say the publishable key is only safe when RLS restricts access.

AI builders generate working screens fast, and a screen that reads a table works the same whether RLS is on or off. So the prototype looks fine, and nothing tells you that anyone with your URL can open the browser console and run `select *` on your `profiles` or `orders` table.

This isn't theoretical. CVE-2025-48757 covered more than 170 Lovable-built apps that exposed data through missing or weak RLS policies. Lovable has since added a security scan that runs Supabase's advisor, which helps, but the advisor only tells you RLS *exists*. It doesn't test whether your policies are correct.

I use Supabase in production for [PainBase](/work/painbase), and this is the first thing I check on any Supabase project I'm asked to look at.

## How do I check which tables have RLS off?

Open **SQL Editor** in your Supabase dashboard and run:

```sql
select schemaname, tablename, rowsecurity
from pg_tables
where schemaname = 'public'
order by rowsecurity, tablename;
```

Any row with `rowsecurity = false` is readable and writable by anyone holding your public key (subject to table grants). Fix those first:

```sql
alter table public.your_table enable row level security;
```

Turning RLS on with **no policies** blocks all access through the API, which is safe but will break the screens that use that table. That's expected. Next, add the policies you actually need.

## How do I check whether my policies are too open?

List every policy:

```sql
select tablename, policyname, cmd, roles, qual, with_check
from pg_policies
where schemaname = 'public'
order by tablename;
```

Read the `qual` (who can see a row) and `with_check` (what can be written) columns. Red flags:

| What you see | What it means |
|---|---|
| `qual = true` | Every row is visible to every role in `roles` |
| `roles = {public}` or `{anon}` on a table with personal data | Logged-out visitors can read it |
| `with_check = true` on an insert or update policy | Users can create or change rows so they belong to someone else |
| Policies on `select` only | Insert, update and delete fall back to "denied", which is fine, unless another permissive policy allows them |

A typical correct policy for user-owned rows looks like this:

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

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

Wrapping `auth.uid()` in a `select` is a performance pattern from Supabase's docs: Postgres evaluates it once per query instead of once per row.

## How do I test RLS like an attacker would?

The SQL above tells you what the rules *say*. Test what they *do*:

1. Create two test accounts, A and B.
2. As A, create a few rows (a note, an order, a profile change).
3. Log in as B and try to read and edit A's rows. Use the app, then try the same thing directly with the Supabase client in the browser console.
4. Log out completely and try reading each table with only the public key.

If B or a logged-out visitor can see A's data, the policy is wrong, whatever the advisor says.

## What about the service role key?

The `service_role` key (or the new `sb_secret_` key) **bypasses RLS entirely**. It must only live on a server: an API route, an edge function, a background job. If it's in a `NEXT_PUBLIC_` or `VITE_` variable, or anywhere in your built JavaScript, treat it as leaked and rotate it. I wrote a separate guide on [which keys are safe in your frontend](/blog/api-keys-frontend-security).

Supabase is also replacing the legacy `anon` and `service_role` keys with `sb_publishable_` and `sb_secret_` keys, and its docs say the legacy keys will be deprecated by the end of 2026. Migrating is a good moment to rotate anything that may have leaked.

## A 10-minute RLS checklist

- [ ] Every `public` table has `rowsecurity = true`
- [ ] No policy uses `using (true)` on a table with user or business data
- [ ] Policies are scoped `to authenticated` unless logged-out access is intentional
- [ ] Insert and update policies have a `with check`
- [ ] Two-account test passes: B can't read or change A's rows
- [ ] Logged-out test passes: the public key alone can't read private tables
- [ ] Service role or secret key is not in any frontend env var or built bundle
- [ ] Storage buckets with private files are not public, and have their own policies

## FAQ

### Is the Supabase anon key secret?

No. It's designed to be public and will be visible in your site's JavaScript. Your data is protected by RLS policies, not by hiding that key.

### Does Lovable's security scan check my RLS?

It runs Supabase's advisor, which flags tables with RLS off or missing policies. It does not prove your policies are correct, so still run the two-account test.

### Will enabling RLS break my app?

It can, for any screen reading a table you haven't written policies for. That break is useful: it shows you exactly which tables were open. Add a policy for each real use case.

### Do I need RLS if I only query Supabase from my server?

If no browser code ever uses the public key against that table, RLS matters less. Most AI-generated apps do query from the browser, though, so enable it anyway as a second layer.

---

Want a second pair of eyes on your Supabase setup? This is the kind of review I do. See [my work](/#work) or reach me through the contact section below.

## Sources

- Supabase docs: [Understanding API keys](https://supabase.com/docs/guides/api/api-keys) and [migrating to publishable and secret keys](https://supabase.com/docs/guides/getting-started/migrating-to-new-api-keys) (checked November 2026)
- Lovable: [Secure vibe coding](https://lovable.dev/blog/secure-vibe-coding)
- Superblocks: [Lovable vulnerability explained](https://www.superblocks.com/blog/lovable-vulnerabilities) (CVE-2025-48757 write-up)