← All posts
·updated ·28 min read·GuardLayer·how we write

Supabase Row Level Security (RLS): Complete Guide

#supabase#rls#postgres#security

Row Level Security (RLS) is the Postgres feature that decides which rows each Supabase API request may read or change. Any table in public that anon or authenticated holds a grant on is reachable with the publishable (anon) key from your browser bundle, so enable RLS on every such table (alter table ... enable row level security) and write one policy per command, scoped with to authenticated and (select auth.uid()) = user_id. A table with RLS off, or a policy of using (true), is effectively public.

Supabase is Postgres with an auto-generated REST, GraphQL and Realtime API in front of it. The key that API accepts from browsers is public by design: it ships in every bundle you deploy. Row Level Security is the gate that decides which rows each request may see. Get it right and Supabase is secure by default. Get it wrong and you've published your database.

This guide covers the whole mechanism: the request path, grants versus policies, the policy grammar, the patterns that hold, what bypasses RLS anyway, and how to verify it. Each subtopic links to a focused deep-dive when you need the long version.

This isn't hypothetical: CVE-2025-48757. In May 2025, researcher Matt Palmer disclosed 303 endpoints across 170 production apps with Supabase tables readable by anyone holding the public anon key (emails, addresses, even API keys) because RLS wasn't protecting them. The official record scores it CVSS 9.3. The fix was one line per table. Full breakdown: the Lovable RLS vulnerability.

It isn't rare in newer projects either. In our November 2026 study of 844 public Supabase projects, 17% created at least one table without RLS, and 42% had a policy that let any signed-in user read or change every row.

What is Row Level Security in Supabase?

Row Level Security is a Postgres feature that filters every query on a table through policies you write, so a request only sees and changes the rows a policy allows. Rows that match no allowing policy are invisible, as if they didn't exist. With RLS enabled and no policies, the table denies everything. The PostgreSQL manual is blunt: "If row-level security is enabled for a table, but no applicable policies exist, a 'default deny' policy is assumed, so that no rows will be visible or updatable." With RLS disabled, Postgres skips the check entirely.

What happens between .select() and a row coming back

Almost every fact in the rest of this guide falls out of this sequence:

  1. Your client sends the request with an API key (publishable, or the legacy anon key) and, if a user is signed in, an Authorization: Bearer <access_token> header.
  2. PostgREST, the API layer, connects to Postgres as a role called authenticator. Supabase's roles docs describe it as a role that "has very limited access, and is used to validate a JWT and then 'change into' another role determined by the JWT verification."
  3. PostgREST verifies the JWT and switches role for the transaction: anon when there's no user token, authenticated when there is (strictly, whatever the token's role claim names).
  4. PostgREST puts the token's payload into the transaction-local setting request.jwt.claims. auth.uid() is a small SQL function that reads sub out of those claims and casts it to uuid.
  5. Postgres runs your query as that role, and AND-s your policy's USING expression onto the query as an implicit predicate, evaluated as the table is scanned.

Step 5 is the mental model that matters: a policy is a row filter Postgres injects into your query, not a gate that runs once in front of it. That explains why auth.uid() can be NULL (no JWT reached step 4), why the SQL editor lies (it skips steps 2 to 4), why an ORM walks straight past your policies (it skips PostgREST entirely), and why an unindexed policy column is slow (the predicate runs per row).

Two consequences trip up everyone. Enabling RLS with no policy locks the table: your app suddenly gets empty results, which is RLS working before you've granted the access you intended. And the secret / service_role key ignores RLS completely: it's for trusted server code, and if it ever reaches the browser or an AI agent, every policy you wrote is bypassed at once.

Is RLS enabled by default in Supabase?

Only for tables you create in the Dashboard. Supabase's tables docs: "The Table Editor enables row level security for you when you create a table in the Dashboard." Tables created with SQL (the SQL Editor, a migration, an ORM schema push) start with RLS off: "When you create a table with SQL, enable it yourself."

To make it automatic, Supabase documents an event trigger named ensure_rls. It fires on ddl_command_end for CREATE TABLE, CREATE TABLE AS and SELECT INTO, and runs enable row level security on each new table in public. It "applies to tables created after the trigger is installed. Existing tables still need RLS enabled manually."

What "RLS off" costs you now depends on grants:

  • Tables that existed before October 30, 2026 kept their automatic Data API grants. With RLS off, they're readable with your publishable key today. The Table Editor's red Unrestricted badge marks exactly this state.
  • Tables created since then get no grants at all (new projects since May 30, 2026). A new table with RLS off is unreachable until someone grants it, and that grant is the moment it goes public.

If someone disabled RLS to make a query work, or a migration created a table without it, turn it back on and write the policy the query was missing.

Grants or policies: which lock is actually stopping my query?

There are two locks on every Supabase table, and people burn hours writing policies to fix a grant problem. Supabase's RLS guide puts it in one line: "Grants decide whether a role can run an operation on the table at all. Policies decide which rows that operation applies to."

Postgres checks access in a fixed order, and RLS is dead last:

  1. Database CONNECT
  2. Schema USAGE
  3. Table privilege (SELECT / INSERT / UPDATE / DELETE)
  4. Column and sequence privileges
  5. Row Level Security policies

If layer 3 fails, Postgres never reaches layer 5 and no policy ever executes. You get 42501: permission denied for table, and adding policies changes nothing. That path is walked step by step in permission denied for table (42501).

This is now the normal state of a new table. Supabase's Data API change (discussion #45329) reached every existing project on October 30, 2026: new tables in public no longer get automatic select, insert, update and delete grants for anon, authenticated and service_role. Views follow the same default, so a new view needs its own grant too. Existing tables "keep their current grants and stay reachable." RLS itself is unchanged. Migration path: new tables need GRANTs.

The reverse trap is just as common: adding policies doesn't take grants back. If anon already holds INSERT on an older table, a permissive policy is the only thing preventing anonymous writes. Close both locks explicitly in the same migration: enable RLS, revoke everything, grant back only the verbs you need.

alter table public.reports enable row level security;

revoke all on table public.reports from anon, authenticated;

grant select, insert, update, delete on table public.reports to authenticated;

Who is anon, authenticated, and service_role?

TO in a policy names a Postgres role, not a concept. These are the ones you'll meet:

RoleWhat it isDoes RLS apply?
anonUnauthenticated access. PostgREST uses it when no user is signed in.Yes
authenticatedThe role PostgREST switches into when the request carries a valid user JWT.Yes
authenticatorPostgREST's login role. It validates the JWT, then changes into one of the above.Never queries your tables as itself
service_roleElevated access, behind the secret key (sb_secret_…) or the legacy service_role JWT. Created with BYPASSRLS.No
postgresThe default admin role. The SQL editor, and what most direct connections and ORMs log in as.No: it owns your tables and holds BYPASSRLS

Two rules follow. First, always name the role with TO. Omit it and Postgres defaults the policy to PUBLIC, "which will apply the policy to all roles," so your predicate also runs for anon. Second, to authenticated is the right replacement for a using (auth.role() = 'authenticated') predicate: the planner checks it once instead of per row.

Users created through anonymous sign-in also arrive as authenticated, so to authenticated alone does not mean "a real account". See anonymous sign-ins.

Publishable and secret keys

Supabase's new API keys map onto the same roles. A publishable key (sb_publishable_…) runs as anon, or as authenticated when the request carries a signed-in user's token. Supabase calls it "Safe to expose online," and it is, because RLS constrains it. A secret key (sb_secret_…) runs as service_role, and "bypasses every Row Level Security policy you have." Supabase rejects a secret key sent from a browser with a 401, matching on the User-Agent header. The legacy anon and service_role JWT keys keep working alongside the new ones, and Supabase is "deprecating the anon and service_role keys in early 2027." Migration details: publishable vs secret keys.

What does a Supabase RLS policy look like?

Turn RLS on for the table first. This is the one line that separates a private table from a public one:

alter table public.orders enable row level security;

Then write policies. Here is the complete grammar, from the PostgreSQL manual:

CREATE POLICY name ON table_name
    [ AS { PERMISSIVE | RESTRICTIVE } ]
    [ FOR { ALL | SELECT | INSERT | UPDATE | DELETE } ]
    [ TO { role_name | PUBLIC | CURRENT_ROLE | CURRENT_USER | SESSION_USER } [, ...] ]
    [ USING ( using_expression ) ]
    [ WITH CHECK ( check_expression ) ]

Every bracketed clause is optional, and two defaults are silent and dangerous:

  • AS PERMISSIVE is the default. Permissive policies OR together, so every policy you add can only widen access.
  • TO PUBLIC is the default. A policy with no TO clause applies to every role, anon included.

The manual: "The default for newly created policies is that they apply for all commands and roles, unless otherwise specified." Write the clauses out, every time.

USING or WITH CHECK: which clause does each command need?

Most RLS bugs hide behind this table. USING filters rows that already exist; WITH CHECK validates rows being written.

CommandUSINGWITH CHECKWhat the clauses decide
SELECTYesNoUSING = which rows are returned.
INSERTNot allowedYesNothing exists to filter; WITH CHECK decides if the new row is allowed.
UPDATEYesYesUSING = which rows may be targeted. WITH CHECK = what the row may become.
DELETEYesNot allowedUSING = which rows may be deleted. No new row to validate.
ALLYesYesAll four commands with the same predicate(s).

Postgres rejects the two impossible combinations at create policy time: "An INSERT policy cannot have a USING expression, as it only applies in cases where records are being added to the relation," and "A DELETE policy cannot have a WITH CHECK expression... so that there is no new row to check."

Three consequences explain most "my policy doesn't work" reports.

Reads fail silently; writes throw. When a USING expression returns false or null, "the row is not visible. Typically, no error occurs when a row is not visible." When a WITH CHECK expression returns false or null, "an error occurs." So an empty result points at USING; 42501 new row violates row-level security policy points at WITH CHECK or a missing grant. Walkthrough: new row violates row-level security policy.

SELECT rights leak into writes. An UPDATE that reads columns of the row it changes, "in a WHERE clause or a RETURNING clause, or in an expression on the right hand side of the SET clause," also has the SELECT policies applied. Any write with RETURNING needs the new rows to "satisfy the relation's SELECT policies." That is what supabase.from('orders').insert(row).select() compiles to. A plain .insert() succeeding while .insert().select() fails is a missing SELECT policy, not a bug.

Omitting WITH CHECK on UPDATE or ALL reuses USING. "If no WITH CHECK expression is defined, then the USING expression will be used both to determine which rows are visible... and which new rows will be allowed to be added." So a for all using (...) policy does check inserts. The real footgun is appending with check (true) to make a write work: now a user can rewrite user_id and hand a row to another account. That's the UPDATE WITH CHECK (true) trap.

How do I write a correct first policy set?

One migration, all four commands, every policy role-scoped, every predicate wrapped for the planner:

alter table public.orders enable row level security;

-- Lock 1: grants. New tables get none since Oct 30, 2026; older ones get
-- the defaults, so revoke first either way.
revoke all on table public.orders from anon, authenticated;
grant select, insert, update, delete on table public.orders to authenticated;

-- Lock 2: policies. One per command, each scoped to the caller.
create policy "orders_select_own"
  on public.orders for select
  to authenticated
  using ( (select auth.uid()) = user_id );

create policy "orders_insert_own"
  on public.orders for insert
  to authenticated
  with check ( (select auth.uid()) = user_id );

create policy "orders_update_own"
  on public.orders for update
  to authenticated
  using ( (select auth.uid()) = user_id )
  with check ( (select auth.uid()) = user_id );

create policy "orders_delete_own"
  on public.orders for delete
  to authenticated
  using ( (select auth.uid()) = user_id );

-- Every column a policy filters on needs an index.
create index orders_user_id_idx on public.orders (user_id);

Three details do real work. to authenticated stops the predicate from being evaluated for anon at all. (select auth.uid()), rather than bare auth.uid(), is an uncorrelated subquery, so Postgres plans it as an InitPlan and evaluates it once per statement instead of once per row. And the update policy carries both clauses, so a user can neither update someone else's row nor reassign their own to another user_id.

Here's the opposite: a migration that creates a table and never enables RLS. This is live GuardLayer engine output on that file, not a mockup:

guardlayer scan · supabase/migrations/20260701_orders.sqlLive engine output
Passed with warnings
92/100 · A
  • Warningsupabase/migrations/20260701_orders.sql:2

    Table created without enabling RLS

    Add ALTER TABLE <table> ENABLE ROW LEVEL SECURITY; plus access policies right after the CREATE TABLE, and grant anon / authenticated only the privileges the app needs, per table, after RLS is on. A later migration in the same scan that enables RLS (or drops the table) clears this warning. It still shows when the enable is in a file whose run order is unknown (a schema.sql with no version number) or not part of this scan (a pull-request scan sees only the files the PR changes).

The rule fires on the create table line because nothing in the file enables RLS on orders. On a project that still hands out default grants, that table is readable and writable with the anon key the moment the migration runs. On a new table since October 30, it's a latent leak: the first grant ... to anon someone adds to fix a 42501 makes it public.

How do multiple policies combine?

Permissive policies are combined "using the Boolean 'OR' operator." Restrictive policies are combined "using the Boolean 'AND' operator." With both present, "a record is only accessible if at least one of the permissive policies passes, in addition to all the restrictive policies."

Read that as an operational rule: adding a permissive policy can only ever grant more access. A perfect using ((select auth.uid()) = user_id) policy beside a leftover using (true) policy is worthless: the OR is true for every row. "We have RLS policies" is not the same as "our table is protected." The Supabase advisor's 0006_multiple_permissive_policies is a performance lint, but it's also a correctness smell.

When a condition must hold regardless of other policies, use as restrictive. Supabase's own example is a second-factor gate on the JWT's aal claim:

-- Nobody reads or writes this table without a second factor,
-- no matter how many permissive policies exist.
create policy "orders_require_mfa"
  on public.orders
  as restrictive
  for all
  to authenticated
  using ( (select auth.jwt() ->> 'aal') = 'aal2' );

Restrictive policies never grant access on their own. With no permissive policy to pass, the default deny still applies. Pair one with the permissive set above.

Which RLS pattern fits my table?

Most tables are one of six shapes. Pick the shape first, then write the four policies around it.

1. Own rows. The default, shown above: (select auth.uid()) = user_id. The column must be uuid, or the comparison silently never matches.

2. Rows owned through a parent. The child table has no user_id; ownership lives one hop away.

create policy "line_items_select_own"
  on public.line_items for select
  to authenticated
  using (
    exists (
      select 1 from public.invoices i
      where i.id = line_items.invoice_id
        and i.user_id = (select auth.uid())
    )
  );

3. Org / tenant membership.

create policy "invoices_select_tenant"
  on public.invoices for select
  to authenticated
  using (
    tenant_id in (
      select tenant_id from public.memberships
      where user_id = (select auth.uid())
    )
  );

The where user_id = (select auth.uid()) is the entire security property. Drop it and the subquery returns every tenant id, the predicate is true for every row, and you have cross-tenant reads that look correct in review. Full treatment, including the JWT-claim alternative and its staleness problem: Supabase multi-tenant RLS.

4. Public read-only. RLS stays on; the openness is scoped to select only.

create policy "posts_public_read"
  on public.posts for select
  to anon, authenticated
  using ( true );

This is the one legitimate using (true): a select-only policy on data you'd print on a billboard. Never pair it with with check (true), and never write it for all. Why it goes wrong everywhere else: the using (true) trap.

5. Role or claim gate. Read authorization claims from app_metadata, never user_metadata:

create policy "orders_admin_read"
  on public.orders for select
  to authenticated
  using ( (select auth.jwt() -> 'app_metadata' ->> 'role') = 'admin' );

Supabase's RLS guide is unambiguous: raw_user_meta_data "can be updated by the authenticated user" and "is not a good place to store authorization data"; raw_app_meta_data "cannot be updated by the user." A role in user_metadata is self-service admin: see app_metadata vs user_metadata. Don't look the role up in auth.users from a policy either. anon and authenticated have no privileges on that table, so the policy fails with permission denied for table users, and granting access exposes every user's email. The safe options are in permission denied for schema auth.

6. A lookup that would recurse. A policy that queries its own table raises 42P17 infinite recursion detected in policy. The classic case is a team_members policy whose subquery selects from team_members. (A policy on orders that reads a separate admins table does not recurse.) Break the loop with a SECURITY DEFINER helper in a schema PostgREST doesn't expose:

create schema if not exists private;

create or replace function private.is_team_member(_team_id uuid)
returns boolean
language sql
stable
security definer
set search_path = ''
as $$
  select exists (
    select 1 from public.team_members m
    where m.team_id = _team_id
      and m.user_id = (select auth.uid())
  );
$$;

-- EXECUTE defaults to PUBLIC. Take it back.
revoke all on function private.is_team_member(uuid) from public, anon;
grant execute on function private.is_team_member(uuid) to authenticated;

create policy "team_members_select"
  on public.team_members for select
  to authenticated
  using ( private.is_team_member(team_id) );

The function runs with its owner's rights, and that owner owns team_members, so the read inside it bypasses that table's RLS and the policy is never re-entered. set search_path = '' stops a caller-controlled schema from shadowing an unqualified name inside a function running with the owner's privileges. Details: infinite recursion in RLS and SECURITY DEFINER search_path.

The mistakes that leak a Supabase table

Almost every Supabase data leak is one of these:

  • RLS off on a table that has grants. The table is public. Usually it was never enabled, or it was disabled to "fix" a query that was blocked because no policy granted access.
  • The using (true) trap. A policy that matches every row. RLS is "on," the dashboard looks fine, and the table is still world-readable.
  • A policy that isn't user-scoped. using (auth.role() = 'authenticated') lets any signed-in user read everyone's rows. Scope to auth.uid() = user_id.
  • A role read from user_metadata. That field is user-writable, so a role stored there rather than in app_metadata is an escalation any account can perform on itself.
  • A grant written to silence a 42501. Since October 30, every new table fails with permission denied until it's granted. grant select on ... to anon on a table with RLS off turns that error into a leak. Grant to the role that needs it, with RLS and policies in the same migration.

What bypasses RLS even when your policies are correct?

Perfect policies protect nothing if the query never reaches them as a constrained role. The ways a request walks past RLS:

  • The secret / service_role key. It authorizes as service_role, which bypasses RLS by design. Server-side only: an exposed service_role key voids every policy at once.
  • The postgres role. Prisma, Drizzle, psql and any raw DATABASE_URL connection log in as postgres, which owns your tables and holds BYPASSRLS. Your policies aren't in the code path: does Prisma respect Supabase RLS?
  • Table owners generally. "Table owners normally bypass row security as well, though a table owner can choose to be subject to row security with ALTER TABLE ... FORCE ROW LEVEL SECURITY." FORCE closes the owner hole and does nothing to a BYPASSRLS role: "superusers and roles with the BYPASSRLS attribute always bypass the row security system."
  • Views without security_invoker. Supabase: "Views bypass RLS by default because they are usually created with the postgres user." On Postgres 15+, alter view <name> set (security_invoker = on); makes the view obey its tables' policies. On older versions, revoke access from anon and authenticated or move the view to an unexposed schema. See SECURITY DEFINER views. Since October 30, a new view also needs its own grant, and permission denied for view is exactly where people add one. Set security_invoker first, or the grant hands every caller every row.
  • SECURITY DEFINER functions. They run with the definer's privileges by design, and EXECUTE is granted to PUBLIC by default. Pin the search_path and revoke EXECUTE from roles that shouldn't call them: SECURITY DEFINER search_path.
  • Edge Functions holding an elevated key. An unauthenticated Edge Function with the secret key is an open door around every policy.
  • The SQL editor. It runs as postgres, so a broken policy and a correct one look identical there. It is never a test.

What does RLS not protect?

  • Columns. RLS filters rows; every column of a visible row comes back. Column privileges are a separate mechanism, and on Supabase's default grants a column-only GRANT or REVOKE does nothing. Postgres lets a role use a column "if they hold that privilege for either the specific column or its whole table" (GRANT docs), and older tables carry a table-level SELECT for anon and authenticated. Take the table privilege away first, then grant the columns:

    revoke select on public.posts from anon, authenticated;
    grant select (id, title) on public.posts to authenticated;
    

    After that, select('*') fails for that role with a permission error, so name the columns: .select('id, title'). A view with security_invoker = on that omits the column is the other option, but it only hides anything if the role can't also read the base table, so the same revoke applies. Full walkthrough: Supabase column-level security.

  • Storage. Files are rows in storage.objects, which has its own RLS. Supabase: "By default Storage does not allow any uploads to buckets without RLS policies." Policies there filter on bucket_id and on the path via (storage.foldername(name))[1]: see new row violates RLS on Storage upload. A public bucket skips that check for reads: public storage bucket leak.

  • Realtime, implicitly. Postgres Changes are authorized against your SELECT policies, so an RLS mistake shows up as silence on a subscription, not an error.

  • Direct database connections. Anything that doesn't go through PostgREST never gets the role switch or request.jwt.claims.

  • Existence, under constraints. "Referential integrity checks, such as unique or primary key constraints and foreign key references, always bypass row security." A unique-violation error can confirm that a row you can't see exists. The manual calls this a "covert channel."

  • Rate limiting and business logic. RLS answers "may this role touch this row," not "should this happen."

The strongest control isn't a policy at all: a table PostgREST can't reach. Keep sensitive tables out of the exposed schema (a private schema reached only through server code or a SECURITY DEFINER RPC) and there is no policy to get wrong. That moves the check into your functions, with trade-offs covered in RLS with no policies.

Why does my query return nothing after enabling RLS?

Work down this list in order. Each branch has a full walkthrough.

  1. No policy exists for that command. RLS default-denies, and Postgres returns [] without an error. select * from pg_policies where tablename = 'orders'; and check cmd covers the verb you're running: select returns an empty array.
  2. auth.uid() is NULL because no JWT reached Postgres: you're in the SQL editor, or your SSR client never forwarded the session. NULL = user_id is never true, so every row is filtered out. See auth.uid() returns NULL and getSession vs getUser.
  3. Type mismatch. auth.uid() returns uuid; compared against a text column it never matches: auth.uid() = user_id returns false.
  4. .single() on zero visible rows returns PGRST116, which reads like a missing row but is usually a policy: PGRST116 no rows returned.

And when it throws instead of going quiet:

  1. 42501 permission denied for table: a missing grant, the default for every new table since October 30. No policy ever ran: permission denied for table.
  2. 42501 new row violates row-level security policy: an insert or update failing WITH CHECK: the 42501 write path.
  3. permission denied for table users: a policy, view or function reads auth.users as the caller: permission denied for schema auth.
  4. 42P17 infinite recursion: a policy queries its own table: infinite recursion in RLS.

The rule that routes you fastest: reads go quiet, writes throw. Empty results mean USING or a NULL auth.uid(). A 42501 means WITH CHECK or a grant.

How do I test my RLS policies?

Not in the SQL editor: it connects as postgres, which bypasses RLS, so a broken policy and a correct one both "pass." Run the query as the request role with claims attached. The smallest useful version:

begin;
  set local role authenticated;
  set local request.jwt.claims to
    '{"sub":"11111111-1111-1111-1111-111111111111","role":"authenticated"}';

  -- Should return ONLY that user's rows. If it returns everyone's, the policy is wrong.
  select count(*) from public.orders;

  -- And the unauthenticated case must return zero.
  -- Clear the claims too: auth.uid() reads sub from them, so switching
  -- the role alone would still run this query as the user above.
  set local role anon;
  set local request.jwt.claims to '{"role":"anon"}';
  select count(*) from public.orders;
rollback;

set local scopes both changes to the transaction, and the rollback keeps your session clean. Turn this into assertions with pgTAP in CI, plus a client-SDK test as a real signed-in user: how to test your Supabase RLS policies.

Why are my RLS queries slow?

Because the predicate is evaluated as the table is scanned, conceptually once per candidate row. Four fixes, in order of impact:

  1. Index every column a policy filters on. In Supabase's published 100K-row benchmark, an index on user_id took a query from 171 ms to under 0.1 ms.
  2. Wrap function calls in a sub-select: (select auth.uid()) = user_id. Postgres runs it once per statement (179 ms to 9 ms in the same benchmark). Only valid for expressions that don't depend on the row.
  3. Add to authenticated so the policy is skipped entirely for roles that can never match.
  4. Mirror the predicate in your client query (.eq('user_id', user.id)), so the planner can use the index directly.

Also restructure membership joins so the subquery filters on the fixed user (tenant_id in (select tenant_id from memberships where user_id = (select auth.uid()))) rather than correlating against each row. Measurements and the EXPLAIN ANALYZE workflow: why Supabase RLS queries are slow.

How do I check if my Supabase RLS is correct?

A fast audit you can run today:

-- Tables in `public` with RLS turned OFF. Each one with a grant is exposed:
select relname
from pg_class
where relnamespace = 'public'::regnamespace
  and relkind in ('r', 'p')
  and relrowsecurity = false;

Then the four checks that catch tables where RLS is on and still wrong:

-- 1. RLS enabled but ZERO policies: denies everything (fails closed, usually unintended).
select c.relname
from pg_class c
where c.relnamespace = 'public'::regnamespace
  and c.relkind in ('r', 'p')
  and c.relrowsecurity
  and not exists (
    select 1 from pg_policies p
    where p.schemaname = 'public' and p.tablename = c.relname
  );

-- 2. Constant-true predicates: the `using (true)` trap, read or write.
select tablename, policyname, cmd, roles, qual, with_check
from pg_policies
where schemaname = 'public'
  and (qual = 'true' or with_check = 'true');

-- 3. Policies with no TO clause: they apply to PUBLIC, which includes anon.
select tablename, policyname, cmd, roles
from pg_policies
where schemaname = 'public'
  and roles::text[] = '{public}';

-- 4. Write privileges handed to anon.
select table_name, privilege_type
from information_schema.role_table_grants
where table_schema = 'public'
  and grantee = 'anon'
  and privilege_type in ('INSERT', 'UPDATE', 'DELETE');

Supabase's Security Advisor runs its own lints. Map each warning to the section above rather than guessing:

LintMeansFix in this guide
0013_rls_disabled_in_publicPublic table, no RLS"How do I write a correct first policy set?"
0023_sensitive_columns_exposedNo RLS, and column names look sensitiveSame, then "What does RLS not protect?"
0008_rls_enabled_no_policyRLS on, zero policiesAdd the four policies
0007_policy_exists_rls_disabledPolicies written, RLS never enabledalter table ... enable row level security
0024_permissive_rls_policyAlways-true condition"Which RLS pattern fits my table?" (pattern 4)
0015_rls_references_user_metadataPolicy reads user-editable dataPattern 5: use app_metadata
0010_security_definer_viewView bypasses RLS"What bypasses RLS…"
0003_auth_rls_initplanPredicate re-evaluated per row"Why are my RLS queries slow?"
0006_multiple_permissive_policiesPolicies OR-ing together"How do multiple policies combine?"

GuardLayer covers both halves. In the repo, it reads the SQL in your migrations and flags RLS-off tables (supabase/rls-missing-on-table), using (true) policies (supabase/policy-using-true) and policies whose predicate never references the caller (supabase/policy-no-user-scope), with the SQL fix inline. For a one-off, paste a migration into the Supabase security checker, which runs the same rules and never stores your SQL. Both are static, per-file analysis of what your migrations say, and the CI check posts a result rather than blocking a merge (that needs branch protection). For the live database, Live check connects read-only and lists the tables anon can read without RLS and the views that skip RLS, with the SQL fix for each.

The RLS checklist for every table you ship

  1. enable row level security is in the same migration as create table.
  2. Grants are explicit: grant only the verbs you need, to the role that needs them. On older tables, revoke the defaults from anon and authenticated first.
  3. A separate policy for select, insert, update and delete, not one for all.
  4. Every policy carries a TO clause naming a real role.
  5. Every predicate references (select auth.uid()), or a subquery that filters on it.
  6. Every write policy has a WITH CHECK, and update has both clauses.
  7. Every column a policy filters on is indexed.
  8. Authorization claims come from app_metadata, never user_metadata or auth.users.
  9. Every view in an exposed schema has security_invoker = on.
  10. Verified as anon and as a real signed-in user, not in the SQL editor.
  11. The secret / service_role key exists only in server code, and nothing in the app connects as postgres.

FAQ

Is RLS enabled by default in Supabase? Only for tables created in the Dashboard's Table Editor. Tables created with SQL, migrations or an ORM start with RLS off unless you've installed Supabase's ensure_rls event trigger. Since October 30, 2026, new tables also get no Data API grants, so they're unreachable until granted. Enable RLS before you grant.

Do I need RLS if my app has a login? Yes. Auth proves who is calling; RLS decides which rows they may touch. Without RLS, any signed-in user, or anyone with the publishable key if anon has a grant, can query every row through the API and skip your app code entirely.

Is it safe that my publishable (anon) key is public? Yes, as long as RLS is enabled and your policies are correct. The publishable key is designed to be public; RLS is what constrains it. The secret / service_role key is the one that must never be public.

Can RLS hide a column? No. RLS filters rows only. To hide a column, revoke the table-level SELECT (revoke select on public.posts from anon, authenticated;), then grant the allowed columns (grant select (id, title) on public.posts to authenticated;) and select them by name. A column grant on its own does nothing while the table grant exists.

Why does my policy work in the SQL editor but not in my app? The SQL editor connects as postgres, which bypasses RLS and carries no JWT, so your policy is never enforced there and auth.uid() is NULL. Test with set local role authenticated and request.jwt.claims inside a transaction, or through the client SDK as a real user.

Does force row level security stop the service_role key? No. FORCE subjects the table owner to policies. Roles with BYPASSRLS, which service_role and postgres both have, always bypass row security. The control is the connection role, not the table setting.

live check · read-only

See which of your Supabase tables anyone can read, free

Connect your Supabase project read-only. GuardLayer checks RLS, policies, grants and functions as they are right now, and gives you the SQL to fix each problem. It never reads your rows and can't change anything.

Check my Supabase project

Prefer to check code instead? Scan your repo, no signup.

Keep reading