# Supabase security checklist for apps built with AI tools

Six checks for a Supabase project set up by Lovable, Bolt or another AI tool, each with a way to verify it yourself.

Published 2026-11-25.

Page: https://touji.dev/guides/supabase-security-checklist

Apps built with AI tools often talk to Supabase straight from the browser. Lovable, for example, [puts the Supabase URL and publishable key into the front-end build](https://docs.lovable.dev/features/secrets). That is a supported design, but it moves the security work into the database: the key in the browser is public, so database rules, storage rules and a few settings decide who can read and change what.

This checklist covers the six places we look first. Each item says why it matters and how to check it yourself. The checking queries only read; run them in the Supabase SQL editor, and try any change on a copy of production first.

A note on key names. Supabase now issues **publishable** keys (`sb_publishable_...`) and **secret** keys (`sb_secret_...`). Older projects use the `anon` and `service_role` keys, which Supabase is [deprecating in early 2027](https://supabase.com/docs/guides/getting-started/api-keys). The rules below apply to both: publishable and `anon` are public, secret and `service_role` are not.

## Start with the Security Advisor

Supabase ships [Advisors](https://supabase.com/docs/guides/observability/advisors), a set of automatic checks that flag tables without RLS, risky views and functions, and other problems. Open **Advisors → Security Advisor** in the dashboard, or run `supabase db advisors` with the [CLI](https://supabase.com/docs/reference/cli/supabase-db-advisors). The CLI command has a `--fail-on` flag, so you can run it in CI and fail the build when a new problem appears.

The Advisor is a good first pass, not a full review. It can't know which rows each user should see. The checks below cover that gap.

## 1. Row Level Security on every table

**Why it matters.** A table in an exposed schema without RLS is [readable and writable by any role with a grant on it](https://supabase.com/docs/guides/database/postgres/row-level-security), and in many projects new tables in `public` are [granted to `anon` and `authenticated` by default](https://supabase.com/docs/guides/api/securing-your-api). Anyone with your publishable key, which is everyone who loaded your site, can then read the table.

**How to check.** List the tables in `public` that have RLS turned off. The `rowsecurity` column comes from Postgres's [`pg_tables` view](https://www.postgresql.org/docs/current/view-pg-tables.html):

```sql
select tablename
from pg_tables
where schemaname = 'public' and not rowsecurity;
```

Any result is a finding. Turn RLS on, then add policies for what the app needs:

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

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

Then review the policies that exist. Postgres lists them in the [`pg_policies` view](https://www.postgresql.org/docs/current/view-pg-policies.html):

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

Look for these problems:

- **Always-true policies.** `using (true)` or `with check (true)` lets every row through. The Advisor flags these as [permissive policies](https://supabase.com/docs/guides/observability/advisors).
- **Policies based on user metadata.** Users [can edit their own `user_metadata`](https://supabase.com/docs/guides/auth/managing-user-data), so a policy that reads a role or team ID from it lets users grant themselves access. Keep roles in a table users can't write to.
- **Insert and update without `with check`.** `using` checks the existing row; [`with check` checks the new one](https://supabase.com/docs/guides/database/postgres/row-level-security). Without it, a user may be able to write a row that belongs to someone else.
- **Views.** Views [bypass RLS by default](https://supabase.com/docs/guides/database/postgres/row-level-security) because they run as their owner. On Postgres 15 and later, create them with [`security_invoker = true`](https://www.postgresql.org/docs/current/sql-createview.html) so the caller's policies apply.

**Test it from outside.** Call the REST API the way a visitor's browser can, with only the publishable key, using the request from Supabase's [API quickstart](https://supabase.com/docs/guides/api/quickstart):

```bash
curl 'https://<PROJECT_REF>.supabase.co/rest/v1/orders?select=*' \
  -H "apikey: <PUBLISHABLE_KEY>"
```

If that returns rows a signed-out visitor shouldn't see, the policies are wrong. To keep them right, write [pgTAP tests](https://supabase.com/docs/guides/database/testing) that run with `supabase test db` and assert what each role can and can't do.

## 2. The secret key stays on the server

**Why it matters.** The secret key (and the legacy `service_role` key) [bypasses every RLS policy](https://supabase.com/docs/guides/getting-started/api-keys). Whoever holds it can read and change everything. New secret keys [refuse requests from browsers](https://supabase.com/docs/guides/getting-started/api-keys), a check the legacy `service_role` key doesn't have.

**How to check.**

- Search the built front-end code (usually the `dist/` folder) and the deployed site's JavaScript for `sb_secret_`.
- Legacy keys are long tokens starting with `eyJ`. Both the `anon` and `service_role` keys look like this, so decode the middle section of any you find and check its `role` field. Do this on your own machine, not in an online decoder.
- Check environment variable names. A secret in a variable starting with `VITE_` or `NEXT_PUBLIC_` [ends up in the browser](https://vite.dev/guide/env-and-mode).
- Search the repository and its history, not just the current files.

If a secret key was ever exposed, follow Supabase's guide to [rotating leaked keys](https://supabase.com/docs/guides/security/rotate-leaked-api-keys). Once nothing uses the legacy keys, disable them in **Settings → API Keys**.

## 3. Storage bucket policies

**Why it matters.** Files are often more sensitive than table rows: ID documents, invoices, private photos. In a **public** bucket, [anyone with a file's URL can download it](https://supabase.com/docs/guides/storage/buckets/fundamentals), with no policy check. Buckets are private by default, and in a private bucket every operation goes through [policies on `storage.objects`](https://supabase.com/docs/guides/storage/security/access-control).

**How to check.** List the buckets and which ones are public:

```sql
select id, public from storage.buckets;
```

Make sure every public bucket holds only files you'd be happy to see shared, such as product images. Then review the storage policies:

```sql
select policyname, cmd, roles, qual, with_check
from pg_policies
where schemaname = 'storage' and tablename = 'objects';
```

Look for policies that let any signed-in user read or overwrite any file in a bucket, rather than only their own. Also look for broad `select` policies on public buckets: public files don't need one, and it lets clients [list every file in the bucket](https://supabase.com/docs/guides/observability/advisors).

## 4. Auth settings

**Why it matters.** Defaults that are convenient while building can be wrong for real users. These settings live under **Authentication** in the dashboard. Supabase's [general configuration](https://supabase.com/docs/guides/auth/general-configuration) page lists where each one is.

**How to check each setting.**

- **Confirm email.** With it off, Supabase [treats every email address as confirmed](https://supabase.com/docs/guides/auth/general-configuration), so anyone can sign up with someone else's address.
- **Site URL and redirect URLs.** Set the Site URL to your production domain and use [exact redirect URLs in production](https://supabase.com/docs/guides/auth/redirect-urls). Wildcards belong to local and preview addresses.
- **Password rules.** Set a minimum length of at least 8 and turn on [leaked password protection](https://supabase.com/docs/guides/auth/password-security), which is available on the Pro plan and above.
- **Anonymous sign-ins.** If they're on, anonymous users get the [`authenticated` role](https://supabase.com/docs/guides/auth/auth-anonymous), so any policy that only checks "signed in" lets them through. Check the `is_anonymous` claim where it matters, or turn the feature off.
- **Abuse protection.** Review the [rate limits](https://supabase.com/docs/guides/auth/rate-limits) and add [CAPTCHA](https://supabase.com/docs/guides/auth/auth-captcha) to sign-up, sign-in and password reset if bots are a risk.
- **Multi-factor authentication.** Offer [MFA](https://supabase.com/docs/guides/auth/auth-mfa), and require it for admin accounts.
- **Email sending.** The built-in sender is limited to [2 emails per hour](https://supabase.com/docs/guides/auth/rate-limits). Set up [custom SMTP](https://supabase.com/docs/guides/auth/auth-smtp) before launch.

## 5. Edge Function secrets and access

**Why it matters.** Edge Functions are where your server-side secrets live, such as Stripe, email and AI API keys. Supabase also [gives every function your project's secret keys and database URL](https://supabase.com/docs/guides/functions/secrets) automatically. A function that uses the secret key skips RLS, so the function's own code becomes the access check.

**How to check.**

- **Where secrets are set.** Production secrets belong in the dashboard or are set with `supabase secrets set`. Locally they live in `supabase/functions/.env`, which [must be in `.gitignore`](https://supabase.com/docs/guides/functions/secrets). Run `supabase secrets list` to see which secrets are set.
- **Nothing echoes them.** Search function code for responses or logs that include environment values or full error objects.
- **Token checks are on.** Functions check the caller's token by default through [`verify_jwt`](https://supabase.com/docs/guides/functions/function-configuration). Search `supabase/config.toml` for `verify_jwt = false`. Each function with it off must check the caller some other way. A Stripe webhook, for example, should [verify Stripe's signature](https://supabase.com/docs/guides/functions/auth).
- **Ownership checks.** In any function that uses the secret key, confirm it checks that the signed-in user owns the record before reading or changing it.

## 6. Database functions with SECURITY DEFINER

**Why it matters.** A `security definer` function runs as the user who created it, usually `postgres`, which bypasses RLS. By default [any role can call it, including `anon`](https://supabase.com/docs/guides/database/functions), through `supabase.rpc()`. Switching a function to `security definer` is a tempting way to make an RLS error go away, for a person or an AI tool, and it can quietly open the data the policy was protecting.

**How to check.** List the `security definer` functions in `public`, whether their search path is set, and whether signed-out visitors can call them. The columns come from Postgres's [`pg_proc` catalog](https://www.postgresql.org/docs/current/catalog-pg-proc.html):

```sql
select p.proname,
       p.proconfig as settings,
       has_function_privilege('anon', p.oid, 'execute') as anon_can_call
from pg_proc p
join pg_namespace n on n.oid = p.pronamespace
where n.nspname = 'public' and p.prosecdef;
```

For each one, Supabase's [database functions guide](https://supabase.com/docs/guides/database/functions) recommends:

- **Use `security invoker` unless you need definer.** Invoker is the default and respects RLS.
- **Set the search path.** Add `set search_path = ''` and name the schema of every table in the body, such as `public.orders`. In the query above, a function with no `search_path` in `settings` needs this fix.
- **Check ownership in the body.** Who can call the function doesn't limit which rows it returns. The function itself has to compare the row's owner with `auth.uid()`.
- **Narrow who can call it.** Revoke `execute` from `public` and `anon`, then grant it only to the roles that need it:

```sql
revoke execute on function public.get_invoice from public, anon;
grant execute on function public.get_invoice to authenticated;
```

If the function takes arguments, add the argument types after its name, such as `public.get_invoice(uuid)`.

## Keep it checked

Security fixes in an AI-built app are easy to lose, because the next prompt can change a policy or a function. Keep the database schema in [migrations](https://supabase.com/docs/guides/deployment/database-migrations) in Git, run `supabase db advisors` and your pgTAP tests in CI, and read the diff when the AI tool changes anything under `supabase/`.

Supabase's own [production checklist](https://supabase.com/docs/guides/security/production-checklist) covers further items, such as network restrictions and access to your Supabase organization.

## Want a second pair of eyes?

We review Supabase projects for exactly these issues, fix what matters, and show you how to check each fix yourself. See [Security scanning and hardening](https://touji.dev/services/security-scanning) and [Vibe-coded app rescue](https://touji.dev/services/vibe-coded-app-rescue), or [book a call](https://touji.dev/contact). If the app also misbehaves in production, start with [what to check first](https://touji.dev/guides/lovable-bolt-app-breaks-in-production).

## Contact

To start, book a call or send a short note about your business and the problem at https://touji.dev/contact. The intro call is free. After the call we send a written, fixed-scope quote, so the full cost is known before any work starts. We do not publish prices. On-site across Los Angeles and Orange County. Remote anywhere.
