Abbi Labs

Guides

Supabase RPC functions are callable by anyone with your anon key unless you revoke execute

By Pritesh Ghodge, Senior Solutions Engineer (cybersecurity) · Last updated 16 November 2026

Scan your app free — see what your public Supabase key can reach.

Abbi Labs looks at your live site from the outside: Supabase tables readable with your public key, admin-looking RPC functions visible to it, secret keys in the JavaScript, exposed .env and .git files, source maps, and security headers. No sign-up for the quick check.

No app handy?

No sign-up. Read-only public-resource and protocol metadata checks. No model prompts or tool execution. Scan only sites you own or are allowed to test.

Run on every deploy or use from Cursor / Claude Code via MCP →

Weekly AI-app security checklist

One short email a week: a practical check for apps built with Supabase, Next.js and AI tools (RLS, leaked keys, headers and more). Unsubscribe anytime.

AI builders love Postgres functions. Ask Lovable, Bolt or Cursor for "a function to increment credits" or "an admin function to set a user's role" and you get a create function public.something(...) plus a supabase.rpc('something') call in the frontend. What nobody mentions: that function is now an API endpoint at /rest/v1/rpc/something, and by default anyone with your anon key can call it with whatever arguments they like. RLS doesn't help if the function is security definer, because then it runs as its owner.

Supabase's 30 October 2026 change made new tables opt-in for the Data API (see the 42501 guide). Functions were left as they were. Supabase's own Securing your API page says new functions are callable by every role, because Postgres grants execute to PUBLIC through a global default.

1. List every function anon can execute

Run this in the SQL Editor. It shows each function in public, whether it's security definer, and whether anon and authenticated can execute it (directly or through PUBLIC):

select p.oid::regprocedure as function,
       p.prosecdef as security_definer,
       has_function_privilege('anon', p.oid, 'execute') as anon_can_execute,
       has_function_privilege('authenticated', p.oid, 'execute') as authenticated_can_execute
from pg_proc p
join pg_namespace n on n.oid = p.pronamespace
where n.nspname = 'public'
order by anon_can_execute desc, security_definer desc;

Read the top of the list first. Any row with security_definer = true and anon_can_execute = true is something a signed-out stranger can run with your owner's rights. Open each one and ask: does it check auth.uid()? Does it take a user_id, role, amount or credits parameter the caller controls?

2. Revoke from public AND anon

The common mistake is revoking only from anon. Anon still gets in through PUBLIC. Supabase's database functions guide revokes from both:

revoke execute on function public.set_user_role from public;
revoke execute on function public.set_user_role from anon;
-- only if signed-in users shouldn't call it either:
revoke execute on function public.set_user_role from authenticated;

-- then confirm:
select has_function_privilege('anon', 'public.set_user_role(uuid, text)', 'execute');

The last query should return false. If the function has overloads, use the full signature from step 1.

3. Test from outside

Signed out, with only the anon key your site already ships:

curl -s -X POST "https://<project>.supabase.co/rest/v1/rpc/set_user_role" \
  -H "apikey: <anon key>" -H "Content-Type: application/json" \
  -d '{}'

You want a permission error (42501). A result, or an error about missing arguments, means the function is still callable. Only test your own project.

4. Fix the default for functions you create later

Otherwise the next AI-generated function is open again. Supabase's docs and knowledge base give this, and stress that it must not say in schema public (a schema-scoped default can't remove the global PUBLIC grant, so that version silently does nothing):

alter default privileges for role postgres
  revoke execute on functions from public;

alter default privileges for role postgres in schema public
  revoke all on functions from anon, authenticated, service_role;

Two consequences. Every new function now needs an explicit grant execute ... to authenticated (or anon) if the app calls it. And helper functions that your RLS policies call need execute granted to the roles that run those policies, or the policies start failing. Check pending defaults with:

select defaclrole::regrole as owner, defaclnamespace::regnamespace as schema, defaclacl
from pg_default_acl where defaclobjtype = 'f';

5. If a function must stay callable, guard it inside

Some functions are meant for signed-in users (a "like this post" counter, say). Then the function itself has to do the checking:

A prompt for Lovable, Bolt or Cursor

List every function in the public schema with whether it is security definer and whether anon and authenticated can execute it (use has_function_privilege). For each one the frontend doesn't call while signed out, revoke execute from public and anon. Don't change function bodies. Show me the SQL before applying it.

What an outside scan adds, and what it can't do

Abbi Labs can't read your function bodies or grants, so steps 1 and 2 are on you. From the outside, the scan finds your Supabase URL and anon key in your JavaScript. If your project serves the API description to that key, it reads it (metadata only) and flags admin-looking function names visible to anon, and it flags admin-looking rpc(...) names referenced in your JavaScript. It never calls them. It also checks Supabase tables readable with your public key, secret keys in the JavaScript, exposed .env/.git files, source maps and security headers. For policies, paste them into the free Supabase RLS policy checker (runs in your browser).

Scan your app free

FAQ

Can anyone call my Supabase database functions?

By default, yes. Functions in the public schema are exposed by the Data API at /rest/v1/rpc/<name>, and Supabase's docs say any role can run a database function unless you restrict it. Postgres grants execute to PUBLIC on new functions, and Supabase's defaults also grant execute to anon, authenticated and service_role on functions created in public. Anyone holding your public anon key (it's in your site's JavaScript) can call them.

Did the October 2026 Supabase grants change fix this?

No. From 30 October 2026, new tables and sequences in public no longer get automatic Data API grants. Functions are different: Supabase's Securing your API page says new functions are still callable by every role because Postgres grants execute to PUBLIC through a global default.

Why didn't revoke execute ... from anon work?

Because anon also inherits execute through PUBLIC. Supabase's database functions guide revokes from both: revoke execute on function public.fn from public; and revoke execute on function public.fn from anon;. Check afterwards with has_function_privilege('anon', 'public.fn(...)', 'execute').

Why doesn't alter default privileges in schema public revoke execute on functions from public work?

A schema-scoped default can add privileges but can't remove the global PUBLIC default for functions. Supabase's docs and knowledge base say to run it without in schema: alter default privileges for role postgres revoke execute on functions from public;. That applies to every schema, so grant execute back on helper functions your RLS policies call.

Is a security definer function dangerous?

It runs with the owner's rights (usually postgres), so it skips RLS on whatever it touches. That's fine when it's not callable by anon or authenticated, or when it checks auth.uid() and the caller's role inside. A security definer function that anon can execute and that takes a user_id or role parameter is the classic way a signed-out caller changes data they shouldn't.

Does Abbi Labs check my RPC functions?

Partly, from the outside. The free quick check finds your Supabase URL and anon key in your site's JavaScript. If your project serves the API description to that key, the scan reads it (metadata only) and flags admin-looking function names such as set_role or make_admin that anon can see, plus admin-looking names referenced in your JavaScript. It never calls your functions, so it can't prove what they do. The SQL on this page lists every function anon can execute.

Related guides

Weekly AI-app security checklist

One short email a week: a practical check for apps built with Supabase, Next.js and AI tools (RLS, leaked keys, headers and more). Unsubscribe anytime.