LeakPatrol › Guides

Supabase "Function Search Path Mutable": what it means and the fix

By LeakPatrol · Updated 26 November 2026

You open the Security Advisor in Supabase, or Lovable shows its security warnings, and there it is: Function Search Path Mutable, often several times, once for each function such as handle_new_user, update_updated_at_column or is_admin. It means the function doesn't set its own search_path, so the tables and functions it refers to by short name are looked up using whatever search path the caller has. The fix is one line per function. The only thing to watch is not breaking the function in the process.

What the warning means

When a function says profiles instead of public.profiles, Postgres finds the table by walking the search_path: a list of schemas to try in order. If the function doesn't fix that list itself, it uses the caller's. Someone who can change their search path, and create a table or function with the same name in a schema that comes first, could make your function use their object instead of yours.

That matters most for security definer functions, which run with the owner's rights, often skipping Row Level Security. Those are the ones to fix first. For ordinary functions the warning is mostly good hygiene, but it costs one line, so fix them all and the Advisor goes quiet.

Find every affected function

Run this in the Supabase SQL editor. It lists your own functions in public that don't set a search path, and whether each one is security definer:

select p.proname as function,
       pg_get_function_identity_arguments(p.oid) as args,
       p.prosecdef as security_definer
from pg_proc p
join pg_namespace n on n.oid = p.pronamespace
where n.nspname = 'public'
  and not exists (
    select 1 from unnest(coalesce(p.proconfig, '{}'::text[])) c
    where c like 'search_path=%')
  and not exists (
    select 1 from pg_depend d
    where d.objid = p.oid and d.deptype = 'e')
order by p.prosecdef desc, p.proname;

The fix

For each function, set an empty search path:

alter function public.handle_new_user() set search_path = '';
alter function public.update_updated_at_column() set search_path = '';

Include the argument types if the function has any, exactly as the args column shows them, for example alter function public.has_role(uuid, text) set search_path = '';. Re-run the Security Advisor and the warnings are gone.

Don't break the function: use full names inside

With an empty search path, every short name inside the function stops resolving. A trigger that inserts into profiles will now fail with relation "profiles" does not exist, and if it's the sign-up trigger, new users see "Database error saving new user". So check the body of each function and write every table and function with its schema:

You can see a function's current body with select pg_get_functiondef('public.handle_new_user'::regproc);. If the body is long and you'd rather not rewrite it now, set search_path = public also clears the warning and keeps short names working. It's less strict than an empty path, but far better than none.

A fixed version of the most common one looks like this:

create or replace function public.handle_new_user()
returns trigger
language plpgsql
security definer
set search_path = ''
as $$
begin
  insert into public.profiles (id, email)
  values (new.id, new.email)
  on conflict (id) do nothing;
  return new;
end;
$$;

While you're in the Security Advisor

And check who can call your security definer functions. Functions in public can be called by anyone through /rest/v1/rpc/, so revoke what visitors shouldn't run: revoke execute on function public.is_admin() from anon;.

A prompt to paste into Lovable, Bolt or Cursor

The Supabase Security Advisor shows "Function Search Path Mutable".
Fix it without breaking anything:
1. List every function in the public schema that doesn't set
   search_path.
2. For each one, add set search_path = '' and rewrite every table
   and function name inside it with its schema (public.profiles,
   not profiles).
3. Keep security definer where it is already used, and revoke
   execute from anon on security definer functions that visitors
   don't need.
4. Test sign-up and every trigger afterwards. Do not disable RLS.

The Security Advisor only sees your database. LeakPatrol's free scan checks your live app from the outside, for leaked keys, readable tables and public files, in about a minute.

Check your app in a minute

Free, read-only, no sign-up. Every problem comes with a plain-English fix and a prompt for your AI tool.

Get the 10-point checklist

Every check we run on AI-built apps, with how to do each one yourself. Straight to your inbox.

Questions

What does Function Search Path Mutable mean in Supabase?

The function does not set its own search_path, so short names inside it, like profiles, are looked up using the caller's search path. Someone who can change that path could make the function use a different table or function.

How do I fix Function Search Path Mutable?

Run alter function public.your_function() set search_path = ''; for each flagged function, then write every table and function name inside it with its schema, such as public.profiles.

Will setting search_path break my function?

It can, if the function uses short names like profiles. With an empty search path they stop resolving, so rewrite them as public.profiles, or use set search_path = public as a less strict option.

Is Function Search Path Mutable dangerous?

It matters most for security definer functions, which run with the owner's rights. For ordinary functions it is mostly hygiene, but the fix is one line, so fix them all.

More guides