I built a multi-tenant SaaS starter with Next.js + Supabase — and found 4 real bugs while hardening it #52409
Replies: 1 comment
|
The ones I see most often:
with check (user_id = (select auth.uid()))That lets anyone insert themselves into any org_id. Inserts into memberships should go through an invite flow, or a server-side path that checks the inviter is an admin of that org.
with check (
exists (select 1 from projects p
where p.id = project_id and p.org_id = tasks.org_id)
and org_id in (select org_id from org_members
where user_id = (select auth.uid()))
)
Testing #1 and #3 with two users in different orgs catches most of these. Docs: https://supabase.com/docs/guides/database/postgres/row-level-security I wrote up the details here: https://www.guardlayer.io/supabase-rls-checker |
Uh oh!
There was an error while loading. Please reload this page.
I tested a multi-tenant SaaS starter against real Postgres — here's what I learned
I've been building B2B SaaS OS, a Next.js + Supabase foundation for developers who need multi-tenancy, RBAC, authentication, Stripe billing, API keys, usage limits, and audit logs.
While hardening it, I found and fixed four real bugs and added regression tests so those specific failures could be caught in the future.
One lesson that stood out: having RLS policies isn't the same as proving your entire application enforces tenant isolation correctly.
A useful test plan needs to consider more than whether one user can read another user's rows. You also need to think about:
My hardening suite uses Vitest against a real PostgreSQL database rather than mocked database calls. It covers cross-tenant isolation and several other security and billing boundaries, although it doesn't prove every possible application access path is safe.
I'm building this into a production-oriented starter kit rather than asking every developer to assemble these foundations from scratch.
Project and demo: https://www.andrady.co/demo
I'd be interested to hear from other Supabase developers: what's the most easily overlooked failure mode you've encountered in a multi-tenant application?
All reactions