Supabase SECURITY DEFINER functions any visitor can call
Last updated October 24, 2026
Steps
- In the Supabase dashboard, open Advisors and look for the lints "anon security definer function executable" (0028) and "authenticated security definer function executable" (0029).
- List every function with security definer in your migrations or SQL editor history. Ask: does this really need to bypass RLS? Supabase recommends security invoker, which is the default.
- Switch functions that don't need elevated rights to security invoker so your RLS policies apply.
- For functions that must stay security definer: set search_path = '' and name the schema for every table (public.orders), as Supabase's docs require.
- Inside the function, check ownership (for example compare the row's user_id to auth.uid()). Supabase notes that an execute grant controls who can call the function, not which rows they get back.
- Revoke execute from public and anon (and from authenticated where it isn't needed), then grant it only to the roles that need it. Change default privileges so new functions aren't callable by everyone.
- Test it: call the function with the anon key and no session, then as a second signed-in user. Neither should see someone else's rows.
Why it matters
Supabase's database functions guide says a security definer function can return rows the caller isn't allowed to read, that functions created in the dashboard or by migrations are owned by postgres (which bypasses RLS), and that any role, including anon, can call a function by default. Pinning the search_path doesn't change who can call it. Turning RLS on for your tables doesn't help if a function quietly goes around it.
Sources
Supabase Docs: Database functions (Secure a database function, Function privileges) — https://supabase.com/docs/guides/database/functions
Supabase Docs: Database advisors (lints 0028 and 0029) — https://supabase.com/docs/guides/database/database-advisors
Related patterns
Found a problem you'd rather not fix yourself?
Tell us what's wrong. A StorenTech engineer reviews your app and replies with a fixed quote, so you know the cost before any work starts.
Get it fixed by StorenTechVibe Security Weekly
One email a week with new failure patterns and how to fix them.
By joining you agree we may email you this newsletter. See our privacy policy. Free. Unsubscribe anytime. We'll never sell your email.