Description
Ensure every Postgres function in exposed schemas has a fixed search_path set, preferably an empty string, and refers to objects with fully qualified names such as public.table_name. This makes sure the function always uses the objects it was written for.
Rationale
If a function's search_path is not fixed, it depends on the search_path of the user calling it. An attacker who can create objects in a schema on that path could make the function use a fake table or function instead of the real one. This is especially dangerous for SECURITY DEFINER functions, which run with higher permissions.
Impact
Prevents functions from being tricked into using the wrong objects
Makes function behavior predictable
Functions may need fully qualified object names
Default Value
By default, Postgres functions do not have a fixed search_path and use the caller's search_path.
Pre-Requisites
Project Owner or Admin role
Access to the SQL Editor
Test Plan
Sign in to the Supabase Dashboard at https://supabase.com/dashboard.
Select your project.
Open Advisors in the sidebar and select Security Advisor.
Check for the finding Function Search Path Mutable.
If any function is listed, follow the implementation steps.
Implementation Steps
Sign in to the Supabase Dashboard at https://supabase.com/dashboard.
Select your project.
Open the SQL Editor in the sidebar.
For each listed function, run: alter function public.<function_name>(<argument types>) set search_path = '';
Update the function body to use fully qualified names (for example, public.orders) if needed.
Test the function and rerun the Security Advisor.
Backout Plan
Sign in to the Supabase Dashboard at https://supabase.com/dashboard.
Select your project.
Open the SQL Editor in the sidebar.
Run: alter function public.<function_name>(<argument types>) reset search_path;
Reference