Row Level Security for Supabase, with the tests that prove it.
If your app was built with Lovable, Bolt, v0 or Cursor, RLS is the only thing between one user's data and another's. This kit is the policy set I run in production, plus 25 tests and an audit script.
One-time purchase. Personal and commercial use. Updates included.
What "it works" looks like when RLS is wrong
The app runs. Every user sees every row. Nobody notices until someone does.
-- what the AI generated create policy "allow all" on public.profiles using (true); -- every profile readable by anyone -- holding the public anon key -- (which is in your page source)
-- what the kit ships create policy "profiles: read own" on public.profiles for select to authenticated using (auth.uid() = id); revoke all on public.profiles from anon; -- and a test that proves it
What's inside
Plain SQL and TypeScript. Nothing proprietary, no runtime dependency on Shieldbase.
| File | What it gives you |
|---|---|
001_profiles.sql | One profile per user created by a signup trigger. Users read and update only their own row. with check on every write. |
002_entitlements.sql | Premium and paid-content gating through has_entitlement(). Premium rows are invisible without an active, unexpired entitlement. |
003_tenants.sql | Organizations, members and documents. Org A can never read, write or see org B. Membership checks go through security-definer helpers, so nothing recurses. |
004_storage.sql | A public avatars bucket and a private files bucket, both locked to <user-id>/ folders. |
tests/rls.test.ts | 25 Vitest tests run as two real signed-in users plus the raw anon key. When one goes red, that's a real hole. |
scripts/rls-audit.sql | One query that lists every table with RLS off, RLS on but no policies, using (true), writes without with check, anon grants, exposed definer functions, and public buckets. |
src/lib/supabase/* | Browser, server and admin clients for Next.js App Router. The admin client imports server-only, so the build fails if it's ever bundled for the browser. |
README.md | Install in 15 minutes, adapt to your schema, and the six mistakes below with the fix and the test for each. |
The six RLS mistakes AI builders make
Each one has a policy in the kit that fixes it, a test that proves it, and an audit finding that catches it.
RLS on, no policies
Every query returns nothing. Builders "fix" it by turning RLS off, which is the next mistake.
using (true)
The same as no security. Every user's data is readable with the public key.
Writes without with check
Users can insert rows that belong to someone else, or re-point their row at another user.
Policies that query another RLS table
Recursion errors, or a silent empty result that locks everyone out.
Service-role key in the browser
It bypasses RLS entirely. Once it's in page source, anyone owns the database.
Public storage bucket "for now"
User documents become world-readable URLs and nobody revisits it.
Proof, not promises
The tests and the audit script are the product. The policies are what they protect.
Pricing
The kit for people who want to fix it themselves. The audit for people who want it checked.
RLS Starter kit
- 4 migrations with complete policies
- 25-test suite
- rls-audit.sql
- Next.js client, server and admin setup
- README with the six mistakes
- Updates via private buyers repo
Supabase Security Audit
- Every table's RLS status and policies reviewed by hand
- Auth configuration, storage rules, exposed keys
- Written report: findings ranked critical, high, medium, each with the exact fix
- Fixed quote to implement, if you want me to
- Needs read-only project access or a schema dump, revocable after
Questions
Does it work with a Lovable, Bolt or v0 project?
Yes. Those tools create a standard Supabase project. Apply the migrations through the SQL editor or the CLI, and replace the generated client files with the ones in the kit.
Does it work with Prisma or Drizzle?
The SQL is plain Postgres and works with any tool. The TypeScript clients are for the Supabase JS SDK; a Drizzle variant is planned for buyers.
Do I need Docker?
No. The tests run against any Supabase project, including a free hosted one. Local Supabase via Docker is supported but optional.
Why revoke grants from anon if RLS is already on?
RLS filters rows. Grants decide whether the role can query the table at all. Both layers on is defence in depth, and the audit script checks both.
What's the licence?
Use it in unlimited personal and commercial projects. Don't resell or republish the kit itself.
Who's behind it?
Rusiru De Silva, a backend engineer with 10+ years on production systems for healthcare, government and enterprise. I answer RLS questions in the Supabase and Lovable communities most days; the kit is everything I kept repeating.