Update: thanks to [@sunnatullah] for catching two gaps in the first version of this script. (1) Checks 2 and 3 could pass even if User B never got a profile row, so they proved nothing. (2) Owner-only RLS filters rows, not columns, so with a table-wide UPDATE grant a user can edit sensitive columns on their own row. Both are fixed below.
An RLS policy can look perfect and still leak. When AI helps write your migrations, a policy can also quietly go missing. The only way to know your database is locked down is to try to break it.
This post shows a two-user test you can run in a minute: create User A and User B, sign in as each, and check that A can’t read or edit B’s data. It works on any table. I’ll use a profiles table with owner-only policies as the example.
Why “it works in my app” proves nothing
When you test your own app, you are always logged in as the same user, looking at your own rows. Of course it works.…