Function Search Path Mutable
A database function can quietly pick up a look-alike table or function planted by someone else, and then run it with the function’s own permissions.
What it means
This is a WARN in Supabase’s own Security Advisor (lint 0011_function_search_path_mutable), so you may see it in your dashboard or email before any scanner reports it.
When a function mentions a table or another function by its bare name, Postgres looks the name up through a list of schemas called the search_path. If the function does not fix that list, the result can change depending on who calls it and what they have set up.
That matters most for functions that run with their owner’s permissions or that fire from triggers. AI app builders can write these without fixing the search_path.
Check it yourself
Run this in the Supabase SQL editor. It lists functions in the public schema that have no fixed search_path. Functions that belong to an installed extension can show up too; leave those alone.
select p.proname as function, pg_get_function_identity_arguments(p.oid) as arguments
from pg_proc p
join pg_namespace n on n.oid = p.pronamespace
where n.nspname = 'public'
and p.prokind = 'f'
and not exists (
select 1 from unnest(coalesce(p.proconfig, '{}')) as setting
where setting like 'search_path=%'
)
order by 1;The fix
- 1
Open each function’s body (in the dashboard, or with
select pg_get_functiondef('public.note_count(uuid)'::regprocedure);) and put the schema in front of every table and function it uses, so nothing depends on the search_path. Functions that use something from an extension need that extension’s schema in front too, for example extensions.some_function(). Here is the idea written out in full, with the search_path fixed in the same statement so the function is never live with an empty path and unqualified names.create or replace function public.note_count(owner_id uuid) returns bigint language sql stable set search_path = '' as $$ select count(*) from public.notes where user_id = owner_id; $$; - 2
If a function’s body already uses a schema in front of every name, you can fix just its search_path. An empty value means the function can only see built-in names. Do not run this on a function until you have read its body.
alter function public.note_count(uuid) set search_path = ''; - 3
Trigger the feature that uses each function once, then refresh the Security Advisor and run your scanner again.
What can break
If the search_path is emptied but the function body still uses bare names, the function fails with errors such as “relation does not exist”, and anything that fires it (a trigger on insert, a sign-up flow) can start failing. Change one function at a time and test the feature that calls it.
Undo it
To return one function to how it was, run alter function public.note_count(uuid) reset search_path;. If you replaced the body, put the old body back from your saved copy (take it with pg_get_functiondef before you change anything). To confirm the fix, run the check again: the function should no longer be listed.
Table, column and bucket names here are examples. This page is general guidance for one finding; it does not make an app safe on its own. Take a backup before changing a live database. Any SQL on this page was run on a test Postgres database with two test users before we published it; the tests are public. The test database is not a Supabase project. Auth and storage are stand-ins, and GraphQL and queue extensions are not installed, so those pages are tested for permissions and rules only. Dashboard steps and app code are not tested.