---
title: "Supabase RLS: the mistake that exposes your users' data"
description: "A Supabase table without RLS can be read by anyone holding your site's public key. A 2-minute test and the SQL policies to copy."
url: "https://vibe-code.blog/en/supabase-rls-security"
lang: "en"
author: "Thierry Gustin"
published: "2026-11-02"
updated: "2026-11-21"
---

# Supabase RLS: the mistake that exposes your users' data

> **Key takeaways** — In a Supabase app, the public key is visible to everyone in the browser; only Row Level Security (RLS) policies stop a stranger from reading or changing your tables. The classic mistake is a table without RLS, or a using (true) policy added to "unblock" the app. Enable RLS on every table, write one policy per operation based on auth.uid(), then test with the public key.

Supabase RLS (Row Level Security) is the only thing standing between your users' data and the rest of the internet. Your app talks to the database straight from the browser, using a key anyone can read. If a table has no RLS policies, or policies that are too broad, a stranger can read it with a single request. Here is how to check, fix and test.

## Why doesn't the Supabase public key protect anything?

The Supabase public key is not a password; it is a visitor badge. The [Supabase](https://supabase.com/) docs describe the *publishable* key (`sb_publishable_...`, or the older `anon` key) as "safe to expose online", precisely because what it can do is limited by RLS.

In practice, an app generated by [Lovable](https://lovable.dev/) or [Bolt](https://bolt.new/) ships your project URL and that key inside its JavaScript. Any visitor can copy both from the Network tab of their browser and query your database's REST API directly, without going through your interface.

What decides the response:

| State of the table | What a stranger gets with the public key |
| --- | --- |
| RLS disabled | Read and write access to every row, depending on the grants on the role |
| RLS enabled, no policies | Nothing: everything is denied by default |
| RLS enabled, `using (true)` policy for `anon` | Every row, read-only |
| RLS enabled, policy based on `auth.uid()` | Only their own rows, if signed in |

The Supabase docs are explicit about the second case: once RLS is enabled, no data is accessible through the API with the public key until you create policies.

## What is the mistake that exposes the data?

The most common mistake is not forgetting RLS; it is working around it to make the app run. The pattern repeats itself:

1. You enable RLS (or the tool does).
2. The app shows nothing, because everything is denied by default.
3. You ask the AI to fix it. It writes a `using (true)` policy, disables RLS, or switches to the secret key.
4. The app works again. The data is open to everyone.

That is the kind of flaw described in [CVE-2025-48757](https://nvd.nist.gov/vuln/detail/CVE-2025-48757), rated 9.3 out of 10: insufficient RLS policies in sites generated by Lovable up to 15 April 2025 let unauthenticated attackers read or write database tables. Lovable disputes it, pointing out that each customer is responsible for protecting their app's data. Either way, the takeaway for you is the same: checking is your job.

> **The secret key is never the fix** — The `service_role` key (or `sb_secret_...`) bypasses all RLS. Supabase rejects the newer secret keys when they are sent from a browser (HTTP 401), but a leaked key still works from a terminal, and the legacy `service_role` key is not covered by that block. If the AI put it on the client, rotate it.

## How can you tell in 2 minutes whether your database is exposed?

The fastest route is the Supabase **Security Advisor**, followed by a manual test to confirm.

### Step 1: the Security Advisor

In the Supabase dashboard, open **Advisors**, then **Security Advisor**. The alerts to handle first:

- `rls_disabled_in_public` (ERROR level): a table in the `public` schema has RLS off, so anyone with your project URL can read, insert, update and delete its rows.
- `policy_exists_rls_disabled`: you wrote policies, but RLS is not enabled, so they do nothing.
- `security_definer_view`: a view runs with its creator's privileges and bypasses RLS.

### Step 2: the public key test

Grab your project URL and public key from your site's Network tab (F12), then run this in a terminal:

```bash
curl "https://YOUR-PROJECT.supabase.co/rest/v1/profiles?select=*" \
  -H "apikey: YOUR_PUBLIC_KEY"
```

Swap `profiles` for each of your tables. A private table should return `[]` or an error. If you see emails, names or orders, the table is open.

## Which RLS policies should you write for a user table?

The baseline rule: one policy per operation, each restricted to the `authenticated` role and to rows owned by the user. Here is a template for a `notes` table with a `user_id` column:

```sql
-- 1. Enable RLS
alter table public.notes enable row level security;

-- 2. Read your own notes
create policy "Read own notes"
on public.notes for select
to authenticated
using ( (select auth.uid()) = user_id );

-- 3. Create notes in your own name only
create policy "Create own notes"
on public.notes for insert
to authenticated
with check ( (select auth.uid()) = user_id );

-- 4. Update your own notes
create policy "Update own notes"
on public.notes for update
to authenticated
using ( (select auth.uid()) = user_id )
with check ( (select auth.uid()) = user_id );

-- 5. Delete your own notes
create policy "Delete own notes"
on public.notes for delete
to authenticated
using ( (select auth.uid()) = user_id );

-- 6. Index for performance
create index on public.notes (user_id);
```

Three details from the Supabase docs:

- `using` filters existing rows; `with check` validates rows being created or changed. `update` needs both, otherwise a user could reassign their note to someone else.
- Wrapping `auth.uid()` in `(select ...)` lets Postgres compute the value once per statement instead of once per row.
- An `update` policy needs a matching `select` policy to work.

> **Public data** — For genuinely public data (a product catalogue, published articles), a `for select to anon using (true)` policy is fine. It must never cover a table holding personal data.

## Which RLS traps does the AI miss?

Even with RLS enabled everywhere, five mistakes keep showing up in generated apps.

1. **The catch-all `for all` policy.** Supabase advises against it: a single policy for every operation makes mistakes hard to spot. Write one per operation.
2. **Roles stored in `user_metadata`.** A signed-in user can edit their own `user_metadata`. If your admin policy checks `user_metadata.role = 'admin'`, anyone can promote themselves. Use `app_metadata`, which only the server can change.
3. **Views that bypass everything.** By default a view runs with its creator's privileges. On Postgres 15 and later, create it `with (security_invoker = true)`.
4. **Exposed `security definer` functions.** These functions run with elevated privileges. They should set `search_path = ''` and live outside any schema exposed by the API.
5. **The silent `null`.** For a signed-out visitor, `auth.uid()` returns `null`, and `null = user_id` is never true. That is safe, but if you write more complex conditions with `or`, add `auth.uid() is not null` explicitly.

One last technical point: grants and RLS policies are two separate layers. The Supabase docs note that on existing projects, new tables in the `public` schema grant all privileges to the `anon` and `authenticated` roles, and adding policies does not remove those grants. RLS remains your main protection; tightening grants is a second belt.

## Which prompt fixes RLS without breaking everything?

A good prompt explicitly forbids the dangerous shortcuts. Paste this into Lovable, Bolt, [Cursor](https://cursor.com/) or Claude Code:

```text
Audit this project's Supabase security, table by table.
For each table in the public schema:
1. Say whether RLS is enabled and list existing policies.
2. Propose a SQL migration that enables RLS and creates one policy per
   operation (select, insert, update, delete), restricted to the
   authenticated role and to (select auth.uid()) = user_id, unless the
   table holds explicitly public data: ask me which ones.
3. Add an index on every column used in the policies.

Do not:
- ever disable RLS;
- use using (true) on any table holding user data;
- ever use the service_role key or any secret key on the client;
- store any role in user_metadata.

If a feature breaks after the migration, explain why and propose a
precise policy, not a workaround.
```

After the migration, rerun the `curl` test on every table, then the two-account test: sign in as user A, create a record, and check that user B cannot see it. Those are the two core checks in our [pre-launch security checklist](https://vibe-code.blog/en/vibe-coding-security).

## What if the app needs to access all the data?

Some operations genuinely need every row: an admin dashboard, an export, a scheduled job. The fix is not to loosen the policies but to move the operation to the server.

- **Edge Function or API route**: server code uses the secret key, stored as an environment variable, and checks for itself that the caller is an admin. The browser only calls that function.
- **Admin policy based on `app_metadata`**: if the admin needs the normal interface, write a policy that checks a role stored in `app_metadata`.

Server-side key handling is covered in [API keys: why they must never live in your front end](https://vibe-code.blog/en/api-keys-security), and user accounts in authentication without security holes. If you are starting with Supabase from scratch, see Supabase for beginners; if you build with Lovable, our [full Lovable review](https://vibe-code.blog/en/lovable-review) covers its Supabase integration. And to check the rest of the generated code without being a developer: [testing AI-generated code](https://vibe-code.blog/en/testing-ai-generated-code).

## Frequently asked questions

## Frequently asked questions

### Is Supabase RLS enabled by default?

Never assume it is. Depending on how a table was created (table editor, SQL query, AI-generated migration), RLS may or may not be on. Open the Supabase Security Advisor, which flags every table in the public schema without RLS with the rls_disabled_in_public alert, and check table by table. A table that holds user data and has RLS off is readable and writable through your public API.

### Why does my app show nothing after I enabled RLS?

Because a table with RLS but no policies denies everything by default, which is the intended behaviour. You now need policies that allow exactly what is required, for example reading your own rows with auth.uid() = user_id. Do not just ask the AI to "unblock" the app: it may disable RLS or write a using (true) policy, which reopens the data to everyone.

### Is the anon key in my code a vulnerability?

No. The public key (anon or publishable) is designed to be visible in the browser. It only allows what your RLS policies permit. The vulnerability is a table without RLS, or with a policy that is too broad. The key you must never expose is the secret key (service_role or sb_secret), which bypasses every policy. If it sits in your front end, rotate it now.

### Does RLS slow down queries?

It can on large tables if policies are badly written. The Supabase docs recommend two habits: wrap functions like auth.uid() in (select ...) so they are evaluated once per statement, and add an index on every column used in your policies, such as user_id. For an app with a few thousand rows, the impact is negligible.

### Do Lovable or Bolt set up RLS correctly?

They often create policies, and Lovable checks for tables without RLS in its pre-publish scan. But the tool does not know your intentions: it cannot tell which data should be public or private. CVE-2025-48757 shows that generated apps have shipped with insufficient policies. Always confirm with the Security Advisor and a curl test using the public key.

## Sources

- [Row Level Security — Supabase Docs](https://supabase.com/docs/guides/database/postgres/row-level-security)
- [Understanding API keys — Supabase Docs](https://supabase.com/docs/guides/api/api-keys)
- [Database Advisors — Supabase Docs](https://supabase.com/docs/guides/database/database-advisors)
- [CVE-2025-48757 — NIST National Vulnerability Database](https://nvd.nist.gov/vuln/detail/CVE-2025-48757)
- [Security — Lovable Documentation](https://docs.lovable.dev/features/security)
- [OWASP Top 10:2025 — OWASP Foundation](https://top10.owasp.org/2025/)

— Thierry Gustin, Formateur en intelligence artificielle (GustinAI) · November 21, 2026
