AI-WRITTEN CODE

Supabase Row Level Security: the setting that protects your data

Apps built quickly with AI tools often ship with Row Level Security switched off. Here is why that exposes every row, and how to fix it.

Supabase is a popular backend for apps built quickly with AI coding tools. It is safe when set up properly, but one setting decides whether your data is protected: Row Level Security, or RLS.

Why it matters

A Supabase app usually talks to the database straight from the browser, using a public "anon" key. That key is meant to be visible. What keeps your data safe is RLS: rules on each table that decide which rows a user may read or change.

If RLS is switched off on a table, anyone with your public key, which anyone can find in your website's code, can read and change every row in that table.

The two common mistakes

  • Tables created without RLS. Tables created with SQL do not have RLS turned on unless you enable it.
  • The service role key in the browser. The service role key bypasses RLS completely. It belongs only in server code, never in frontend code or a public environment variable such as NEXT_PUBLIC_.

How to fix it

Turn RLS on for every table in your public schema:

alter table public.profiles enable row level security;

Then add policies that allow only what each user needs, for example letting people read and update only their own profile:

create policy "Users read their own profile"
on public.profiles for select
using (auth.uid() = id);

Move any use of the service role key into server-side code, such as an API route or an edge function, and rotate the key if it was ever deployed to the browser.

Check your code

Our code scan looks for tables created without RLS, migrations that switch it off, and service role keys in browser code. Upload a ZIP or link your Git repository; each email address gets one free scan.

Check your own website or code for these problems.

Run a free security scan Ask us to review it

More from the blog

EMAIL SECURITY

SPF, DKIM and DMARC: stop people sending email as you

Without these three DNS records, anyone can send email that appears to come from your domain. Here is what each one does and how to set them up.

Read the article

WEBSITE SECURITY

How to read your free security scan report

Your scan report gives a score, findings by severity and evidence for each one. Here is what each part means and what to fix first.

Read the article

AI-WRITTEN CODE

Five security mistakes that are common in AI-written code

AI assistants write working code fast, but working is not the same as safe. Five common mistakes, how to spot them in your own code and how to fix each one.

Read the article
Let’s chat