---
name: supabase-rls-review
description: Reviews a project's Supabase migrations and SQL files for tables anyone can read or change. Finds tables without row-level security (RLS), policies that let everyone through such as using (true), and tables the anonymous role can write to. Use when the user asks whether their Supabase database is safe, whether RLS is set up correctly, who can see or edit their data, or wants a database check before launch. Explains each problem in plain language with the SQL to fix it.
allowed-tools: Read Grep Glob
license: MIT
---

# Supabase RLS review

Read the project's SQL and report which tables are open to people who should not have access. Change nothing.

## Rules

- **Read only.** Use Read, Grep and Glob. Do not edit or create files and do not run commands or SQL. Give the fix as SQL the user can paste; do not apply it.
- You are reading files, not the live database. Someone may have changed the database by hand in the dashboard. Say this under "Not checked" every time.
- Write for someone who is not an engineer. Say "anyone on the internet" and "any signed-in user", not "the anon role" on its own.

## Background you need

In Supabase, every table in the `public` schema is reachable from the browser with the project's anon or publishable key, and that key is public by design. Row-level security is the only thing between a visitor and the table.

- **RLS off**: anyone with the public key can read, add, change and delete every row.
- **RLS on, no policies**: nobody can reach the table from the browser. This is locked, not broken.
- **RLS on, with policies**: each policy opens a door. `using (...)` decides which existing rows a person can see or change. `with check (...)` decides which rows they may write.
- A policy with no `to` clause applies to everyone, including visitors who are not signed in.
- `service_role` bypasses RLS completely. A policy `to service_role` opens nothing new.

## Step 1: Find the SQL

Glob for `supabase/migrations/**/*.sql`, then `supabase/**/*.sql`, then `**/*.sql` (schema dumps, `schema.sql`, `seed.sql`). Read every migration in filename order, oldest first. If there is no SQL at all, say so and stop: there is nothing to review.

## Step 2: Build the final state

Migrations run in order and later ones override earlier ones. For each table, track the state after the **last** migration:

- created (`create table`), dropped (`drop table`), renamed;
- RLS on (`enable row level security`) or off (never enabled, or a later `disable row level security`);
- policies created and later dropped (`drop policy`) or changed (`alter policy`);
- `grant` and `revoke` lines that name `anon`, `authenticated` or `public`.

Only review tables in schemas the browser can reach: `public`, and any other schema the project exposes. Skip dropped tables. Tables in `auth`, `storage`, `private` or other unexposed schemas are out of scope unless a file exposes them; list them under "Not checked" if in doubt. Storage buckets and the policies on uploaded files (`storage.buckets`, `storage.objects`) are not reviewed here: list them under "Not checked" and point the user to the sister skill `storage-bucket-review`, which checks them.

## Step 3: Check each table

Report as a **problem**:

1. **RLS is off.** Never enabled, or switched off by a later migration. Name the migration that left it off.
2. **A policy lets everyone write.** An `insert`, `update`, `delete` or `all` policy whose condition is always true and which is not limited to `service_role`. Always-true means `true`, `1 = 1`, `(true)`, or a missing condition. Say whether it reaches anyone on the internet (`to anon`, `to public`, or no `to` clause) or any signed-in user (`to authenticated`).
3. **A policy lets everyone read private-looking rows.** A `select` policy with an always-true condition on a table that holds personal or per-user data: a `user_id`, `owner_id`, `email`, `phone`, `address`, payment or message column, or a name such as `profiles`, `orders`, `messages`, `invoices`.
4. **Signed-in is treated as authorised.** A condition such as `auth.role() = 'authenticated'` or `auth.uid() is not null`, or `to authenticated using (true)`, on a table with per-user data. Anyone can sign up, so this means "everyone with an account sees everyone's rows".
5. **An update policy with no `with check`** on a table with an owner column, when its `using` is correct. The person can change the owner column and hand their row to someone else. Report it as a lower-priority problem.

Report under **"Check this is intended"**, not as a problem:

- A `select`-only policy with an always-true condition on a table with no personal or per-user columns (a product catalogue, public posts, a price list). Public reading is often the point. Ask the user to confirm.

Do **not** report:

- Policies that compare to the signed-in user, such as `auth.uid() = user_id` or `(select auth.uid()) = user_id`.
- Policies limited `to service_role`, whatever their condition.
- Tables with RLS on and no policies. Mention them in one line under "Looks right" as locked to the browser.
- A table whose RLS was off in an early migration and switched on in a later one.

## Output

Reply with this and nothing before it.

````
Supabase RLS review: <N> problem(s) found in <M> table(s) reviewed

## Problems

1. `<table>`: <the problem in one plain sentence>
   Where: `<file>:<line>`
   What this means: <who can do what, in plain words>
   Fix:
   ```sql
   <SQL to paste into a new migration or the SQL editor>
   ```

## Check this is intended

- `<table>`: <what is open and to whom> (`<file>:<line>`)

## Looks right

- `<table>`: <one line>

## Not checked

- The live database. This review read the SQL files only.
- Storage buckets and the policies on uploaded files. The `storage-bucket-review` skill checks those.
````

- `<M>` is every table you reviewed, including the ones with nothing wrong, not the number of tables with problems.
- Order problems by damage: anyone on the internet can write, then anyone on the internet can read private rows, then any signed-in user, then the rest.
- One numbered problem per table and fault. If a table has two faults, give it two entries.
- Write fix SQL that is complete and safe to paste: `alter table public.<table> enable row level security;`, `drop policy "<name>" on public.<table>;`, then `create policy` statements using `(select auth.uid()) = <owner column>`, with `to authenticated`, and `with check` on every insert and update policy. Use the table's real owner column. If the table has no owner column, say the fix needs one and show the `alter table … add column user_id uuid references auth.users (id)` line, with a note that existing rows will have no owner until they are filled in.
- When the fix enables RLS on a table that has no policies, warn that the app will stop seeing its rows until a policy is added, and include the policy.
- If there are no problems, write `Supabase RLS review: 0 problems found in <M> table(s) reviewed`, write "None." under Problems, and keep the other sections. Do not invent a problem.

<!--
MIT License

Copyright (c) 2026 PT Maverick Rintis Karya

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
-->
