PatchPaste · Guides

Last updated 13 November 2026

Supabase "Security Definer View" error: why your view ignores RLS, and the fix

Supabase Security Advisor shows a red ERROR: Security Definer View, or "View bypasses row-level security". You turned RLS on for your tables, so how can a view leak? Here is what is going on, the one-line fix, and how to test it before you trust it.

Short answer: a view in public runs with its creator's permissions by default, so it skips the RLS policies on the tables it reads from. Anyone who can query the view through your API can get rows your policies were meant to hide. Fix: alter view public.your_view set (security_invoker = true); then make sure the base tables have policies scoped to the caller. If the view reads auth.users, replace it with a profiles table instead.

What the lint says

In Supabase's Advisors docs this is 0010_security_definer_view, level ERROR: "A view in the public schema runs with elevated privileges and ignores Row-Level Security, which could expose more data through the API than intended." The docs explain that Postgres' default for views uses the permissions of the view's creator, and that views created through Supabase Studio or the CLI are typically created by a role that can bypass RLS.

Because the view is in public, it is part of your project's API, just like a table. Your app may only ever read it after sign-in, but the API does not know that.

Why it is easy to miss

The fix

Postgres 15 added the security_invoker option for views. The Postgres docs say it "causes the underlying base relations to be checked against the privileges of the user of the view rather than the view owner", and that with it set, "the policies and permissions of the invoking user are used instead". You can set it on an existing view with ALTER VIEW:

alter view public.your_view set (security_invoker = true);

Or, when you recreate it (the form Supabase's docs show):

create or replace view public.your_view
  with (security_invoker=on)
as
select id, title, user_id
from public.your_table;

After that, whoever queries the view only sees the rows their own RLS policies allow.

If the view reads auth.users

Supabase has a separate ERROR for this: 0002_auth_users_exposed, "User data exposed through a view". Its docs say a public security definer view referencing auth.users exposes all user records to all API users. Supabase's recommended fix is a public.profiles table with only the columns your app needs, filled by a trigger on sign-up, with its own RLS. Don't just add security_invoker to a view of auth.users and hope.

When the fix "breaks" the app

Switching to security invoker often makes the view return an empty list. That is the view now obeying your rules. Usually a base table has RLS on but no policy for the reader (Supabase lint 0008_rls_enabled_no_policy: "no data can be read or written through the API"). Add a scoped policy on the base table. See Supabase select returns an empty array.

Fixes to refuse

Check it worked

  1. Re-run Security Advisor. The 0010 error should be gone for that view.
  2. Logged out: query the view with only the anon key (for example from a private browser window with your app signed out, or with curl against /rest/v1/your_view). It should return nothing private.
  3. As a second test user: sign in as another account and confirm you see only that account's rows.
  4. From outside: scan the live URL to confirm common tables don't answer to your public key and no secret key is in your JavaScript. PatchPaste won't list your views, so steps 1 to 3 are the real test for this one.

A prompt to paste into Lovable

Supabase Security Advisor reports "Security Definer View" (0010_security_definer_view). Do not disable RLS on any table and do not add using (true) policies. 1) List every view in the public schema and what tables it reads. 2) For each view, tell me whether logged-out visitors or all signed-in users should be able to read it. 3) For views that should respect RLS, write a migration that runs: alter view public.<view_name> set (security_invoker = true); 4) If any view reads auth.users, replace it with a public.profiles table filled by a trigger on sign-up, with RLS and a policy so each user reads only their own row. 5) Check that every base table under these views has RLS enabled and policies scoped to (select auth.uid()). 6) Tell me how to test each view logged out and as a second user.

Related: Supabase RLS check, security definer functions and the search path warning, Is my Lovable app secure? and is the anon key safe?

Security Definer View FAQ

What does the Supabase "Security Definer View" error mean?

It is Security Advisor lint 0010_security_definer_view, level ERROR, summary "View bypasses row-level security". A view in your public schema runs with the permissions of whoever created it, not the person querying it, so it ignores the RLS policies on the tables underneath and can return rows your policies were meant to hide.

Why are Supabase views security definer by default?

Supabase's Advisor docs say Postgres' default for views uses the permissions of the view's creator, "an unintuitive default, chosen for backwards compatibility". Views created in Supabase Studio or with the Supabase CLI are usually owned by a privileged role, so the view can read everything that role can.

How do I fix it?

Make the view run as the caller: alter view public.your_view set (security_invoker = true); or recreate it with create view public.your_view with (security_invoker=on) as select ... . Postgres added security_invoker for views in version 15. Then the RLS policies on the underlying tables apply to whoever queries the view.

My app broke after I switched the view to security invoker. Why?

The view now obeys the RLS policies on its base tables. If a table has RLS on but no policy for the role reading it, the view returns nothing. Add a scoped policy on the base table (for example (select auth.uid()) = user_id) rather than switching the view back.

Is a view over auth.users different?

Yes, and worse. Supabase's lint 0002_auth_users_exposed (ERROR) says a public security definer view referencing auth.users exposes all user records to all API users. Supabase recommends a public.profiles table filled by a trigger, with its own RLS, instead.

Can PatchPaste find this?

Not directly. PatchPaste does not sign in or read your database settings, so it cannot list your views or see whether they are security definer. Its free outside-in scan tries a short list of common table names with your public anon key (read-only, at most one row, discarded) and checks the live JavaScript for secret keys. The Security Advisor is the tool for this finding.

Views fixed? Check the live app for free

Paste your live URL for a free A to F report. PatchPaste checks whether common Supabase tables answer to your public anon key without a login (read-only, at most one row, discarded), searches the JavaScript your site sends for secret keys, and flags exposed .env/.git/source maps and missing headers. It does not sign in or read your database settings. Fix prompts for that report are a one-off £9 (or £29 for 10). Scans are free to rerun after each change.

Free. No login. No code access.

Want to see one first? View a sample report.

Sources (checked 13 Nov 2026): Supabase Database Advisors (0010_security_definer_view ERROR and its rationale and fix; 0002_auth_users_exposed; 0008_rls_enabled_no_policy; 0013 "Table publicly accessible"); PostgreSQL CREATE VIEW (security_invoker option and how RLS applies) and ALTER VIEW (SET view options). Screen wording varies between Supabase Studio and Lovable.