Supabase "Function Search Path Mutable": what it means and the fix
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:
profilesbecomespublic.profilesuser_rolesbecomespublic.user_rolesgen_random_uuid()andnow()are fine; built-inpg_catalogfunctions are always foundauth.uid()is already a full name
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
- RLS disabled in public is the warning that really matters. Anyone with your anon key, which is in your frontend, can read and change that table. Turn RLS on and add policies, see the RLS policy generator.
- Security definer view: a view that ignores the RLS of the tables under it. Recreate it with
with (security_invoker = true). - Leaked password protection disabled: a switch under Authentication settings that rejects known leaked passwords.
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.
Plus the odd security tip. Unsubscribe any time.
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
- Supabase RLS policy generator (free)
- Is this API key safe in my frontend? Free key checker
- Security scan MCP server for Claude Code, Cursor and other AI agents
- Supabase October 30 grants change: what it fixes for your app's security, and what it doesn't
- Supabase "42501 permission denied for table": the safe fix (not GRANT ALL)
- Supabase "new row violates row-level security policy": 5 causes and the safe fix
- Supabase service_role key exposed? What to do in the next hour
- Supabase select returns an empty array but the data is there: the RLS fix
- Supabase "Database error saving new user": find the cause and fix it safely
- Supabase Storage upload: "new row violates row-level security policy" fixed
- Supabase "infinite recursion detected in policy for relation" fixed
- Supabase Edge Function "blocked by CORS policy" fixed
- Supabase "Forbidden use of secret API key in browser" (401) fixed
- Supabase "Legacy API keys are disabled" or "Invalid API key": what it means and the fix
- Supabase login or magic link redirects to localhost:3000 (fixed)
- Is your Supabase storage bucket public? What anyone can see, and the fix
- Where to put your OpenAI API key in a Lovable app (so nobody can copy it)
- Lovable data exposure study: is your app one of the 24,664?
- Lovable security check: is your Lovable app safe?
- Bolt.new security check: is your Bolt app safe?
- Launch checklist for apps built with Lovable, Bolt and Cursor
- Supabase security check: is your anon key safe? (RLS checker)
- How to check if your API key is exposed on your website
- Are VITE_ env variables secret? How to hide API keys
- Stop users giving themselves your paid plan (Supabase)