Supabase Security Advisor: "Public Can Execute Dynamic SQL Function" (exec_sql) and the 1-line fix
On 17 Nov 2026 Supabase's linter (splinter 2026.11.0) added two security checks: 0031 "Public Can Execute Dynamic SQL Function" and 0032 "Signed-In Users Can Execute Dynamic SQL Function". If your Security Advisor just started showing one, here is what it means and how to fix it.
What it means
The lint "Detects functions callable without signing in that appear to run a SQL string passed in by the caller." The classic case is a helper like this:
create function public.exec_sql(query text) returns json
language plpgsql security definer as $$ ... execute query ... $$;
AI builders and tutorials often add one so an agent or an admin screen can run migrations or reports from the app. The problem, in the lint's own words: "PostgREST exposes them at /rest/v1/rpc/<name>, so anyone with the anon key can run arbitrary SQL as the function owner (SECURITY DEFINER) or as anon (SECURITY INVOKER)."
Your anon key ships in your frontend by design (see is my anon key exposed?), so "anyone with the anon key" means anyone who opens your site. With security definer, RLS does not stop them: they can read, change or delete every table.
Supabase rates it ERROR when the function is security definer and uses the parameter directly in EXECUTE, and WARN otherwise.
30-second check
In the SQL editor:
select p.proname,
p.prosecdef as security_definer,
has_function_privilege('anon', p.oid, 'execute') as anon_can_call,
has_function_privilege('authenticated', p.oid, 'execute') as users_can_call
from pg_proc p join pg_namespace n on n.oid = p.pronamespace
where n.nspname = 'public'
and p.prolang = (select oid from pg_language where lanname = 'plpgsql')
and p.prosrc ilike '%execute%';
Any row with anon_can_call or users_can_call = true that runs text you pass in needs fixing.
The fix
Supabase's first option is to revoke EXECUTE:
revoke execute on function public.exec_sql(text) from anon, authenticated, public;
Revoke from both roles. Supabase's advisor docs warn: "Revoking from anon alone usually leaves the function callable by every signed-up user, so address both together." Server code using your secret key can still call it.
If nothing needs it, drop it: drop function public.exec_sql(text);
If the app really needs it, Supabase's advice: "Expose one function per operation with typed arguments and no string-built SQL. If you have to build SQL, pass values with EXECUTE ... USING, quote identifiers with quote_ident(), and check table and column names against an allow-list."
Don't just rename the function. The check looks at what the function does, and so does anyone probing your API.
After the fix
- Re-run Security Advisor; the finding clears once the grants change.
- If the app now shows
42501 permission deniedwhere it called the function, that call belonged on your server: see 42501 permission denied. - Check what a second account can see with the second-user test.
Known false positive (from Supabase's docs): format('%I', param) is safe but can still be flagged; use quote_ident(param) instead.
Before you launch
The free Ship-Ready quick scan runs offline on your code and flags leaked keys, RLS turned off, using (true) policies and edge functions with verify_jwt = false and no caller check. Since v0.1.8 it also flags functions like exec_sql that anyone can call to run their own SQL (rule SQL-001). It runs locally, no code upload.
Related: Is my anon key exposed? · 42501 permission denied · Retiring the eyJ keys