DEV Community

Trung Thanh Tran
Trung Thanh Tran

Posted on

Probing Supabase RLS leaks with HEAD Prefer: count=exact (0 rows downloaded)

When you ship a Supabase app generated with Bolt, Lovable, or Cursor, the dashboard can show a green RLS badge on every table while your public anon key can still read every row.

That usually happens for one of four reasons:

  1. The AI ran ENABLE ROW LEVEL SECURITY and then added CREATE POLICY ... FOR SELECT USING (true) to make an early prototype error go away.
  2. A service_role JWT or third-party API key landed in the compiled Vite/Next.js client bundle.
  3. A Postgres view queries an RLS-protected table without WITH (security_invoker = true), so the view executes with the owner's privileges and skips RLS.
  4. A SECURITY DEFINER function is missing a fixed SET search_path = ''.

Checking row exposure without downloading user data

If you want to verify what an unauthenticated visitor can read from your own deployed project without pulling a single byte of user PII into your terminal or logs, PostgREST supports HEAD requests combined with Prefer: count=exact.

First, list the exposed tables from the OpenAPI spec:

curl -s "https://YOUR_REF.supabase.co/rest/v1/" \
  -H "apikey: YOUR_ANON_KEY" | jq '.paths | keys'
Enter fullscreen mode Exit fullscreen mode

Then run a HEAD probe against each table:

curl -I -s "https://YOUR_REF.supabase.co/rest/v1/profiles?select=*" \
  -H "apikey: YOUR_ANON_KEY" \
  -H "Authorization: Bearer YOUR_ANON_KEY" \
  -H "Prefer: count=exact"
Enter fullscreen mode Exit fullscreen mode

Look at the response status and Content-Range header. If it returns 200 OK with Content-Range: */1284, any visitor holding the public anon key from your frontend bundle can read all 1,284 rows. Because the method is HEAD, the response body is empty and zero rows are transferred.

Automating the check before launch

Running those curls by hand gets tedious once a project has 10+ tables and several client JS chunks. I wrapped the exact HEAD count probe, client bundle secret scan, and static schema.sql parser into a free read-only web checker so you can sanity-check your own app in ~10 seconds without signing up:

https://rlsguard-rho.vercel.app

It supports two modes:

  • Live URL scan (with an ownership checkbox): reads public JS chunks for leaked keys and runs read-only HEAD count probes against discovered PostgREST tables.
  • Paste schema.sql: checks locally for missing ENABLE ROW LEVEL SECURITY, USING (true) policies, views without security_invoker = true, and SECURITY DEFINER functions without search_path.

Quick SQL fixes for the two quietest bugs

For views that silently bypass RLS:

ALTER VIEW public.your_view SET (security_invoker = true);
Enter fullscreen mode Exit fullscreen mode

For USING (true) policies on user-owned tables:

DROP POLICY IF EXISTS "allow_read_all" ON public.profiles;
CREATE POLICY "profiles_select_own"
  ON public.profiles
  FOR SELECT
  TO authenticated
  USING ((select auth.uid()) = id);
Enter fullscreen mode Exit fullscreen mode

If you run the scanner on your own schema and hit a false positive or weird SQL syntax it misses, drop a comment and I will patch the parser.

Top comments (4)

Collapse
 
sunnatulla_dev profile image
Sunnatulla •

The HEAD count only covers tables. A SECURITY DEFINER function reading the same table still shows up under /rest/v1/rpc. On Postgres 17 I had profiles return 0 rows to anon, revoked execute on the function from anon, and anon still got all 1284 emails through it, because EXECUTE is granted to PUBLIC by default. revoke execute ... from public closed it.

Collapse
 
tthanh2k6 profile image
Trung Thanh Tran •

Good catch. The web HEAD probe only checks table paths, so it misses /rest/v1/rpc/* entirely. That default EXECUTE grant to PUBLIC in Postgres is easy to overlook if you only run REVOKE EXECUTE ... FROM anon, which is why the local SQL check flags SECURITY DEFINER functions and recommends revoking from PUBLIC first.

Collapse
 
userxnom profile image
Abdullah Naseer •

The HEAD probe is a neat trick — getting Content-Range: */1284 back with zero rows transferred turns a scary "is my data exposed?" question into a check you can run in seconds without touching user data. The USING (true) policy is the one I have seen most in AI-generated apps too: the AI fixes the prototype error by opening the door and nobody comes back to close it. Do you run this probe as part of your launch checklist now, or only when something smells off?

Collapse
 
tthanh2k6 profile image
Trung Thanh Tran •

I run it as part of my pre-launch checklist now, right after applying migrations and before sharing the link. It takes about 10 seconds and catches leftover prototype policies before anyone else hits the endpoint. For local work before deploying, I usually run the schema.sql check first so the bad policy never makes it to production.