AppSec Architecture··6 min read·By Veer Bhanushali

Five Supabase and PostgreSQL Row-Level Security pitfalls caught in audits

Why tables with missing WITH CHECK clauses, security definer views, or self-referencing subquery policies silently leak multi-tenant rows.

Key takeaway

Audit every SQL migration for pg_tables.rowsecurity = true and bind both USING and WITH CHECK expressions cleanly to auth.uid().

Missing WITH CHECK allows cross-tenant INSERT

Many teams write a SELECT/UPDATE USING policy tied to auth.uid() while leaving INSERT unrestricted or reusing column names inside correlated joins where Postgres resolves the inner table column to itself.

Safe RLS policy template
ALTER TABLE invoices ENABLE ROW LEVEL SECURITY;
CREATE POLICY invoices_owner_rw ON invoices
  FOR ALL USING (owner_id = auth.uid())
  WITH CHECK (owner_id = auth.uid());