I built a client portal with Next.js, Supabase and Stripe, mostly with AI help. Each client company sees only its own projects, payments and files.
I had RLS tests, and every one of them passed.
Then I reviewed it the way I would review a client's app. I found six problems. None of them showed up in the tests.
This post is what I checked, what I found, and the queries you can run on your own project.
Why passing tests is not enough
RLS tests check the cases you thought of. "Client A can't read client B's projects" is a good test. But RLS is only one layer. Three other things decide what a user can do:
Grants : what each role is allowed to do at all, before RLS runs
Functions : some run with the owner's rights and skip RLS
Server code : anything that uses the service_role key skips RLS completely
My tests covered RLS well. The problems were in the other three.
Part 1: Look at the live database, not just the policies
1.…