Skip to content
← All guides

Security

Supabase Security Advisor errors explained: security definer view, auth.users exposed, function search_path

By Jan Lipmann, appienceChecked against sources on 11 min read

The weekly Supabase security email or the Security Advisor lists findings like "Security Definer View", "Exposed Auth Users" or "Function Search Path Mutable". The first two are rated ERROR: a view that ignores Row Level Security, possibly handing your users' emails to anyone with your app's public key. The third is a WARN about database functions. Below: what each one means in plain words, how to confirm it in your own project, and the SQL that fixes it.

SupabasePostgreSQL

What you are seeing

Supabase runs its security checks against your projects, and organization owners receive weekly security emails summarizing what they find (Supabase security retro 2025). The same findings appear in the dashboard under Advisors > Security Advisor (Database Advisors). This page covers the three that tend to confuse people:

  • Exposed Auth Users (auth_users_exposed, lint 0002, level ERROR): "View/Materialized View ... in the public schema may expose auth.users data to anon or authenticated roles" (lint 0002).
  • Security Definer View (security_definer_view, lint 0010, level ERROR): "View public.something is defined with the SECURITY DEFINER property" (lint 0010).
  • Function Search Path Mutable (function_search_path_mutable, lint 0011, level WARN): "Function public.something has a role mutable search_path" (lint 0011).

You may not have written any of these yourself. Views and functions are often added by an AI tool or copied from an example while building a feature, and nothing in the app looks wrong. The advisor flags how the database is set up, not a visible bug.

Note: Supabase's own docs say "some findings may be intentional" and that you should check them against your intended access model before changing anything (Database Advisors). The checks below help you decide which findings are real problems in your project.

How to check it yourself

Run these against your own project only - Supabase's security program allows researchers to test only their own projects (Supabase security retro 2025). Every query below only reads, and the role test at the end runs inside a transaction that is rolled back. Use SQL Editor in the Supabase dashboard.

1. Get the full list of findings

  1. In the dashboard, open your project and go to Advisors > Security Advisor. Each finding names the object (a view or a function) and links to Supabase's explanation.
  2. Write down the name of every view and function listed under the three lints on this page. You will need the exact names below.
  3. If you use the Supabase CLI, supabase db advisors prints the same checks. It inspects the local database by default; pass --remote for the linked project (CLI reference). Check supabase db advisors --help on your CLI version.

2. Find views that read auth.users (Exposed Auth Users)

auth.users is the table behind Supabase Auth. It holds every user's email, login methods and other personal data (lint 0002). Supabase keeps it out of the API on purpose (Managing user data). A view in public that selects from it puts that data back into the API. This query lists every view or materialized view that depends on auth.users, and whether visitors (anon) or signed-in users (authenticated) may read it:

select distinct
  n.nspname as schema,
  c.relname as view_name,
  case c.relkind when 'v' then 'view' else 'materialized view' end as kind,
  has_table_privilege('anon', c.oid, 'SELECT') as visitors_can_read,
  has_table_privilege('authenticated', c.oid, 'SELECT') as signed_in_can_read
from pg_depend d
join pg_rewrite r on r.oid = d.objid
join pg_class c on c.oid = r.ev_class
join pg_namespace n on n.oid = c.relnamespace
where d.classid = 'pg_rewrite'::regclass
  and d.refobjid = 'auth.users'::regclass
  and c.relkind in ('v', 'm')
  and n.nspname <> 'auth'
order by schema, view_name;
This mirrors the way the advisor's own check finds these views (lint 0002 source). A row with true in either privilege column, in a schema your API exposes (by default public), is the finding.

To see exactly which columns the view hands out, print its definition (use the name from the list):

select pg_get_viewdef('public.YOUR_VIEW'::regclass, true);
If the definition contains email, phone, raw_user_meta_data or raw_app_meta_data, treat it as personal data exposure.

3. Find views that ignore Row Level Security (Security Definer View)

By default a Postgres view checks the privileges and policies of the view's owner, not of the person querying it (PostgreSQL: CREATE VIEW). In Supabase, views are usually created by the postgres user, so they bypass RLS (Row Level Security). This lists the views in public that do not have security_invoker turned on:

select
  c.relname as view_name,
  pg_get_userbyid(c.relowner) as owner,
  has_table_privilege('anon', c.oid, 'SELECT') as visitors_can_read,
  has_table_privilege('authenticated', c.oid, 'SELECT') as signed_in_can_read,
  c.reloptions as options
from pg_class c
join pg_namespace n on n.oid = c.relnamespace
where c.relkind = 'v'
  and n.nspname = 'public'
  and not (
    lower(coalesce(c.reloptions::text, '{}'))::text[]
    && array['security_invoker=1', 'security_invoker=true', 'security_invoker=yes', 'security_invoker=on']
  )
order by view_name;
Same test as the advisor's check (lint 0010 source), which only reports views that anon or authenticated can read. If you added other schemas to Exposed schemas in the API settings, change n.nspname = 'public' to include them.

For each view, look at the tables it reads (pg_get_viewdef as in step 2) and ask: would a visitor or a signed-in user be allowed to read all of those rows directly? If the tables behind the view have careful owner policies, the view is quietly skipping them.

4. See what a visitor actually gets from a view

This switches to the visitor role the API uses (anon) the same way Supabase's policy tests switch roles (Row Level Security), counts what the view returns, and rolls back:

begin;
set local role anon;

select count(*) as rows_a_visitor_can_read
from public.YOUR_VIEW;

rollback;
A number above 0 for a view over private data means anyone with your app's public key can read those rows through the API. permission denied means visitors have no grant on the view, which is what you want for private data. SQL Editor may show only the result of the last statement: if you see "Success. No rows returned", select the lines from begin; through the select, run only that selection, then run rollback;.

5. Find functions without a fixed search_path (Function Search Path Mutable)

select
  n.nspname as schema,
  p.proname as function_name,
  pg_get_function_identity_arguments(p.oid) as arguments,
  p.prosecdef as security_definer,
  pg_get_userbyid(p.proowner) as owner
from pg_proc p
join pg_namespace n on n.oid = p.pronamespace
where n.nspname not in (
    'pg_catalog', 'information_schema', 'auth', 'storage', 'realtime',
    'extensions', 'graphql', 'graphql_public', 'vault', 'pgbouncer',
    'cron', 'net', 'pgsodium', 'pgsodium_masks', 'supabase_functions',
    'supabase_migrations'
  )
  and not exists (
    select 1 from pg_depend d
    where d.classid = 'pg_proc'::regclass
      and d.objid = p.oid
      and d.deptype = 'e'
  )
  and not exists (
    select 1 from unnest(coalesce(p.proconfig, '{}'::text[])) as cfg
    where cfg like 'search_path=%'
  )
order by security_definer desc, schema, function_name;
Like the advisor's check (lint 0011 source), this skips Supabase's own schemas and functions that belong to extensions. Functions with security_definer = true are at the top: fix those first.

Why it happens

Security definer views

Supabase's explanation: Postgres' default for views is security definer, which means "they use the permissions of the view's creator" rather than the user running the query, a default kept for backwards compatibility (lint 0010). A view in public is reachable through your project's API. So a view created in the SQL Editor or by a migration, without security_invoker, can return every row of the tables behind it, even if those tables have perfect RLS policies. The security_invoker option, which makes a view check the caller's privileges and policies instead, exists from Postgres 15 (Row Level Security).

Exposed auth users

This is the same problem pointed at the most sensitive table in the project. Supabase's docs state that a public security definer view referencing auth.users "exposes all user records to all API users" (lint 0002). Materialized views do not support RLS at all, so they are flagged too. The usual reason it exists: a screen needed user names or emails, auth.users is not reachable from the app, and a view was the quickest way to make the screen work.

Mutable search_path

When a function says profiles instead of public.profiles, Postgres looks the name up in the schemas listed in search_path (PostgreSQL: search_path). A function without its own search_path setting inherits the caller's, so the same function can find different objects depending on who calls it (lint 0011). For a security definer function, which runs with its owner's privileges, PostgreSQL's docs warn that a caller could create objects that "mask objects intended to be used by the function" (PostgreSQL: CREATE FUNCTION). That is why Supabase says to set search_path = '' on every security definer function and to put the schema in front of every name inside it (Row Level Security). On ordinary functions the advisor still warns, because their behaviour can change with the caller's settings.

How to fix it

Warning: Each fix changes what the app can read the moment it runs. Try it on a Supabase branch or a copy of the project first, keep the old definitions (pg_get_viewdef, or Database > Functions in the dashboard), and put the final SQL in a migration so it is not lost the next time your AI tool regenerates the database.

Exposed Auth Users: close it first

If step 2 showed a view over auth.users that anon or authenticated can read, take the API's access away now. The advisor only reports such views when one of those roles has select on them (lint 0002 source):

revoke select on public.YOUR_VIEW from public, anon, authenticated;
public is included because a grant to PUBLIC applies to every role, including anon (lint 0016). Screens that read this view will stop showing data until you finish the steps below. That is the trade-off: until then, every user's personal data is readable by anyone who has your public key, which ships inside your app.

Then give the app what it actually needs in a safe way. Supabase recommends a profiles table in public with only the fields your app needs, filled by a trigger on auth.users, with RLS on the table (lint 0002, Managing user data). If you already have a profiles table, add the missing columns to it instead of creating a new one. If your project already has a handle_new_user function or an on_auth_user_created trigger (check Database > Functions and Database > Triggers), edit that function instead of running the create statements below:

create table if not exists public.profiles (
  id uuid not null references auth.users on delete cascade,
  display_name text,
  primary key (id)
);

alter table public.profiles enable row level security;

grant select on public.profiles to authenticated;

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

create function public.handle_new_user()
returns trigger
language plpgsql
security definer set search_path = ''
as $$
begin
  insert into public.profiles (id, display_name)
  values (new.id, new.raw_user_meta_data ->> 'display_name');
  return new;
end;
$$;

create trigger on_auth_user_created
  after insert on auth.users
  for each row execute procedure public.handle_new_user();
Adapted from Supabase's example. The explicit grant is needed on projects where new tables are no longer exposed automatically (grants change). If the app should show other users' names (a member list, comments), add a narrow select policy for that case rather than using (true).

Like Supabase's example, this puts a security definer function in public, so the advisor will list it under lints 0028 and 0029 (lint 0028 source). It cannot be called as an RPC, because Postgres only runs trigger functions as triggers, but you can clear the finding by revoking execute and then testing sign-up once:

revoke execute on function public.handle_new_user() from public, anon, authenticated;
  • Test the trigger before you rely on it. It runs in the same transaction as the sign-up, so an error in it blocks new sign-ups (lint 0002). With search_path = '', a name without its schema (profiles instead of public.profiles) makes every sign-up fail with Database error saving new user (Managing user data).
  • Copy only harmless fields from raw_user_meta_data. The person signing up fills it in, so never take a role, plan or admin flag from it - see Can users make themselves admin?.

Users who signed up before the trigger existed have no profile yet. Create their rows once, from the SQL Editor:

insert into public.profiles (id, display_name)
select id, raw_user_meta_data ->> 'display_name'
from auth.users
on conflict (id) do nothing;

Change the app to read from profiles instead of the view (search the code for the view's name, for example .from('YOUR_VIEW')), then remove the view: drop view public.YOUR_VIEW; (for a materialized view, drop materialized view public.YOUR_VIEW;). Supabase's docs also describe a second route - a security_invoker view plus RLS on auth.users itself (lint 0002) - but it means changing a table Supabase manages, so the profiles route is the simpler one to keep correct.

Security Definer View: make the view respect RLS

Supabase's fix is to set security_invoker so the view respects the RLS policies of the tables it reads (lint 0010). You do not have to recreate the view: view options can be changed on an existing view with ALTER VIEW (PostgreSQL: ALTER VIEW).

select version();

alter view public.YOUR_VIEW set (security_invoker = true);
security_invoker needs Postgres 15 or newer. On an older project, Supabase's docs say to revoke access from anon and authenticated or to move the view to a schema the API does not expose (Row Level Security).
  • After the change, the person querying the view needs their own privileges on the view and on every table behind it (PostgreSQL: CREATE VIEW). If a screen that uses the view now fails with permission denied (42501), a table behind it has no grant for that role - see our guide to the 42501 error.
  • If the screen now shows fewer rows, that is RLS working: the view used to show rows the user's policies never allowed. Write the policy the screen really needs on the underlying table.
  • If the view was only meant for you (an admin report, a dashboard), do not expose it at all: revoke select on public.YOUR_VIEW from public, anon, authenticated;, or move it out of public with alter view public.YOUR_VIEW set schema private; (create the schema first with create schema if not exists private; and do not add it to Exposed schemas).
  • If the view deliberately shows a safe subset to everyone (for example public leaderboard names), you can keep it as it is - Supabase treats some findings as intentional (Database Advisors). Make sure it really selects only columns and rows that are fine to publish.

Function Search Path Mutable: pin search_path

Supabase recommends setting the function's search_path to an empty string and then putting the schema in front of every table, view and function the body uses (lint 0011). You can change the setting on an existing function with ALTER FUNCTION ... SET (PostgreSQL: ALTER FUNCTION). Start with the security definer functions from step 5:

  1. Open the function in Database > Functions, or print it with select pg_get_functiondef('public.YOUR_FUNCTION'::regproc); (for functions with several versions, use 'public.YOUR_FUNCTION(uuid)'::regprocedure with the arguments from step 5).
  2. Find every table, view, type or function name without a schema: from profiles must become from public.profiles, my_helper() must become public.my_helper(). Built-in Postgres functions such as now() or count() keep working, because the system schema pg_catalog is always searched (PostgreSQL: search_path). Functions from extensions live in the schema the extension was installed in (shown in Database > Extensions), so add that prefix too.
  3. If the body needed changes, recreate the function with create or replace function and set search_path = '', as in the example below. If the body already uses full names everywhere, the one-line alter function is enough.
  4. Call the function once from the app (or with select) to confirm it still works.
-- Body already uses schema-qualified names: one line is enough.
alter function public.YOUR_FUNCTION(uuid) set search_path = '';

-- Body needs fixing: recreate it with full names and the setting.
create or replace function public.get_my_orders()
returns setof public.orders
language sql
stable
security invoker
set search_path = ''
as $$
  select *
  from public.orders
  where user_id = (select auth.uid());
$$;
Replace (uuid) with the function's real argument types from step 5, or leave the brackets empty if it has none. A function with search_path = '' that still refers to orders instead of public.orders fails with relation "orders" does not exist.

While you are looking at security definer functions in public: they are callable over the API by anyone whose role has execute on them, and they run with their owner's rights, so they skip RLS. Supabase flags that separately (lints 0028 and 0029). If a function does not need to be called from the app, revoke it, from public as well, because that is where Postgres' default grant lives (lint 0028):

revoke execute on function public.YOUR_FUNCTION(uuid) from public, anon, authenticated;
Do not run this on a function your app calls with rpc(...), The handle_new_user trigger function has its own revoke in the Exposed Auth Users section above - test sign-up after running it.

Verify

Run checks 2 to 5 again: views over auth.users should be gone or unreadable by anon and authenticated, the role test should return permission denied or only rows that are meant to be public, and step 5 should list nothing you still intend to fix. Then reload the Security Advisor (or run supabase db advisors --remote) and click through the app as a signed-out visitor and as a normal user. Create one new test account to confirm sign-up still works if you touched the trigger.

When to get help

Most findings on this page are fixed with a few lines of SQL once you know what the view or function is for. Get a second pair of eyes when:

  • A view over auth.users was readable by anon on a live app. If you are subject to the GDPR, a personal data breach generally has to be reported to the supervisory authority within 72 hours of becoming aware of it, unless it is unlikely to result in a risk to people (GDPR, Article 33). Get legal advice on that part.
  • The advisor lists many views and functions and you cannot tell which ones the app still uses, or what each one was meant to do.
  • Switching a view to security_invoker broke screens and the fix seems to need broad policies like using (true) - that usually means the policies behind the view were never designed for the app's real access rules.
  • A security definer function changes data (payments, credits, roles, invitations) and you are not sure it checks who is calling it.
  • Sign-up started failing after a change to the trigger on auth.users and you cannot find why.

Sources

Primary documentation this guide was checked against. Platforms change - if something here no longer matches, the source wins.

Frequently asked questions

Which Security Advisor finding should I fix first?
Exposed Auth Users (lint 0002), because it can put every user's email and personal data in your public API. Then Security Definer View (lint 0010) for views over private tables. Both are rated ERROR. Function Search Path Mutable (lint 0011) is a WARN; fix it first on security definer functions.
What does "security definer view" mean in plain words?
The view reads its tables with the rights of whoever created it, usually the all-powerful postgres user, not with the rights of the person using your app. So your Row Level Security policies on those tables are skipped. Setting security_invoker = true on the view makes it apply the user's own policies.
Will setting security_invoker break my app?
It can change what a screen shows. After the change, each user only sees the rows their own policies allow, and needs grants on the tables behind the view. A screen that shows fewer rows or a 42501 error is telling you which policy or grant is missing. Test on a branch first.
Is a mutable search_path a real vulnerability?
On a security definer function, it can be: PostgreSQL's docs warn that callers could create objects that mask the ones the function means to use, while the function runs with its owner's rights. On an ordinary function it is mainly about predictable behaviour. Supabase recommends search_path = '' on all of them, with schema-qualified names in the body.
Can I just ignore or dismiss these findings?
Only after checking. Supabase's docs say some findings may be intentional, for example a view that deliberately shows a safe public subset. A view over auth.users that visitors can read is almost never intentional.
Can I fix these with the Supabase Assistant or my AI tool?
You can ask it to write the SQL, but check the result against this page before running it. In particular, refuse fixes that make a broken screen work again by adding using (true) policies or table-wide grants.

Related guides

Fixed-price audit

Want someone to check the whole app, not just this?

A review of data security, production readiness and App Store readiness for apps built with AI tools. 900 USD, a ranked list of fixes within 5 business days.