PeekLok

Can anyone call my Supabase database functions? An RPC check for Lovable and Bolt apps

Short answer: by default, yes. Supabase's docs say “by default, any role can run a database function,” including anon, the role used when nobody is signed in. That's fine for most functions. It's a problem when a function is marked security definer, because then it skips your Row Level Security and can hand back rows the caller isn't allowed to read. Here are four checks.

Free scan: check my app Just your web address. Results in seconds. No signup, no card.

A database function is a small piece of SQL saved inside your database. Your app calls it with supabase.rpc('name'), and Supabase's API exposes it at /rest/v1/rpc/name. AI builders often add one for things like a dashboard total, a search, or checking a user's role. These are not the same as Edge Functions, which are covered in our Edge Function guide. This guide is for Lovable and Bolt apps connected to your own Supabase project. Lovable's docs say its built-in backend is built on Supabase's open-source foundation, and Bolt's default Bolt Database can be claimed in Supabase. If you're on a built-in backend, ask the AI in the chat to run the checks below for you.

1. Know which functions skip your rules

Postgres runs a function either as the person calling it (security invoker, the default) or as the person who created it (security definer). Supabase's docs warn that a function created in the dashboard or by a migration is owned by postgres, “which bypasses Row Level Security,” and that any role can call it by default, including anon. So a security definer function that reads a table can return every row, even though RLS is on for that table.

Supabase's own notes on this also say that, in a default project, anon and authenticated get the same default access to new functions. So taking access away from anon alone usually still lets every signed-up user call the function. If your app lets anyone sign up, that's nearly the same as public.

2. Look for these findings in the Security Advisor

In your Supabase dashboard, open the Security Advisor. Look for:

Some findings are on purpose, such as a “submit contact form” function. Supabase's notes say a function like that is effectively a public API endpoint, so it should check its inputs and do only one small job.

3. List your security definer functions and who can call them

In the SQL Editor, run this read-only query. It lists every security definer function in your public schema and whether a signed-out visitor (anon) or any signed-in user (authenticated) can call it.

select p.proname as function_name,
       pg_get_function_identity_arguments(p.oid) as arguments,
       has_function_privilege('anon', p.oid, 'execute') as signed_out_can_call,
       has_function_privilege('authenticated', p.oid, 'execute') as signed_in_can_call
from pg_proc p
join pg_namespace n on n.oid = p.pronamespace
where n.nspname = 'public' and p.prosecdef;

For each row where either column says true, ask: what does this function read or change, and should that person be allowed to do it?

4. Check the function checks who's asking

Supabase's docs make a point that's easy to miss: letting only signed-in users call a function “doesn't limit the rows” it gives back. If a security definer function takes a user ID or record ID and returns that record, any signed-in user can ask for someone else's. The function itself has to compare the record's owner with auth.uid(). Test it the same way as our two-user check for Lovable apps: sign in as test user A and call the function with test user B's ID. It should return nothing.

How to fix it

Supabase's docs and Security Advisor give three options for each function:

One warning: some functions are called by your RLS policies, for example a function that checks whether a user is an admin. Supabase's docs say to keep execute for the roles that need those helper functions. If you revoke it from authenticated, signed-in users may suddenly see nothing.

Fix prompt to paste into the Lovable or Bolt chat

List every database function in the public schema of my Supabase database. For each one, tell me whether it is security definer or security invoker, what it reads or changes, whether anon and authenticated can execute it, and whether any RLS policy calls it. For each security definer function: if it doesn't need to bypass RLS, switch it to security invoker. If it must stay security definer, set search_path = '' and use schema-qualified names, check inside the function that any per-user record belongs to auth.uid(), and revoke execute from public and anon (and from authenticated if signed-in users shouldn't call it). Keep execute for authenticated on helper functions that RLS policies use. Don't change functions that are meant to be public without asking me. Show me a table of each function and what you changed.

After the AI makes changes, run the Security Advisor and the query in check 3 again, then repeat check 4 with two test accounts. AI fixes can look right and still miss a function.

What PeekLok's scan checks

PeekLok's scan doesn't call your database functions yet. If your app's public anon key is in your page code, it tries to read your Supabase tables with that key and reports any that return rows, and with two test logins (Supabase login) it checks whether one user can read the other's row in a table you pick. For functions, use the checks above.

Sources

Related

Get a free scan

PeekLok checks your live app for secret keys in the page code, Supabase keys and tables anyone can read with the public key, and five security headers. With two test logins (Supabase login) it also checks whether one user can see the other’s data. It doesn’t test database functions yet, so use the steps above for those. Only scan apps you own. First scan free. Weekly re-checks will be $12 US a month once payments open.

Start my free scan