Skip to content
toujiBook a call

Guide

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

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. 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. 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, 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. 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, and in many projects new tables in public are granted to anon and authenticated by default. 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:

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:

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:

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.
  • Policies based on user metadata. Users can edit their own user_metadata, 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. Without it, a user may be able to write a row that belongs to someone else.
  • Views. Views bypass RLS by default because they run as their owner. On Postgres 15 and later, create them with security_invoker = true 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:

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 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. Whoever holds it can read and change everything. New secret keys refuse requests from browsers, 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.
  • 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. 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, with no policy check. Buckets are private by default, and in a private bucket every operation goes through policies on storage.objects.

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

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:

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.

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 page lists where each one is.

How to check each setting.

  • Confirm email. With it off, Supabase treats every email address as confirmed, 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. Wildcards belong to local and preview addresses.
  • Password rules. Set a minimum length of at least 8 and turn on leaked password protection, which is available on the Pro plan and above.
  • Anonymous sign-ins. If they’re on, anonymous users get the authenticated role, 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 and add CAPTCHA to sign-up, sign-in and password reset if bots are a risk.
  • Multi-factor authentication. Offer MFA, and require it for admin accounts.
  • Email sending. The built-in sender is limited to 2 emails per hour. Set up custom 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 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. 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. 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.
  • 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, 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:

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 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:
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 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 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 and Vibe-coded app rescue, or book a call. If the app also misbehaves in production, start with what to check first.

Where we can help

All services

Tell us what's going on.

Describe the app and the problem in a few lines. We'll set up a call and send a written quote.