The REVOKE that didn't revoke
Platform defaults are part of your security posture. After you lock something down, check who can actually reach it.
- In code review I caught a SECURITY DEFINER function exposed to every logged-in user, letting them skip ~200 lines of app validation.
- The REVOKE meant to lock it down left it callable by anyone on the internet for about three days, because Supabase grants EXECUTE to the anon role by default and REVOKE … FROM PUBLIC doesn't remove that grant.
- The correction revoked anon too. I now check every role, and the Supabase security advisor later caught five more functions with the same grant.
The hole I caught
ReadySetBind has one step that matters more than the rest: moving an insurance placement a human underwriter just verified forward to signing (the pending_verification → signing transition, plus the correction records that ride along with it). The app does this through record_verification, a Postgres SECURITY DEFINER function. That means it runs with its owner's privileges instead of the caller's, so it can write tables the caller isn't allowed to touch directly. The route that calls it runs about two hundred lines of validation first.
In code review I found record_verification granted to authenticated, the role every logged-in user gets. Supabase exposes functions like that over its REST API, so any agency member could call supabase.rpc('record_verification', …), a remote procedure call that invokes the database function directly, and force whatever state transition they wanted. The validation wasn't a gate. It was a suggestion you could decline.
I caught it before merge, with no real placements touched, and hardened it. I revoked the function from regular users, restricted it to the service role (the backend's own identity), added an explicit p_verified_by argument the route has to vouch for, and put a membership re-check inside the function itself.
The fix that wasn't a fix
The hardening migration ran REVOKE EXECUTE … FROM PUBLIC, authenticated. It looked complete. But on every new function, Supabase by default grants EXECUTE (the privilege to run a function) directly to anon, the role used for requests with no login at all. Revoking from PUBLIC only removes the PUBLIC grant. The grant made directly to anon survives.
So I revoked the two roles I was thinking about and left the one I wasn't. For about three days the newly "locked-down" verify primitive was callable by anyone on the internet through POST /rest/v1/rpc/record_verification, no account required. That was worse than the hole I'd just closed.
My verification query waved it through. The hole I'd found was about logged-in users, so the query asked one question, has_function_privilege('authenticated', …), which amounts to "can logged-in users still call this?" The answer was no, the check went green, and I moved on. I never asked the same question about anon.
What actually worked
REVOKE EXECUTE … FROM PUBLIC, authenticated;REVOKE EXECUTE … FROM anon;the gapThe first revoke left the default anon grant in place. The correction revokes anon too.
I found the gap about three days later, while working on something else. I was extending the same function for a new feature, and the authorization review for that change showed record_verification still had EXECUTE granted to anon. The correction migration revokes it, and this time the check confirmed that only the service role could call the function.
Here is what came out of it, in a form you can copy into your own Supabase project. Swap my_function(uuid) for your function's signature.
1. Revoke from all three roles by name
REVOKE EXECUTE ON FUNCTION my_function(uuid) FROM PUBLIC, anon, authenticated;
GRANT EXECUTE ON FUNCTION my_function(uuid) TO service_role;
Supabase grants EXECUTE to both anon and authenticated when a function is created, so a function that only the backend should call needs all three named in the revoke.
2. Check all three roles
SELECT
has_function_privilege('anon', oid, 'EXECUTE') AS anon_exec, -- expect false
has_function_privilege('authenticated', oid, 'EXECUTE') AS authenticated_exec, -- expect false
has_function_privilege('service_role', oid, 'EXECUTE') AS service_role_exec -- expect true
FROM pg_proc WHERE oid = 'my_function(uuid)'::regprocedure;
This is the query I should have run the first time. Mine asked about one role.
3. Audit every function you already have
SELECT proname, proacl
FROM pg_proc
WHERE prosecdef AND pronamespace = 'public'::regnamespace;
-- For every service-role-only function, `anon=` should be absent from proacl.
prosecdef selects the SECURITY DEFINER functions, and proacl lists who holds a grant on each one. Any function locked down with the incomplete revoke will show up here.
4. Keep the check as a test
BEGIN;
DO $$
BEGIN
ASSERT has_function_privilege(
'anon', 'my_function(uuid)', 'EXECUTE'
) = false, 'anon must NOT have EXECUTE';
ASSERT has_function_privilege(
'authenticated', 'my_function(uuid)', 'EXECUTE'
) = false, 'authenticated must NOT have EXECUTE';
ASSERT has_function_privilege(
'service_role', 'my_function(uuid)', 'EXECUTE'
) = true, 'service_role MUST have EXECUTE';
RAISE NOTICE 'ALL PRIVILEGE ASSERTIONS PASSED';
END $$;
ROLLBACK;
Later functions in the project ship with a test like this. It runs against the linked database with supabase db execute --file <test>.sql --linked and rolls itself back, so it leaves nothing behind. The project has no SQL test runner in CI, so I run it by hand.
5. Run the Supabase security advisor
I wrote all of this down as a rule after the correction, and the project already lived by the table-level version, where every table gets row-level security (the database filters rows per user). But nothing enforced the function rule. A month later the Supabase security advisor flagged five more functions with the same anon grant under its lint 0028 (anon-executable SECURITY DEFINER functions), and one migration fixed them. I now run the advisor after any migration that creates or changes a function.
Verify the state, not the action
Memorizing the Supabase default won't help much. Defaults change, and the next platform will have a different one. What went wrong is that I checked my action ("I revoked access") when what I cared about was the resulting state ("nobody unauthorized can call this"). This class of bug lives in the gap between those two claims.
In an assessment I'd file this as a configuration-baseline finding: the platform did something on my behalf that my threat model never accounted for. As a builder the rule is shorter. When a platform does something for you automatically, assume it also did something you didn't ask for.