Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4133 pages
Databases and Redis

The Supabase Security Advisor flags functions whose search_path parameter is not set

Your error

Function Search Path Mutable2 more lines it can show

Fix it fast

Most common cause, 1 of 3

The function was created without a search_path setting

Recreate the function with an empty search_path and qualify every table, view and function in the body.

Fix
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);
  return new;
end;
$$;
Did this fix it?
Full steps for this cause: check, fix, verify

Short answer

Supabase's linter warns when a Postgres function has no fixed search_path, because it then uses whatever search path the calling session has, and a caller could steer it to their own tables or functions. Add SET search_path = '' to the function and qualify every object inside it with its schema, such as public.profiles. The warning clears on the next lint run.

  • Applies to PostgreSQL 18 (PGlite), Supabase database linter
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Which cause do you have?

List the functions in your schemas that have no search_path in their settings. Those are the ones the linter reports.

Run this first
select n.nspname as schema, p.proname as function, p.prosecdef as security_definer
from pg_proc p
join pg_namespace n on n.oid = p.pronamespace
where n.nspname not in ('pg_catalog', 'information_schema')
  and n.nspname not like 'pg_%'
  and not exists (
    select 1 from unnest(coalesce(p.proconfig, '{}')) c where c like 'search_path=%'
  );

Then find the line you see in this list and open its fix:

  1. 1The function was created without a search_path settingLint 0011 (function_search_path_mutable) at level WARN for a function you wrote
  2. 2Many existing functions need the setting and you do not want to rewrite themThe advisor lists dozens of functions, and their bodies already use schema-qualified names
  3. 3A security definer function trusts the caller's pathThe flagged function is SECURITY DEFINER, often an auth trigger or an RPC exposed to the API

What does the error look like?

  • Function Search Path Mutable
  • Detects functions where the search_path parameter is not set.
  • Unsecured function search path

Cause 1 of 3

The function was created without a search_path setting

You seeLint 0011 (function_search_path_mutable) at level WARN for a function you wrote

Check

Supabase's lint page explains that such a function inherits the search path of the session that calls it, so it can behave differently per user and can be pointed at objects an attacker controls.

Check
select proname, proconfig from pg_proc where proname = 'handle_new_user';

Fix

Recreate the function with an empty search_path and qualify every table, view and function in the body. An empty path means unqualified names no longer resolve, which is the point.

Fix
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);
  return new;
end;
$$;

Verify

proconfig now shows search_path="" and the Security Advisor no longer lists the function after it re-runs.

Verify
select proname, proconfig from pg_proc where proname = 'handle_new_user';

Confirmed by supabase.com

Did this fix it?

Cause 2 of 3

Many existing functions need the setting and you do not want to rewrite them

You seeThe advisor lists dozens of functions, and their bodies already use schema-qualified names

Check

ALTER FUNCTION accepts SET configuration_parameter, so the setting can be added without touching the body. If the body uses unqualified names, use the trusted schema list instead of an empty path.

Check
select pg_get_functiondef('public.my_func(uuid)'::regprocedure);

Fix

Attach the setting with ALTER FUNCTION, giving the full argument list so the right overload is changed.

Fix
-- body already uses public.table names
alter function public.my_func(uuid) set search_path = '';

-- body uses bare names that live in public
alter function public.legacy_func(text) set search_path = public, pg_temp;

Verify

Call the function from the SQL editor as it is used in the app and confirm it returns the same result as before.

Verify
select public.my_func('00000000-0000-0000-0000-000000000000');

Confirmed by postgresql.org

Did this fix it?

Cause 3 of 3

A security definer function trusts the caller's path

You seeThe flagged function is SECURITY DEFINER, often an auth trigger or an RPC exposed to the API

Check

A security definer function runs with its owner's rights. The PostgreSQL manual says its search_path should exclude any schema untrusted users can write to, and place pg_temp last, because otherwise a temporary object could stand in for a real one.

Check
select proname from pg_proc where prosecdef and proconfig is null;

Fix

Fix these first. Use an empty path with qualified names, or list only trusted schemas followed by pg_temp.

Fix
alter function public.get_secret_stats()
  set search_path = public, pg_temp;

Verify

Re-run the query from the check; no security definer function is left without a configured path.

Verify
select proname from pg_proc where prosecdef and proconfig is null;

Confirmed by postgresql.org

Did this fix it?

How do I stop it coming back?

  • Add set search_path = '' to the function template your team copies.
  • Write schema-qualified names in every function body, even when the path would find them.
  • Run the Supabase advisors in CI or after each migration, not only in the dashboard.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.