Supabase database

Supabase “Function Search Path Mutable” warning: is it dangerous, and how do I fix it?

It means a database function doesn’t pin its search_path, so table and function names inside it are looked up wherever the caller’s session points. Through your app’s API that can’t be changed, so on its own it isn’t a leak; it becomes one for SECURITY DEFINER functions when anyone else can run SQL. The fix is set search_path = '' plus a schema in front of every name.

TL;DR

  • The warning is Supabase’s lint 0011, level WARN. It flags any function in an exposed schema without a fixed search_path, including harmless ones.
  • In our lab a SQL login with no table grants made a security definer admin check return true for a normal user, by creating a temporary table with the same name.
  • Setting search_path = '' alone did not stop it: an unqualified name still found the temporary table. Writing public.user_roles did.
  • Pinning the path breaks unqualified extension calls such as uuid_generate_v4(); write extensions.uuid_generate_v4().

What the warning means

Postgres finds an unqualified name like user_roles by walking the search_path, a list of schemas. A function without its own search_path uses the caller’s. Supabase’s lint 0011 (“Function Search Path Mutable”, level WARN) flags every such function in an exposed schema and recommends search_path = '', which forces every name in the body to be fully qualified.

For an ordinary function this is hygiene. It runs with the caller’s rights, so a trick gets the caller nothing they couldn’t do anyway. For a SECURITY DEFINER function, which runs with its owner’s rights (often postgres, which skips RLS), a name that resolves to the wrong object runs with those rights.

Can someone exploit it through my app?

Not through the Data API alone. A browser can call your function at /rest/v1/rpc/…, but it can’t run SQL or change the session’s search path. In our lab the admin check answered correctly to every API call.

It matters when someone or something can run SQL against the database without being the owner: a teammate with their own login, an analytics or BI connection, a read-only role for an AI agent, or a reporting tool. That is more common than it was, as AI agents get database connections.

The exploit we tested

A security definer function, the way AI builders often write it, with no search path and an unqualified table name:

vulnerable function
create function public.is_admin() returns boolean
  language sql security definer stable as $$
  select exists (select 1 from user_roles where user_id = auth.uid() and role = 'admin')
$$;

Then a separate login, analyst, with no grants on any table. Postgres lets every role create temporary tables by default, and the temporary schema is searched before the others for tables.

lab output, 5 Dec 2026 (Postgres 17.11 and 18.6, PostgREST 12.2.12)
-- through the API
bob POST /rpc/is_admin:   false [HTTP 200]
alice POST /rpc/is_admin: true  [HTTP 200]
-- as the analyst login
analyst reads public.user_roles directly: ERROR:  permission denied for table user_roles
analyst: create temp table user_roles … ('bob','admin'); call is_admin() as bob: t
-- after "alter function public.is_admin() set search_path = ''", name still unqualified
bob POST /rpc/is_admin: {"code":"42P01","message":"relation \"user_roles\" does not exist"} [HTTP 404]
analyst: same temp table trick: t
-- after search_path = '' and public.user_roles in the body
bob POST /rpc/is_admin:   false [HTTP 200]
alice POST /rpc/is_admin: true  [HTTP 200]
analyst: same temp table trick: f

Two lessons. An admin check built this way can be fooled by anyone with a SQL login. And search_path = '' is only half the fix: it made the app’s own call fail and still let the temporary table win, because Postgres searches the temporary schema first unless it is listed. Supabase’s guidance says both halves: pin the path and schema-qualify every name. Supabase’s own linter stopped flagging the function as soon as the path was pinned, so a clean Security Advisor doesn’t prove the names are qualified.

The fix

supabase/migrations/…_pin_search_path.sql
create or replace function public.is_admin()
returns boolean
language sql
security definer
stable
set search_path = ''
as $$
  select exists (select 1 from public.user_roles
                 where user_id = (select auth.uid()) and role = 'admin')
$$;

Qualify everything in the body: public. for your tables, auth.uid(), and extensions. for extension functions. Built-in functions such as now() and gen_random_uuid() live in pg_catalog, which is always searched.

What breaks if you forget, from the lab:

lab output
create new_invite_code() with search_path '' calling uuid_generate_v4() unqualified:
  ERROR:  function uuid_generate_v4() does not exist
after writing extensions.uuid_generate_v4(): works

A language sql function fails when you create it. A plpgsql function fails the first time it runs, so test each function after the change. If a definer function doesn’t need to be called from the browser, also revoke execute from anon and authenticated, or move it to a schema the API doesn’t expose (see SECURITY DEFINER functions).

How to check it worked

This read-only query lists functions in public with no pinned path, definer functions first:

functions-without-search-path.sql (read-only)
select p.oid::regprocedure as function,
       p.prosecdef as security_definer,
       has_function_privilege('anon', p.oid, 'execute') as anon_can_call
from pg_proc p join pg_namespace n on n.oid = p.pronamespace
where n.nspname = 'public' and p.prokind in ('f','p')
  and not exists (select 1 from unnest(coalesce(p.proconfig, '{}')) c
                  where c like 'search_path=%')
order by p.prosecdef desc, 1;

Empty means the warning is gone. Then read each definer function’s body for unqualified names, because the linter won’t. Run the Security Advisor again and call each function from the app once.

Ask your AI builder to fix it

Prompt for your AI builder
Supabase's Security Advisor shows "Function Search Path Mutable" for some of my functions. For each function it lists, write a migration that recreates it with set search_path = '' and with every table, view and function in its body schema-qualified (public.…, auth.uid(), extensions.… for extension functions). Don't change what any function does. List each function and show me the exact SQL before you apply it. For any SECURITY DEFINER function, also tell me which roles can execute it.

Questions people ask

Is "Function Search Path Mutable" a critical security issue?

Not on its own. Supabase rates it WARN. Through the Data API nobody can change the search path. It becomes a real risk for SECURITY DEFINER functions when someone other than the owner can run SQL, as our lab showed with a temporary table.

How do I fix Function Search Path Mutable in Supabase?

Recreate the function with set search_path = '' and put a schema in front of every name in its body, such as public.profiles and extensions.uuid_generate_v4(). Supabase's lint 0011 recommends the empty path.

Is setting search_path = '' enough?

No. In our lab an unqualified table name in a function with an empty search path still resolved to a temporary table created by another login. Qualified names closed it. The linter stops warning as soon as the path is pinned, so check the names yourself.

Why did my function break after setting search_path?

Names in the body are no longer found without a schema. Tables need public. in front and extension functions need extensions. in front. Built-in functions like now() keep working.

Sources and lab

The checks behind this guide, each with example code, a self-check and the fix.

Free check

Check your migrations for this, free.

Paste a public GitHub repo. The free RLS check reads its supabase/migrations and flags tables with RLS off or no policies, always-true policies, update policies with no WITH CHECK, SECURITY DEFINER functions anyone can call or with no fixed search_path, views that skip RLS and public buckets. It never connects to your database.

Free, no sign-upReads migration files onlyHow it works

Written by Manraj Singh Dhillon. Last checked 5 Dec 2026. Code samples are synthetic and run against your own project; nothing here names a real app. Spotted a mistake? Tell us.