Skip to content
All rules

SB-RPC-DEFINER

SECURITY DEFINER function callable by anyone

Severity
Medium
Confidence
Medium (to verify)
Stack
Supabase
Runs
On by default

What the CLI looks for

A SECURITY DEFINER function that never checks auth.uid() and is not revoked from anon and public.

Why it matters

SECURITY DEFINER runs with the privileges of the function owner, which usually bypasses RLS. Functions in the public schema can be called through the API with the anon key.

How to fix it

Revoke execution from anon and public, grant it only to the roles that need it, check the caller inside the function and pin the search_path.

revoke execute on function public.admin_stats() from anon, public;
grant execute on function public.admin_stats() to authenticated;

-- Inside the function body:
--   if (select auth.uid()) is null then raise exception 'not allowed'; end if;
alter function public.admin_stats() set search_path = '';