Skip to content
OverKnightsOverKnights home

Supabase security checklist for apps built with AI

Row-level security, service role keys, storage policies and edge functions: the Supabase checks that matter most when an AI assistant wrote the code.

OverKnightsPublished 3 min read
Short answer

For a Supabase app built with AI, confirm row-level security is enabled on every table in exposed schemas, that each policy restricts rows to the right user or organisation, that the service role key never appears in client code or public environment variables, that storage buckets have policies, and that edge functions and RPCs check the caller. Then test with the anonymous key as an outsider would.

  • With the anon key in the browser, RLS is the security boundary.
  • The service role key bypasses RLS, so it must only exist on the server.
  • Test policies from the outside with the anon key, not from the dashboard.

Supabase makes it easy to go from idea to working app, which is why it appears in so many AI-built products. Its security model is simple and strict: the browser talks to the database with a public key, and row-level security decides what each request can see.

When an assistant wrote the code, that model is often half applied.

1. RLS enabled on every exposed table

Check every table in schemas exposed through the API. Any table without RLS is readable and writable by anyone holding the public anon key, which is everyone who loads your site.

select schemaname, tablename, rowsecurity
from pg_tables
where schemaname = 'public'
order by rowsecurity, tablename;

Every row should show true.

2. Policies that actually restrict

RLS enabled with a policy of using (true) is the same as RLS off. Read each policy and ask: which rows can a signed-in user from another organisation see? Typical correct shapes:

create policy "members read own org projects"
on projects for select
using (org_id in (select org_id from memberships where user_id = auth.uid()));

Watch for separate insert, update and delete policies. Assistants often write a good select policy and a permissive write policy. More detail in Supabase RLS mistakes in AI code.

3. Service role key only on the server

The service role key bypasses RLS entirely. It belongs in server environments only. Search for it in client components, in NEXT_PUBLIC_ variables and in committed files. If it was ever exposed, rotate it.

4. Storage buckets with policies

Buckets marked public serve files to anyone with the URL. Private buckets need policies on storage.objects that match your data model. Check uploads too: who can write where.

5. RPCs and edge functions check the caller

Postgres functions declared with security definer run with elevated rights. Edge functions receive whatever the client sends. Both need explicit checks on who is calling and what they may touch.

6. Auth settings

  • Email confirmation on, unless you have a reason.
  • Redirect URLs restricted to your domains.
  • Rate limits reviewed for sign-up and password reset.

Test from the outside

The dashboard runs queries with elevated rights, so it will not show you a policy gap. Test with the anon key, signed out and signed in as a second test user, and try to read the first user's rows. Write it as an automated test so a future change cannot quietly break it.

Checklist

  • RLS enabled on every exposed table
  • Every policy scoped to user or organisation, for select and writes
  • Service role key absent from client code and public variables
  • Storage buckets private by default with policies
  • Security definer functions and edge functions check the caller
  • Automated test that a second user cannot read the first user's data

These map to SEC-03, SEC-01 and SEC-02 in our checklist, and they are among the most common Critical findings in AI-built apps.

Frequently asked questions

Is the Supabase anon key a secret?

No. It is designed to be public. Your data is protected by row-level security policies, which is why they must be on and correct.

Why do AI assistants turn RLS off?

Because a query that fails due to a policy works immediately once RLS is disabled or the service role key is used. The assistant is solving the error, not the security.

Do RLS policies slow queries down?

They add conditions to queries. Index the columns your policies filter on, such as user or organisation IDs, and the cost is usually small.

OverKnights

Want to know what your repo would show?

Send one public repo. We reply with three verified findings and the prompts to fix them. No call needed.