Engineering

Row Level Security (RLS)

Row Level Security (RLS) is a PostgreSQL feature that controls which rows in a database table a user can read, insert, update, or delete — enforced at the database level, not the application layer.

In depth

RLS is the most important security primitive for multi-tenant SaaS applications. Instead of filtering data in your API routes (which can be bypassed by bugs), RLS enforces data isolation at the database level.

How RLS works in Supabase: 1. Enable RLS on a table 2. Write policies that define who can access which rows 3. Supabase automatically filters rows based on the authenticated user's JWT

Example policy: 'Users can only read their own todos' ```sql CREATE POLICY 'user_todos' ON todos FOR SELECT USING (auth.uid() = user_id); ```

Without RLS, a bug in your API could accidentally expose one tenant's data to another. With RLS, even if your API has a bug, the database refuses to return unauthorized rows.

RLS is non-negotiable for any multi-tenant SaaS storing sensitive data.

Real example

A project management SaaS has 1,000 company workspaces. With RLS, a query for 'all projects' by user from Company A automatically returns only Company A's projects — even if the developer forgot to add a WHERE clause in the application code.

Tools & calculators

Related terms

Ready to build your product?

Fixed price. 21-day delivery. Senior team.

Get a free scoping call →

Browse the glossary