Deutsch
Security wikiSupabase · Database

What is a Postgres policy (RLS policy)?

Also known as: RLS policy, row security policy, CREATE POLICY, Supabase policy

A Postgres policy is the rule row level security applies to each row. The parts of CREATE POLICY, how policies combine, and a tested query to review yours.

By Tim GeithnerPublished 2 min read

Short answer

A Postgres policy, or RLS policy, is a named rule attached to a table that decides which rows a role may see (USING) and which rows it may write (WITH CHECK) for a given command. Policies only take effect once row level security is enabled. Permissive policies are combined with OR, restrictive ones with AND, and a missing policy means no access.

Ask an AI about this page:ChatGPTClaude

On this page

A Postgres policy is a named rule on a table that tells row level security which rows a role may read or write for a given command. It is created with CREATE POLICY and does nothing until RLS is enabled on the table. Once RLS is on, Postgres denies everything that no policy allows.

The parts of a policy

One policy, every part named
create policy "Owners update their notes"
  on public.notes
  as permissive
  for update
  to authenticated
  using ((select auth.uid()) = user_id)
  with check ((select auth.uid()) = user_id);
PartWhat it decidesDefault
as permissive / as restrictiveCombined with OR (any passing policy is enough) or with AND (all must pass)permissive
for …Which command: select, insert, update, delete or allall
to …Which roles it applies to, in Supabase usually anon or authenticatedpublic (every role)
using (…)Which existing rows are visible or may be changed–
with check (…)Whether the new row may be writtenthe using expression

Rows hidden by using disappear silently. A row that fails with check raises an error.

Policies in an AI-built app

AI builders write policies in SQL migrations, and three patterns cause most problems:

  • using (true) on private data. It switches RLS on in name only; the Security Advisor flags it as lint 0024 (permissive_rls_policy).
  • An update policy without with check that has a different expression, or no owner check at all. A user can then rewrite user_id and move a row to another account.
  • An update policy without a select policy. Postgres needs the row to be visible to an update that reads columns. In our test, an update with only an update policy finished without error and changed nothing, a classic “saving does nothing” bug.

How to check your app

List every policy in the public schema and read each line out loud:

All policies in public
select tablename, policyname, permissive, roles, cmd, qual, with_check
from pg_policies
where schemaname = 'public'
order by tablename, policyname;

For each row ask: does roles make sense, is qual (the using part) tied to the caller through auth.uid() or a membership check, and does every UPDATE and INSERT have a with_check? Then test as two different users, as shown in How to test your RLS policies.

How to fix or prevent it

Write one policy per command, limit it to authenticated where visitors don’t need access, use (select auth.uid()) so Postgres evaluates it once per query, and index the column the policy filters on. A policy that says yes to everyone is fixed step by step in RLS policy USING (true).

Frequently asked questions

What is the difference between USING and WITH CHECK?

USING filters the existing rows a command may see or touch (select, update, delete). WITH CHECK validates the new or changed row being written (insert, update). An update policy usually needs both.

What happens if two policies apply to the same table?

Permissive policies, the default, are combined with OR: one passing policy is enough. Restrictive policies are combined with AND and must all pass, on top of at least one permissive policy.

Why does my update run without error but change nothing?

An update that reads columns, for example in its WHERE clause, also needs the row to be visible through a select policy. Without one, the update matches no rows. Add a select policy for the same users.

Sources

  1. 1.CREATE POLICY — PostgreSQL Documentation
  2. 2.Row Security Policies — PostgreSQL Documentation
  3. 3.Row Level Security — Supabase Docs
  4. 4.Performance and Security Advisors — Supabase Docs

Find this in your own app

ShipRely reads your repository (read-only), proves each finding with file and line, and gives you a fix prompt to paste into your AI builder.

Run a demo audit
  • Read-only access to your repository
  • Every finding with file and line
  • Fix prompts for Lovable, Cursor, Claude Code and Bolt