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?
Wendel shared insights from building a multi-tenant SaaS starter using Next.js and Supabase, highlighting four bugs found during testing. The discussion emphasizes the importance of robust RLS policies and tenant isolation. Wendel seeks feedback on overlooked failure modes in multi-tenant applications from other developers.
The ones I see most often:
org_members, but the insert policy on org_members is often just this: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.
Tenant or role taken from user_metadata. auth.jwt() -> 'user_metadata' can be changed by the user with supabase.auth.updateUser({ data }), so a policy that reads org or role from there can be bypassed. Use app_metadata or a membership lookup instead.
Cross-tenant foreign keys. A policy checks that tasks.org_id is yours, but tasks.project_id can point at another tenant's project. Check the parent too:
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()))
)
security_invoker = true, and SECURITY DEFINER functions in an exposed schema. New functions get EXECUTE for PUBLIC by default, so anon can call them unless you revoke it.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