Public Can Execute SECURITY DEFINER Function
Anyone with your public key can run that function over the web, and it runs with its owner’s permissions, skipping your Row Level Security rules.
What it means
This is a WARN in Supabase’s own Security Advisor (lint 0028_anon_security_definer_function_executable). A sibling lint, 0029, flags the same thing for any signed-in user; fix both together.
A function marked SECURITY DEFINER runs with the permissions of whoever created it, usually an account that skips Row Level Security. Functions in the public schema are served by the API at /rest/v1/rpc/<function name>, so a visitor can call them directly.
Postgres gives everyone permission to run a new function unless that is taken away. Taking it away only from anon is not enough, because anon also gets it through the built-in public group.
Check it yourself
Run this in the Supabase SQL editor. Each row is a SECURITY DEFINER function in the public schema that the anon role can run.
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.prosecdef
and has_function_privilege('anon', p.oid, 'execute')
order by 1;The fix
- 1
Take away permission to run it from both anon and public. Write the function’s argument types in the brackets exactly as the check shows them.
revoke execute on function public.my_priv_op(int, text) from anon, public; - 2
If logged-in users should still be able to call it, give that back to them only. Think about whether they should: the sibling lint 0029 will flag it.
grant execute on function public.my_priv_op(int, text) to authenticated; - 3
If the function does not need owner permissions at all, switch it to run as the caller. Row Level Security then applies to it again.
alter function public.my_priv_op(int, text) security invoker; - 4
Open the function’s /rest/v1/rpc/ address with only the public key. It should now be refused. Then refresh the Security Advisor and run your scanner again.
What can break
A visitor-facing feature that calls the function (a sign-up count, a public form) stops working until you decide how it should work. Rules on your tables that call the function in their condition also fail for roles that lost permission. Revoking from public also removes permission from Supabase’s own internal roles, so if the function is set up as an Auth Hook (for example a custom access token hook), revoking can lock every user out of signing in. Check Authentication, Hooks in the dashboard before you revoke, and keep grant execute ... to supabase_auth_admin for a hook function. Switching to security invoker can make the function return less or fail where a table has no read rule for the caller.
Undo it
To give permission back, run grant execute on function public.my_priv_op(int, text) to anon, public;. To undo step 3, run alter function public.my_priv_op(int, text) security definer;. Both reopen the finding. 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.