Skip to main content

Supabase Row Level Security for AI-Built Apps

By the OnlineAppCreator editorial team4 min read

Short answer

In a Supabase app the anon key is public, so Row Level Security is the only thing standing between any visitor and your data. AI-built apps often ship with RLS disabled on some tables, policies that use true as a condition or storage buckets left public. Enable RLS on every table, write policies scoped to auth.uid(), keep the service role key server-side and test policies as real users before launch.

On this page
  1. Why RLS matters more in AI-built apps
  2. The most common RLS mistakes
  3. How to test policies properly
  4. Beyond RLS: functions, views and performance
  5. Making it part of the release process

Supabase is the default backend for many apps generated with Lovable, Bolt, v0 and similar tools, and it is a frequent choice in Claude Code and Codex projects too. Its model is simple: the browser talks directly to the database through an API, and PostgreSQL Row Level Security (RLS) decides which rows each user may read or change. When RLS is correct, this is secure and fast. When it is missing or wrong, anyone who opens the browser developer tools can read or modify your data. This guide explains the mistakes we see most and how to fix them.

Why RLS matters more in AI-built apps

The Supabase anon key and project URL are embedded in the frontend by design. That is not a leak; it is how the platform works. The consequence is that every security decision has to be made in the database. Code generators sometimes create tables during rapid iteration and forget to enable RLS, or they add a permissive policy to make an error disappear. Because the app still works, nobody notices. Several public reports of exposed data in vibe-coded apps have come down to exactly this.

The Supabase dashboard flags tables without RLS and offers a security advisor that checks for common problems. Use it, but do not treat it as complete: it can tell you RLS is enabled, not that your policies match your business rules.

The most common RLS mistakes

RLS disabled on "unimportant" tables

Lookup tables, logs, invitation codes or feature flags often stay unprotected. Attackers do not care which table you think is important. An invitation table without RLS can let someone join any workspace.

Policies that always pass

A policy with using (true) for authenticated users means every logged-in user sees every row. Since sign-up is often open, "authenticated" is close to "anyone". Policies should compare ownership, for example auth.uid() = user_id, or check membership through a join to a members table.

Missing write policies and column checks

A select policy is not enough. Insert and update policies need a with check clause, otherwise a user can create rows for another user or change the user_id of an existing row. Columns such as role, is_admin or plan on a profiles table should not be updatable by the user at all; move them to a separate table or restrict updates with column privileges or a trigger.

Public storage buckets and leaked service keys

Storage has its own policies. Buckets marked public serve every file to anyone with the URL. The service role key bypasses RLS completely; if it appears in frontend code, an environment variable prefixed for the browser or a public repository, rotate it immediately.

How to test policies properly

  1. Create two normal test users in separate tenants or organisations, plus one admin.
  2. Log in as user A and, using the browser console or a script with the anon key, try to select, insert, update and delete user B's rows on every table.
  3. Try to update privileged columns on your own profile, such as role or plan.
  4. Call every RPC function and edge function as an anonymous visitor and as user A, and check what they return.
  5. List storage objects in each bucket and request another user's file by path.
  6. Turn the successful checks into automated tests, for example SQL tests with pgTAP or integration tests in CI, so regressions are caught.

Agentic tools help here. Ask Claude Code or Codex to generate the test matrix from your schema and to write policies for every table, then review each one manually. Never accept a policy you cannot explain in one sentence.

Beyond RLS: functions, views and performance

Database functions declared security definer run with elevated rights and bypass RLS; give them an explicit search_path and check permissions inside. Views can also bypass RLS unless created with security_invoker on recent PostgreSQL versions. On the performance side, index every column used in a policy and wrap auth.uid() in a subselect as Supabase recommends, so it is evaluated once per query rather than per row. Our article on scaling an AI-built app explains why this matters as data grows.

Making it part of the release process

RLS is not a one-time task. Every new table, generated in a prompt at midnight, needs a policy before it reaches production. Add a CI check that fails when a table in the public schema has RLS disabled, and include policy review in your pull request template. Our security audit checklist for vibe-coded apps places RLS among the other checks, and the Lovable production deployment guide shows where it fits in the go-live sequence.

For teams, the neooutput secure agentic coding workshops include hands-on RLS exercises, and the neooutput AI development services team reviews and hardens Supabase setups of existing apps. Organisations that need governance over how AI tools access internal data can look at KalaidoCreate for compliance and access controls at platform level.

Frequently asked questions

Is it safe that my Supabase anon key is visible in the browser?

Yes, the anon key is meant to be public. It is only safe when Row Level Security is enabled and correctly configured on every table and storage bucket.

What is the difference between the anon key and the service role key?

The anon key respects RLS policies. The service role key bypasses them entirely and must only be used in trusted server-side code, never in the frontend.

Can I trust policies generated by Lovable or an AI agent?

Treat them as drafts. Review each policy, test it as different users and add automated tests, because generated policies are often too permissive.

Do RLS policies slow down my app?

They can on large tables if the columns used in policies are not indexed. Index those columns and follow Supabase's guidance on caching auth.uid() in policies.

Want this done right, the first time?

OnlineAppCreator takes products from idea to operation. Tell us where you stand and get a concrete plan in a free 15-minute call.