Two-user RLS leak test

Source file: tools/leak-test/README.md

Download

The README was written for the repo version (pnpm leak-test). With the downloaded file, runnode leak-test.mjs with the same options.

Download leak-test.mjs17 KB · Node 20+ · nothing to install

SHA-256 (check it with shasum -a 256 leak-test.mjs)e37d63692a0ed0071a2bc2861c80d8f4ff2c6986080e499685aa75cb3b158828

Run it against a project you own
node leak-test.mjs --i-own-this-project \
  --url https://<ref>.supabase.co \
  --anon-key <publishable key> \
  --user-a a@you.dev:pass \
  --user-b b@you.dev:pass

Signs in to your Supabase project as two test users and as an anonymous visitor, then reports which tables and database functions show one user's data to a stranger or to the other user.

It finds the problems behind most Supabase data leaks in apps built with Lovable, Bolt, v0 or Cursor:

  • RLS disabled. Anyone with the public key in your JavaScript bundle can read the table.
  • Always-true policies (using (true), or "any signed-in user"). Every customer can read every other customer's rows.
  • SECURITY DEFINER functions callable by anon. They skip RLS entirely.
  • Optional write probes: whether user B can change or delete what user A created.

Safety rules

  • Only run it against a project you own or are authorised to test, with test accounts you created. It refuses to start without --i-own-this-project (or LEAK_TEST_I_OWN_THIS=1).
  • Read-only by default. Write probes are opt-in and only touch tables you name.
  • It never prints or stores row values. Reports contain table names, column names and counts.
  • It caps itself at 200 requests with a short delay between them. It is not a scraper.
  • It refuses service_role / sb_secret_ keys. Those bypass RLS, and they should never leave your server.

Setup (5 minutes)

  1. In your app, sign up two test users with throwaway emails, in separate workspaces/teams (for example, leaktest-a@yourdomain.com and leaktest-b@yourdomain.com).
  2. As each user, create a little data through the app: a record or two in each main screen.
  3. Copy your project URL and anon / publishable key from Supabase: Project Settings → API.

Run

bash
pnpm leak-test --i-own-this-project \
  --url https://<ref>.supabase.co \
  --anon-key <publishable key> \
  --user-a leaktest-a@yourdomain.com:<password> \
  --user-b leaktest-b@yourdomain.com:<password> \
  --md leak-report.md

If your project hides its API schema from public keys (good), add --tables invoices,clients,profiles,... with names from the Table Editor.

Write probes (creates and deletes one marker row per table you list):

bash
pnpm leak-test ... --probe-writes --write-tables notes,comments

Residual risk: if your insert triggers send emails or call webhooks, the marker row will fire them. Use tables without side effects, or a staging project.

The exit code is 1 when there is any critical or high finding, so it can run in CI against staging.

Sample output

Against the deliberately broken "before" app in this repo: evidence/leak-test/before-report.md. Against the hardened version: evidence/leak-test/after-report.md.

If it finds something

  1. Anonymous read: turn on RLS for that table, then add policies that name the owner. Supabase: Row Level Security
  2. Cross-user read: replace using (true) with an ownership or membership check, and wrap auth.uid() as (select auth.uid()) for speed. Never authorise with user_metadata, which users can edit.
  3. Function callable by anon: revoke execute ... from anon, public. Prefer security invoker, and pin search_path.
  4. Run the Security Advisor in the Supabase dashboard (Database → Advisors) and clear every ERROR. Supabase: Database Advisors
  5. If a service_role key was ever in your frontend or repo, rotate it. Supabase: API keys

This test covers the most common leaks. It is not a full audit: Storage buckets, Edge Functions, Stripe webhooks and business logic need a human review.