SecurityOct 31, 2026·8 min read

The Supabase RLS Default That Leaks Your Entire User Table

I tested an AI-generated SaaS app before launch: one curl request with the public anon key dumped 2,400 user profiles in 80ms. Here is why it happens and how we closed it.

#Supabase#Row Level Security#Security Audit#Lovable#Cursor#Bolt

01Run this check right now

Diagnostic Test

The 10-Second Supabase Public Exposure Check

Replace YOUR_ANON_KEY and YOUR_PROJECT_ID with values from your frontend code. If you receive a JSON array of users instead of an authorization error, your user table is publicly readable by anyone on the internet.

curl -s -H "apikey: YOUR_ANON_KEY" "https://YOUR_PROJECT_ID.supabase.co/rest/v1/users?select=*"

Findings from the Field

  • /01I ran a single curl check on an AI-built MVP and retrieved 2,400 customer records in 80ms using only the public anon key.
  • /02Tables created through visual dashboards enable RLS by default, but raw SQL statements generated by AI prompts leave RLS disabled.
  • /03Because PostgREST maps public tables directly to REST endpoints, any unconstrained table becomes an open public API.
  • /04A permissive USING (true) policy is a fake fix that leaks sensitive columns even if the frontend only asks for names.
  • /05How 3 precise SQL statements lock down user data to the authenticated owner.

The 80-millisecond data dump

A founder asked me to give their AI-generated app a quick sanity check before their public launch. The frontend looked great: clean Tailwind components, smooth transitions, and authentication with Supabase.

Before looking at any code, I opened the browser network tab, copied their public Supabase URL and anon key, and pasted them into a terminal curl command against their `/rest/v1/users` endpoint. In 80 milliseconds, my terminal printed a JSON array of 2,400 user rows: full names, emails, phone numbers, and Stripe customer IDs. No passwords or authentication required.

The founder was stunned. They assumed that because users had to log in on the frontend to see their profile, the database was protected. It is a very reasonable assumption to make, but it misses how PostgREST works under the hood.

Why SQL migrations skip row level security

Supabase has a subtle behavioral fork depending on how tables are created. If you click through the visual dashboard UI and create a table, Supabase automatically enables Row Level Security (RLS) and warns you if you have no policies.

When an AI coding tool like Cursor, Bolt, or Lovable builds your database, it does not click visual buttons. It generates raw SQL migrations containing statements like `CREATE TABLE public.users (...)`.

In standard PostgreSQL, tables created via SQL have Row Level Security turned off by default. Unless the AI writes an explicit `ALTER TABLE users ENABLE ROW LEVEL SECURITY;` statement, PostgreSQL allows any query arriving through the connection to read and write all rows.

Since Supabase connects your public browser code to PostgREST using the public anonymous key, every table without RLS is an open, unauthenticated REST API endpoint.

The glass house analogy

Think of it like building a house with an expensive smart deadbolt on the front door, but the entire back wall of the house is made of open air. Anyone who walks through the front door gets prompted for a key card, but anyone who walks around to the back can walk in and look through your filing cabinets.

In client-side code, `supabase.from('users').select('name')` looks safe because it only asks for names. But an attacker is not running your React components. They are sending direct HTTP requests to PostgREST with `select=*`.

The fake fix: permissive policies

Sometimes the AI assistant does enable RLS, but then runs into a permission error while building user profile pages. To make the error go away, the AI writes a permissive policy:

`USING (true)` tells PostgreSQL to return matching rows for every caller on the internet, authenticated or not. If your users table stores private metadata alongside display names, every column is returned in the API payload.

The dangerous workaround generated by AI modelssql
CREATE POLICY "Public profiles are viewable by everyone"
ON public.users
FOR SELECT
USING (true);

The 3-statement fix

Closing the leak took about 15 seconds in the Supabase SQL editor. First, flip on Row Level Security.

Second, restrict read access so authenticated callers can only read their own record with USING (auth.uid() = id).

Third, restrict updates so callers can only modify their own row with WITH CHECK (auth.uid() = id):

Production RLS policy suite for public.userssql
-- Step 1: Turn on RLS
ALTER TABLE public.users ENABLE ROW LEVEL SECURITY;

-- Step 2: Restrict SELECT to record owner
CREATE POLICY "Users can view their own data"
ON public.users
FOR SELECT
TO authenticated
USING (auth.uid() = id);

-- Step 3: Restrict UPDATE to record owner
CREATE POLICY "Users can update their own data"
ON public.users
FOR UPDATE
TO authenticated
USING (auth.uid() = id)
WITH CHECK (auth.uid() = id);

Reflections: checking client bundles for service keys

After applying those three SQL statements, I re-ran the curl command. Instead of 2,400 user records, the API returned an empty array `[]` with an HTTP 200 status. The front door and the back wall were both secured.

One parting note: make sure your client build does not contain the `service_role` key. The `service_role` key bypasses RLS by design. A quick terminal search confirms whether it leaked into your build output:

If that search turns up clean, your customer records are safe. Now on to the next audit, because yolo.

Terminal secret auditbash
grep -rn "service_role" dist/ .next/ 2>/dev/null

Production Hardening & Audits

Stuck on prompt regressions, leaked keys, or database scaling in an AI-built app? Explore our platform-specific teardowns:

Diagnostic & Rescue

1 business day reply

Think your prototype is vulnerable or hitting scale limits?

Send us a note with your repository, Supabase link, or project details. A senior engineer will review your policies and reply within one business day.