How to generate and check Supabase RLS policies for Lovable and Bolt apps
A table can show "RLS enabled" in the Supabase dashboard and still leak rows, or break sign-in, if the policies are wrong. This isn't a security audit. It's just a practical check. Full disclosure, we run PrototypeVerdict. The generator and checker on this page run in the browser. They write standard Postgres and Supabase Row Level Security templates and look for text patterns. They don't connect…
Supabase's Row Level Security (RLS) policies can sometimes be misconfigured, leading to data leaks or functionality issues in applications like Lovable and Bolt. To verify these policies, the author built a browser-based generator and checker that writes standard Postgres and Supabase RLS templates and looks for specific text patterns. These tools do not connect to your database or call any external services, ensuring no data is saved.
The generator produces SQL for five different access patterns: private (owner only), public read with owner write, signed-in read with owner write, team or org rows via a membership table, and admin only. The checker runs in Node and tests these patterns on a local Postgres 17 database configured to mimic Supabase.
Key findings include:
1. If a table is created without enabling RLS, any role with a grant can read and write it.
2. Using USING (true) or WITH CHECK (true) on INSERT, UPDATE, DELETE, or FOR ALL allows every user the policy applies to change every row.
3. SELECT policies that query their own table cause Postgres to raise an infinite recursion error (42P17).
4. Policies that call non-security-definer functions reading the same table lead to stack depth limit errors (54001).
5. INSERT policies without WITH CHECK block all inserts, while those with USING are rejected by Postgres.
6. Policies without a TO clause apply to every role, including signed-out visitors, and cannot be trusted for authorization.
7. Security definer functions without set search_path or in the public schema are risky and could be hijacked.
8. Views without security_invoker = true can bypass RLS.
The best practice is to manually review your RLS policies, especially verifying that two separate accounts can't access each other's data. Before launch, sign in as two non-admin test users to confirm this. Also, ensure secret or service role keys aren't exposed in the browser or frontend code.
Rewritten by urgent.news; may contain errors — check the original.
Source: dev.to