# Supabase security checklist: row level security, keys and storage

Published: 2026-11-17 · Updated: 2026-11-16 · By HackerGPT Team
Canonical: https://hackergpt.org/blog/supabase-security-checklist/

> Five checks for a Supabase app before real users arrive: RLS on every table, policies that scope rows, views, storage bucket policies and where each key lives. Each was run on a local Supabase project, with the output it gave.

**TL;DR:** A Supabase app is only as private as its row level security, because the publishable (anon) key in your front end can query every exposed table, view and bucket. Check five things: RLS is on for every table, no policy says `using (true)` where it should name an owner, views run as the caller, storage policies scope files to their owner, and the secret key exists only on your server. Then test each check as an anonymous visitor and as a second user, not only in the dashboard.

This is for the founder or small team shipping on Supabase who wants to know what a stranger can read before real users arrive. Test only a project you own or have written permission to test. We built a small invoicing app on a local Supabase stack, made four common mistakes on purpose, and ran every check below against it. The output in this article is what those checks printed.

If you have not been through the broader list yet, start with our [security checklist for vibe-coded and indie SaaS apps](https://hackergpt.org/blog/vibe-coded-app-security-checklist/). This article goes deeper on its Supabase item.

## Why does the anon key make RLS the whole story?

Because the anon key is meant to be public, row level security is the only thing deciding which rows it gets. Supabase calls publishable keys (`sb_publishable_…`, and the legacy `anon` JWT they replace) "safe to expose online" ([Supabase, API keys](https://supabase.com/docs/guides/api/api-keys)). Anyone can copy that key out of your page and call your Data API and Storage directly, without your UI in the way.

Each request runs as a Postgres role: `anon` for a visitor, `authenticated` once they sign in. On the hosted platform, a new table in `public` on existing projects starts with every privilege granted to those roles ([Supabase, Securing your API](https://supabase.com/docs/guides/api/securing-your-api)). Our local stack (Supabase CLI 3.1.0) showed the same:

```text
    table_name     |                        anon_privileges
-------------------+---------------------------------------------------------------
 feedback          | DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE
 invoices          | DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE
 profile_directory | DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE
 profiles          | DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE
```

So the grants say "yes" to everything, and RLS policies are what narrow that down to the rows a person should see. The secret key works the other way: its `service_role` has the `BYPASSRLS` attribute, so policies never apply to it ([Supabase, API keys](https://supabase.com/docs/guides/api/api-keys)).

![Diagram: the browser key reaches data only through RLS policies; the secret key's service\_role skips them](https://hackergpt.org/blog/supabase-security-checklist/key-paths.webp) *The publishable (anon) key is public by design. What it can reach is decided by RLS policies; the secret key skips them.*

## The lab: four mistakes in one small app

Our test app has three tables, a view and two buckets, written the way a fast build often writes them:

- `profiles`: RLS on, with a policy that lets a user read only their own row. This is the intended pattern.
- `invoices`: created with raw SQL and never given RLS.
- `feedback`: RLS on, but its policy is `using (true)`.
- `profile_directory`: a view over `profiles`, created without `security_invoker`.
- Storage: a public `avatars` bucket, and a private `invoice-pdfs` bucket whose read policy checks the bucket but not the folder.

Two users, Alice and Bob, each own one invoice. To follow along, run `supabase init` and `supabase start` in an empty folder (Docker required), then put the API URL and publishable key from `supabase status` in `$SUPABASE_URL` and `$ANON_KEY`. Every command below also works against your own hosted project.

## How do I check that RLS is enabled on every table?

Ask Postgres which tables in `public` have RLS off and how many policies each has. Run this in the SQL editor or with `psql`:

```sql
select c.relname as table,
       c.relrowsecurity as rls_enabled,
       (select count(*) from pg_policies p
         where p.schemaname = 'public' and p.tablename = c.relname) as policies
from pg_class c
where c.relnamespace = 'public'::regnamespace and c.relkind in ('r', 'p')
order by 1;
```

On our app:

```text
  table   | rls_enabled | policies
----------+-------------+----------
 feedback | t           |        1
 invoices | f           |        0
 profiles | t           |        1
```

`invoices` is the finding. Supabase notes that tables created through the dashboard have RLS on by default, and that you must enable it yourself for tables created in the SQL editor or another tool ([Supabase, Securing your API](https://supabase.com/docs/guides/api/securing-your-api)). AI coding assistants usually write `create table` statements, so this gap is common in generated migrations.

A table with RLS on and zero policies is the opposite case: no data is reachable through the API with a publishable key until you add a policy ([Supabase, Row Level Security](https://supabase.com/docs/guides/database/postgres/row-level-security)). That fails closed, which is safer, but it also explains why a developer under pressure "fixes" an empty response by writing `using (true)`.

## What can the anon key actually read?

Whatever a request with only the anon key returns, which is what you should test rather than infer. Query each table and view the way a visitor's browser could:

```bash
for t in profiles invoices feedback profile_directory; do
  echo "--- $t"
  curl -s "$SUPABASE_URL/rest/v1/$t?select=*" -H "apikey: $ANON_KEY"
  echo
done
```

Our output, with user ids shortened:

```text
--- profiles
[]
--- invoices
[{"id":1,"user_id":"52f4081b-…","customer_email":"client-one@your-app.example","amount_cents":120000},
 {"id":2,"user_id":"2489dfb4-…","customer_email":"client-two@your-app.example","amount_cents":45000}]
--- feedback
[{"id":1,"user_id":"52f4081b-…","message":"Please add CSV export"},
 {"id":2,"user_id":"2489dfb4-…","message":"Export page is slow"}]
--- profile_directory
[{"id":"52f4081b-…","full_name":"Alice Example","plan":"pro"},
 {"id":"2489dfb4-…","full_name":"Bob Example","plan":"free"}]
```

Three findings in one loop:

1. **`invoices`** returns every row because RLS is off. With RLS off, the grants above also allow writes: an anonymous `PATCH` to `invoices?id=eq.2` returned `204` and changed Bob's amount in the database.
2. **`feedback`** returns every row although RLS is on, because a policy of `using (true)` allows every row. A policy that does not name the owner is the most common reason "RLS is on" and data still leaks.
3. **`profile_directory`** returns every profile while `profiles` itself correctly returns `[]`. Supabase warns that views bypass RLS by default because they are usually created by the `postgres` user ([Supabase, Row Level Security](https://supabase.com/docs/guides/database/postgres/row-level-security)).

To find which names to test, list what the API exposes. On our local stack, the Data API root answered the anon key with its OpenAPI description, which lists every exposed table and view:

```bash
curl -s "$SUPABASE_URL/rest/v1/" -H "apikey: $ANON_KEY" \
  | python3 -c 'import sys,json; print(sorted(p for p in json.load(sys.stdin)["paths"] if p != "/"))'
```

```text
['/feedback', '/invoices', '/profile_directory', '/profiles']
```

Then repeat the loop with a second user's access token in `Authorization: Bearer`, because a policy can be right for `anon` and wrong for `authenticated`. If your app has its own API routes beyond Supabase, [AppMap](https://hackergpt.org/features/appmap/) lists every endpoint with the auth it requires, which gives you the rest of the list to test.

## How do I fix RLS policies, views and grants?

Turn RLS on, name the role a policy applies to, and compare the row's owner with `auth.uid()`. This migration fixed all three findings in our app:

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

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

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

drop policy "Anyone can read feedback" on public.feedback;

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

alter view public.profile_directory set (security_invoker = true);
```

The details matter:

- **`to authenticated`** stops the policy from being evaluated for `anon` at all; Supabase recommends always naming the role ([Supabase, Row Level Security](https://supabase.com/docs/guides/database/postgres/row-level-security)).
- **`using` vs `with check`**: `using` decides which existing rows a statement can see or change, and `with check` decides what a new or updated row may look like. Inserts need `with check`, or a user can write rows that claim to belong to someone else. In our app, Bob's attempt to insert an invoice with Alice's `user_id` now fails with `new row violates row-level security policy`.
- **`(select auth.uid())`** rather than bare `auth.uid()` lets Postgres evaluate it once per statement instead of once per row, per the same page.
- **`security_invoker = true`** makes the view apply the caller's permissions and RLS. It requires Postgres 15 or later ([PostgreSQL, CREATE VIEW](https://www.postgresql.org/docs/current/sql-createview.html)).

After the migration, the same anon loop returned `[]` for all four names, and Bob saw only his own invoice and profile.

One result surprised us. After the fix, the anonymous `PATCH` to `invoices` still returned `204`, yet the row was unchanged: RLS filtered the update down to zero rows, and PostgREST reported success anyway. Asking for the result makes the difference visible: with `Prefer: return=representation` the same request returned `[]`. **Judge a write test by the data, not by the status code.**

## Are my storage buckets private?

A bucket is private unless you made it public, but a private bucket is only as private as its policies on `storage.objects`. Supabase's own documentation sets out three rules ([Storage access control](https://supabase.com/docs/guides/storage/security/access-control), [bucket fundamentals](https://supabase.com/docs/guides/storage/buckets/fundamentals)):

- Buckets are private by default.
- In a public bucket, anyone with a file's URL can read it, while uploads, deletes and moves still go through access control.
- No upload is allowed without a policy.

Our private bucket had this read policy:

```sql
create policy "Signed-in users read invoice PDFs"
  on storage.objects for select to authenticated
  using (bucket_id = 'invoice-pdfs');
```

It looks scoped, but it only scopes the bucket. Signed in as Bob, we listed Alice's folder and downloaded her invoice:

```bash
curl -s "$SUPABASE_URL/storage/v1/object/authenticated/invoice-pdfs/$ALICE_ID/2026-11.pdf" \
  -H "apikey: $ANON_KEY" -H "Authorization: Bearer $BOB_TOKEN"
```

```text
%PDF-1.4 invoice for client-one
```

The fix ties the first folder of the path to the caller, the pattern Supabase's access-control guide uses:

```sql
drop policy "Signed-in users read invoice PDFs" on storage.objects;

create policy "Users read their own invoice PDFs"
  on storage.objects for select to authenticated
  using (
    bucket_id = 'invoice-pdfs'
    and (storage.foldername(name))[1] = (select auth.uid()::text)
  );
```

After it, Bob's request returned `Object not found` and Alice's still returned her file. Apply the same folder check to `insert`, `update` and `delete` policies if users upload files.

The public `avatars` bucket behaved as documented: the public URL served Alice's avatar to anyone, an anonymous upload was refused with `new row violates row-level security policy`, and an anonymous listing returned `[]`. Then we added a broad `select` policy on `avatars`, the kind people add when downloads seem broken. Listing then returned Alice's folder name, which is her user id. Supabase says a `select` policy is not needed for public buckets ([Storage access control](https://supabase.com/docs/guides/storage/security/access-control)), so leave it out. Keep anything you would not hand to a stranger in a private bucket.

## Is my service role key exposed?

It is exposed if a secret key (`sb_secret_…`) or a legacy JWT whose payload says `"role":"service_role"` appears anywhere a browser can fetch it. Supabase says never to put a secret key "in a browser, a shipped application, or source control" ([Supabase, API keys](https://supabase.com/docs/guides/api/api-keys)), because it skips every policy above.

Search your production build, not just your source, because the bundler decides what ships. We planted one of each key in a test build and searched it:

```bash
grep -rnoE 'sb_secret_[A-Za-z0-9_-]+|sb_publishable_[A-Za-z0-9_-]+|eyJ[A-Za-z0-9_-]+\.eyJ[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+' dist/
```

```text
dist/assets/admin-def456.js:1:sb_secret_…
dist/assets/index-abc123.js:1:sb_publishable_…
```

(Values cut here; your terminal prints them in full.) A publishable key in the bundle is expected. A secret key is a finding. Legacy keys are both JWTs starting `eyJ`, so decode the middle part to tell them apart:

```bash
echo "$KEY_FROM_BUNDLE" | cut -d. -f2 | python3 -c 'import sys,base64,json; p=sys.stdin.read().strip(); print(json.loads(base64.urlsafe_b64decode(p+"="*(-len(p)%4)))["role"])'
```

On our stack the two legacy keys decoded to `anon` and `service_role`. Our post on [hardcoded credentials in a JavaScript bundle](https://hackergpt.org/blog/hardcoded-credentials-javascript-bundle/) covers source maps and other places where secrets hide in a build.

Supabase adds a safety net on its hosted platform: a secret key sent with a browser `User-Agent` is refused with `401` ([Supabase, API keys](https://supabase.com/docs/guides/api/api-keys)). Our local stack did not do this. The same request with a Chrome `User-Agent` returned `200` and every profile. Do not count on the safety net: it matches a header, and code on your server is not a browser.

If a secret key has shipped, treat it as leaked. Create a new one in the dashboard, deploy the new one to your server, then delete the old one. Note too that Supabase plans to deprecate the legacy `anon` and `service_role` keys by the end of 2026 ([Supabase, API keys](https://supabase.com/docs/guides/api/api-keys)), so moving to publishable and secret keys is due anyway.

## Does the Supabase Security Advisor catch all of this?

It caught two of our five findings. The [Security Advisor](https://supabase.com/docs/guides/database/database-advisors) runs Supabase's database lints, and the CLI runs them locally with `supabase db advisors`. On our app before the fixes:

```text
ERROR security_definer_view - View `public.profile_directory` is defined with the SECURITY DEFINER property
ERROR rls_disabled_in_public - Table `public.invoices` is public, but RLS has not been enabled.
```

It did not flag the `using (true)` policy on `feedback`, the storage policy without a folder check, or the secret key in the bundle. After the fixes it printed `No issues found`. That is a useful gate for CI (`--fail-on error`), but a clean advisor run means only that these lints passed. Whether Bob can read Alice's rows is a question about your data model, and only a test as Bob answers it.

## What should a Supabase security checklist include?

Here is the list we ran, in the order we would run it:

| Check | How | A finding looks like |
| --- | --- | --- |
| RLS on every exposed table | `pg_class.relrowsecurity` query | `rls_enabled = f` |
| Policies name an owner | read `pg_policies.qual` | `true`, or no `auth.uid()` where rows belong to users |
| What anon can read | `curl` each table and view with the anon key | rows from a table that should be private |
| A second user's view | same `curl` with another user's token | another user's rows |
| Writes | `PATCH`/`POST` as anon and as another user, then check the data | the row changed |
| Views | `reloptions` lacks `security_invoker=true` | view returns rows its table hides |
| Storage policies | download another user's file path | the file comes back |
| Public buckets | list them as anon | file names or user ids |
| Secret key | grep `dist/`, decode JWT `role` | `sb_secret_` or `service_role` in the bundle |
| Advisor | `supabase db advisors --fail-on error` | any ERROR |

Supabase's [production checklist](https://supabase.com/docs/guides/security/production-checklist) adds account-level items worth doing before launch: MFA on your Supabase account, email confirmations, SSL enforcement and network restrictions.

## Key takeaways

- Treat the publishable (anon) key as public and RLS as the only gate: enable RLS yourself on every table you create with SQL.
- Write policies that compare an owner column with `(select auth.uid())`, name the role with `to authenticated`, and add `with check` to every insert and update policy.
- Set `security_invoker = true` on views in exposed schemas, and scope storage policies to the caller's folder, not just the bucket.
- Test as anon and as a second user with `curl`, and judge write tests by the data, since a blocked `PATCH` can still return `204`.
- Keep the secret key on the server, grep your built bundle for `sb_secret_` and `service_role`, and run `supabase db advisors` in CI as a floor, not a verdict.

## FAQ

### Is it safe to expose the Supabase anon key?

Yes. The anon key and the newer publishable key are designed to ship in the browser. What makes that safe is row level security: with RLS off on a table, the same public key can read, and often change, every row in it. Exposing the secret or service\_role key is never safe.

### Does Supabase enable RLS by default?

Tables created in the Supabase dashboard have RLS enabled by default. Tables created with SQL, in the SQL editor, in migrations or by other tools do not, and you must run `alter table … enable row level security` yourself. A table with RLS on and no policies returns nothing through the API until you add one.

### How do I test Supabase RLS policies?

Call the Data API the way a browser would: once with only the publishable key, and once with a second test user's access token, and compare what comes back with what that person should see. Test writes too, and check the data afterwards rather than trusting the status code. `supabase db advisors` catches missing RLS and unsafe views, but it cannot tell whether a policy matches your intent.

### Are Supabase storage buckets public?

Buckets are private by default. A public bucket serves any file to anyone who has its URL, while uploads, deletes and moves still need a policy. In a private bucket, access depends entirely on your `storage.objects` policies, so check that they scope files to the user, usually through the first folder in the path.

### What happens if my service\_role key leaks?

Anyone with it can read and change every row and every file, because the `service_role` bypasses RLS. Create a new secret key, move your server to it, delete the old key, and then review your data for changes made while the old key was exposed.

## Sources

- [Supabase — API keys](https://supabase.com/docs/guides/api/api-keys)
- [Supabase — Row Level Security](https://supabase.com/docs/guides/database/postgres/row-level-security)
- [Supabase — Securing your API](https://supabase.com/docs/guides/api/securing-your-api)
- [Supabase — Storage access control](https://supabase.com/docs/guides/storage/security/access-control)
- [Supabase — Storage buckets fundamentals](https://supabase.com/docs/guides/storage/buckets/fundamentals)
- [Supabase — Database advisors](https://supabase.com/docs/guides/database/database-advisors)
- [Supabase — Production checklist](https://supabase.com/docs/guides/security/production-checklist)
- [PostgreSQL — CREATE VIEW](https://www.postgresql.org/docs/current/sql-createview.html)

Want to see the same access-control mistakes on a target built for practice? Try them on [CyberGym](https://cybergym.hackergpt.app), or point HackerGPT at your own app at [hackergpt.app](https://hackergpt.app).
