SupabaseSecurityRow Level SecurityAI App Builder

Supabase Row Level Security: Fixing the Mistakes AI App Builders Make

Supabase Row Level Security explained for AI-built apps: the six RLS mistakes AI tools make, the SQL to fix them, and how to test policies before launch.

DeveloperMill5 min read

Most AI app builders and coding agents reach for Supabase as the backend, and for good reason: auth, Postgres, storage and an instant API in one place. The catch is how the instant API works. Your app talks to the database directly, using a key that ships inside the app. The only thing deciding what that key can do is Row Level Security (RLS).

When AI tools get RLS wrong, the result isn't a bug, it's a breach. In 2025, CVE-2025-48757 documented more than 170 apps built on one AI builder whose tables were readable without logging in, because RLS was off or too permissive.

Here are the six RLS mistakes we see most in AI-built apps, and how to fix each one.

How Supabase access actually works

Your app uses the anon or publishable key. Requests arrive as the anon role when logged out, or the authenticated role with the user's ID available as auth.uid() when logged in. RLS policies decide, row by row, what each role can do.

The service_role or secret key bypasses RLS completely. It's for servers and edge functions only.

Mistake 1: RLS is turned off

The classic. A table gets created by a migration or an AI prompt, and RLS is never enabled. Supabase's dashboard Security Advisor flags this, but only if someone looks.

Fix: enable it on every table in exposed schemas:

alter table public.profiles enable row level security;
alter table public.orders enable row level security;

With RLS on and no policies, the table denies everything. That's the right starting point. Add policies only for what's needed.

Mistake 2: "Allow all" policies

To make an error go away, AI tools often generate a policy like this:

-- Don't do this
create policy "Enable read access for all users"
on public.orders for select
using (true);

using (true) means every row is visible to everyone, including logged-out visitors. It's equivalent to RLS being off for reads.

Fix: scope reads to the owner, and to the right role:

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

Wrapping auth.uid() in a select lets Postgres evaluate it once per query instead of once per row, which Supabase recommends for performance. Add an index on user_id too.

Mistake 3: Checking "logged in" instead of "owns this row"

-- Any signed-in user can read every profile
create policy "Authenticated can read"
on public.profiles for select
to authenticated
using (true);

This passes a quick test, because the app works when you're logged in, but it lets any user read every other user's data. Anyone can sign up, so "authenticated" isn't a meaningful barrier.

Fix: always tie the condition to the row: user_id = (select auth.uid()), or membership in the row's team or organization (see mistake 6).

Mistake 4: Update policies without with check

using controls which rows a user can target. with check controls what the row is allowed to look like after the change. Without it, a user can update their own row in ways you never intended, such as changing user_id to someone else's or setting role = 'admin'.

create policy "Users update their own profile"
on public.profiles for update
to authenticated
using ((select auth.uid()) = id)
with check ((select auth.uid()) = id);

For columns users must never change, like role, plan or credits, don't rely on policies alone. Supabase grants table-wide update permission by default, so revoking a single column does nothing. Revoke update on the table, then grant it back only for the columns users may edit. Or keep those values in a separate table only the server writes to:

revoke update on public.profiles from authenticated;
grant update (full_name, avatar_url) on public.profiles to authenticated;

Mistake 5: Views and functions that bypass RLS

Two quieter leaks:

  • Views run with the permissions of the user who created them by default, often a superuser, so they can skip the RLS on the tables underneath. On Postgres 15 and later, create views with security_invoker so they respect the caller's policies:
create view public.order_summaries
with (security_invoker = true)
as select id, user_id, total from public.orders;
  • security definer functions run as their owner and bypass RLS. They're useful, but they must check auth.uid() themselves, set a fixed search_path, and shouldn't sit in an exposed schema unless you mean them to be callable.

Mistake 6: Team data with no membership model

B2B apps share data across a team or company. AI tools often handle that by making rows readable to all authenticated users. The correct pattern is a membership table and policies that check it:

create policy "Members read their team's projects"
on public.projects for select
to authenticated
using (
  team_id in (
    select team_id from public.team_members
    where user_id = (select auth.uid())
  )
);

The team_members table itself needs RLS, so users can't add themselves to someone else's team.

Don't forget storage

Files in Supabase Storage are protected by policies on storage.objects, separate from your tables. A public bucket serves every file to anyone with the URL. For private files, use a private bucket with policies tied to the path, for example a folder per user ID, and serve downloads through signed URLs.

How to test your policies

Before launch, test each table as three users:

  1. Logged out: using only the public key, try to select, insert, update and delete. Everything private should fail.
  2. Owner: confirm the app's normal flows work.
  3. A different user: sign up a second account and try to read and change the first user's rows by ID. This catches most real-world leaks.

Then open the Security Advisor in the Supabase dashboard and clear every warning about RLS being disabled or security-definer views.

The bigger picture

RLS is one layer. Secrets in the app bundle, payments trusted from the client and tokens in unencrypted storage are just as common in AI-built apps. Our 15-point AI-built app security checklist covers the rest. If you'd rather have someone else check it, that's exactly what our free production-readiness review is for.

Frequently asked questions

What is Row Level Security in Supabase?

Row Level Security (RLS) is a Postgres feature that Supabase uses to control which rows each user can read, insert, update or delete. Because Supabase apps query the database directly with a public key, RLS policies are what stop one user from reading another user's data, or an anonymous visitor from reading everything.

What happens if RLS is disabled on a Supabase table?

Any table in an exposed schema like public without RLS can be read and modified by anyone who has your project URL and public key, and both are inside your app. That was the root cause of CVE-2025-48757, which exposed more than 170 apps built with an AI app builder.

Does enabling RLS without policies break my app?

It blocks access. With RLS enabled and no policies, the table denies all reads and writes from the public and authenticated roles. That's the safe default. You then add specific policies for exactly what each user is allowed to do.

Does the service role key bypass RLS?

Yes. The service_role key, or the newer secret key, bypasses Row Level Security entirely. It must only be used on a server or in edge functions, never in a mobile or web client.

Bring us your AI prototype

Get a free 30-minute production-readiness review. We'll look at security, data access, store compliance and what it takes to ship, and you'll get a straight answer on whether to rebuild, harden or launch as-is.

Book your free review