caelo

Caelo › Guides › RLS using (true)

What does USING (true) mean in a Supabase RLS policy, and is it safe?

By Arthi Arumugam, Irth Labs · Published · Updated

Short answerUSING (true) means the policy's condition always passes, so every row is visible to the roles it applies to. With no TO clause that includes anon, anyone holding your public key. That is right for public data such as published posts and wrong for profiles, orders or messages, which need a condition like (select auth.uid()) = user_id.

USING and WITH CHECK, in one table

PostgreSQL's docs say: "Existing table rows are checked against the expression specified in USING, while new rows that would be created via INSERT or UPDATE are checked against the expression specified in WITH CHECK."

CommandClause that appliesWhat (true) means there
SELECTUSINGThe role can read every row.
INSERTWITH CHECKThe role can insert any row with any values, including someone else's user_id.
UPDATEUSING and WITH CHECKThe role can change every row, and change it to anything.
DELETEUSINGThe role can delete every row.
ALLBothAll of the above. With no WITH CHECK, PostgreSQL reuses the USING expression for new rows.

The vulnerable pattern and the fix

These two policies are common in AI-generated migrations. Row level security is on, so the dashboard looks fine, but the policies grant everything.

Vulnerable: RLS enabled, but every row is open

alter table profiles enable row level security;

create policy "Enable read access for all users"
on profiles for select using (true); -- no TO clause, so anon can read every profile

create policy "Enable all for authenticated users"
on profiles for all to authenticated using (true) with check (true); -- any user edits anyone

Fixed: each user reads and edits only their own row

drop policy "Enable read access for all users" on profiles;
drop policy "Enable all for authenticated users" on profiles;

create policy "Users read their own profile"
on profiles for select to authenticated
using ((select auth.uid()) = user_id);

create policy "Users update their own profile"
on profiles for update to authenticated
using ((select auth.uid()) = user_id)
with check ((select auth.uid()) = user_id);

Drop the old policies first. Policies are permissive by default and PostgreSQL combines permissive policies with OR, so a leftover USING (true) cancels out your new narrow one.

Supabase recommends wrapping the call as (select auth.uid()) because it makes PostgreSQL run the function once per statement instead of once per row. Supabase also says to always name the role with a TO clause; without one, the policy applies to public, which includes anon.

When is USING (true) fine?

  • Read-only public content: published blog posts, a product catalog, public profiles you mean to show to everyone. Scope it to for select and only that table.
  • Policies to service_role. The service_role key bypasses row level security anyway, so these grant nothing new.
  • Never for INSERT, UPDATE or DELETE on user data, and never for for all.

Find every open policy in your project

  1. Run this in the SQL editor: select tablename, policyname, cmd, roles, qual, with_check from pg_policies where schemaname = 'public' and (qual = 'true' or with_check = 'true');
  2. For each row, decide whether that table is public content. If not, replace the policy with an owner check as above.
  3. Find tables with RLS switched off too: select tablename from pg_tables where schemaname = 'public' and not rowsecurity;
  4. Test as two different users, as our RLS guide shows. User B must not see or change user A's rows.

Check it automatically

Caelo reads the SQL migrations in your project, replays them in path order and flags policies whose condition is literally true on their final state (supabase.permissive-policy, and supabase.public-read-policy for select-only ones, which it reports as low because public reads are often intended). It skips restrictive policies and policies scoped only to service_role. It cannot see policies created by hand in the dashboard, so also run the pg_policies query above.

Part of the real report from the demo app in the Caelo README

- RLS policy lets the role read and write every row [needs review]
    supabase/migrations/001_init.sql:3  (supabase.permissive-policy)
    value: profiles: for all to authenticated, condition is (true)
    why: The condition is literally true, so any "authenticated" client can read, change and delete every row in profiles, not only its own.

1. Run the free local check

npx caelo .

Caelo is a free, open source (MIT) command line tool and MCP server from Irth Labs that checks the files of an AI-built app for exposed API keys, Supabase and Firebase misconfigurations and .env files with real values. It runs on your machine, uploads nothing and uses no AI model. Each finding comes with a plain-English fix.

2. Act on a finding

Follow the fix in your report and run Caelo again. If Git could commit an untracked file containing secrets, preview a US$19 quick fix for that file.

For findings that need an engineer, Irth Labs offers a US$490 App Health Check. You receive a written report within 48 hours and a fixed repair quote. The fee counts toward the repair if you proceed.

Book the App Health Check See repair services

Questions

Is "to authenticated using (true)" safe?

No, for anything per-user. Anyone can sign up, so authenticated means anyone with an account. They can read or change every row the policy covers.

What happens if RLS is on and there are no policies?

Supabase says no data is accessible through the API with a publishable key until you create policies. That is safe, and it is why AI tools add USING (true) to make errors go away.

Does service_role respect these policies?

No. The service_role and secret keys bypass row level security entirely, which is why they must stay on the server.

Should I use auth.uid() or auth.jwt()->>'sub'?

Both return the signed-in user's ID. Supabase's RLS docs use (select auth.uid()); its Storage examples use (select auth.jwt()->>'sub'). Wrap either in select so it runs once per statement.

Sources