PatchPaste · Guides

Last updated 10 November 2026

Supabase "Function Search Path Mutable" and "security definer function executable": the safe fix

You opened Supabase Security Advisor on your Lovable or Bolt app and saw function_search_path_mutable, maybe next to anon_security_definer_function_executable. They look alike but they are not equally urgent. Here is what each means, which one can expose data, and the SQL to fix both.

Short answer: Function Search Path Mutable (lint 0011) means a function doesn't pin its search_path. Add set search_path = '' and schema-qualify every name. Security definer function executable by anon (lint 0028) is the more serious one: a function that skips RLS can be called by anyone with your public key at /rest/v1/rpc/. Revoke execute from anon, authenticated and public unless that caller really needs it.

Which warning to fix first

Why your functions are callable by anon

You probably never granted it. Supabase's 0028 docs explain that Postgres grants EXECUTE on new functions to PUBLIC by default, and Supabase also grants default privileges on new functions to anon, authenticated and service_role. PostgREST then exposes any function the role can execute at /rest/v1/rpc/, even if your app never calls it. AI builders often mark helpers security definer to get past an RLS error, which is how an admin-only helper becomes a public endpoint.

Step 1: list the security definer functions and their owners

Run this in the SQL Editor (query from Supabase's 0028 docs):

select
    p.proname,
    pg_get_function_identity_arguments(p.oid) as args,
    pg_catalog.pg_get_userbyid(p.proowner) as owner,
    p.prosecdef as security_definer
from pg_catalog.pg_proc p
join pg_catalog.pg_namespace n on n.oid = p.pronamespace
where n.nspname = 'public'
  and p.prosecdef
order by p.proname;

For each one, decide: should a logged-out visitor call it, a signed-in user, or only your server or a trigger?

Step 2: revoke execute where it isn't needed

-- nobody outside your server should call it
revoke execute on function public.my_admin_helper(uuid)
  from anon, authenticated, public;

-- signed-in users only
revoke execute on function public.my_user_helper()
  from anon, public;
grant execute on function public.my_user_helper() to authenticated;

-- stop new functions being callable by default
alter default privileges in schema public
  revoke execute on functions from anon, authenticated, public;

Revoke from public as well, because that is where the Postgres default grant lives. If the function doesn't need to skip RLS at all, Supabase's other option is alter function public.f(args) security invoker; so it runs as the caller and RLS applies.

Some functions are meant to be public, such as a contact form or an anonymous vote. Supabase says those can stay callable, but they should validate input and do as little as possible, because a security definer function open to anon is effectively a public API endpoint.

Step 3: pin the search path

Supabase recommends an empty search path, which forces every name in the body to carry its schema:

-- quick fix for an existing function
alter function public.handle_new_user() set search_path = '';

-- or when you recreate it
create or replace function public.handle_new_user()
returns trigger
language plpgsql
security definer
set search_path = ''
as $$
begin
  insert into public.profiles (id) values (new.id);
  return new;
end;
$$;

After this, an unqualified profiles inside the body will fail with "relation does not exist". Write public.profiles, auth.uid() and so on. If the function is a signup trigger, sign up a test user straight away: Supabase notes that an error in a trigger on auth.users can block signups.

Fixes to refuse

Check it worked

  1. Re-run Security Advisor. The 0011, 0028 and 0029 warnings for functions you changed should be gone, or left only for functions you decided are meant to be public.
  2. Test the app: sign up a new user, use it as two different users, and open it logged out in a private window.
  3. 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. It won't see your function grants, but it catches the AI edit that "fixed" an error by turning RLS off.

A prompt to paste into Lovable or Bolt

Supabase Security Advisor shows function_search_path_mutable and/or anon_security_definer_function_executable / authenticated_security_definer_function_executable warnings. Fix them without weakening security. 1) List every function in the public schema with whether it is SECURITY DEFINER, its owner, and which roles can execute it. 2) For each SECURITY DEFINER function, tell me who needs to call it (logged-out visitors, signed-in users, or only triggers/server) and wait for my OK. 3) Revoke EXECUTE from anon, authenticated and public where it is not needed, and grant back only to the role that needs it. Switch functions that don't need to bypass RLS to SECURITY INVOKER. 4) Add SET search_path = '' to every flagged function and schema-qualify every name in its body (public.profiles, auth.uid()). 5) Add: alter default privileges in schema public revoke execute on functions from anon, authenticated, public. Do NOT disable RLS, do NOT use USING (true) on private tables, and do NOT use the service_role key in frontend code. Show me the final SQL, then remind me to sign up a test user to check signup still works.

Related: Supabase RLS check, RLS using (true), 42501 permission denied and pre-launch checklist.

Function search path and security definer FAQ

What does "Function Search Path Mutable" mean in Supabase?

It is Security Advisor lint 0011 (function_search_path_mutable, level WARN). The function has no fixed search_path, so it uses the caller's session search_path to find unqualified names like profiles. Supabase's docs say that can make it behave differently for different callers and could let someone point it at objects they control. The fix is to add set search_path = '' and write every table and function name with its schema, for example public.profiles.

Is Function Search Path Mutable dangerous?

On its own it is a hardening warning rather than a sign your data is open. It matters most on security definer functions, because those run with the owner's rights. Fix it, but look first at any 0028 or 0029 warning, which is about who can call a privileged function at all.

What does "security definer function executable by anon" mean?

It is lint 0028 (anon_security_definer_function_executable). A security definer function runs as its owner, usually a privileged role that bypasses Row Level Security. If the anon role can execute it, Supabase says anyone with your public anon key can call it through POST /rest/v1/rpc/ and may read or change data RLS would normally block. Lint 0029 is the same for any signed-in user.

Why is my function executable by anon when I never granted it?

Supabase's docs explain that Postgres grants execute on new functions to PUBLIC by default, and Supabase also grants default privileges on new functions to anon, authenticated and service_role. So a function created in public is callable by anon unless you revoke it.

Will set search_path = '' break my function?

Only if the body uses unqualified names. Once search_path is empty, every table, view and function inside must be written with its schema (public.profiles, auth.uid()). Test the function, and for a signup trigger, sign up a test user, before you ship.

Can PatchPaste find these warnings?

No. PatchPaste does not sign in or read your database settings, so it cannot see search_path or function grants. Supabase Security Advisor is the tool for these. PatchPaste checks the live site from outside: secret keys in the JavaScript, common tables readable with the public anon key, exposed .env, .git and source maps, and headers.

Fixed the Advisor warnings? 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 10 Nov 2026): Supabase Database Advisors, 0011 function_search_path_mutable, 0028 anon_security_definer_function_executable (default PUBLIC/anon/authenticated execute grants, /rest/v1/rpc/ exposure, owner query, revoke and security invoker options, pg_graphql note) and 0029 authenticated_security_definer_function_executable; signup-trigger caution from lint 0002 auth_users_exposed on the same page.