Case study: the ImpactMojo fix that was live but not in git
#supabase#migrations#security-definer#case-study
ImpactMojo's repository created a SECURITY DEFINER function, notify_user(), that anyone could call to put a notification with any link into any member's inbox. We reported it privately. The live database turned out to be safe: the team had revoked the function in August. But the migration that did it was never committed, so every database built from the repository would have come up with the hole open again. The fix was to commit what production already had.
We reported this on November 13, 2026. Varna Sri Raman, founder of PinPoint Ventures, which builds ImpactMojo, replied on November 21, checked production, and opened pull request #1418 the same day. This write-up is published with her permission. ImpactMojo is at impactmojo.in.
What ImpactMojo does
ImpactMojo is free, open-source development education for South Asia: courses, hands-on labs, a browser game library and research tools. Members sign in, take courses, earn certificates and get notifications in an in-app inbox. The notifications are created by Supabase Edge Functions, through a database function.
What the repository showed
The function, from supabase/migrations/20260320_cohorts_and_notifications.sql:
-- NOTIFICATION HELPER: Insert notification for a user
-- Callable from Edge Functions via service role
create or replace function public.notify_user(
p_user_id uuid,
p_type text,
p_title text,
p_body text default null,
p_link text default null,
p_metadata jsonb default '{}'
)
returns uuid as $$
-- inserts (p_user_id, p_type, p_title, p_body, p_link, p_metadata)
-- into public.notifications and returns the new id
$$ language plpgsql security definer;
The comment says what the function was for: Edge Functions, calling with the service role. But nothing in the repository limited it to that. Postgres grants EXECUTE on every new function to PUBLIC, which anon and authenticated inherit, so as written the function was callable by anyone through /rest/v1/rpc/notify_user. It runs as its owner, so it skips the RLS on notifications, and it writes to whatever p_user_id the caller passes. Someone could send every member a message with a link of their choosing, delivered inside a trusted app. That's a phishing channel.
What production showed
When Varna checked the live database, notify_user() could be executed by postgres and service_role only. The team had closed it on August 19, 2026, along with eight other definer functions, in a migration recorded in the database's history as version 20260819110149. The file for that migration never made it into the repository.
So our report was right about the repository and out of date about the live site. That gap is the real lesson here, because a lot of things are built from the repository rather than from production:
- a new environment, like a staging project or a second region
- a local stack after
supabase db reset - a Supabase branch, which runs the repository's migrations
- a rebuild after an incident, or a project someone forks to start their own
Each of those would have come up with notify_user() open, and nothing would have looked wrong.
One correction to our report, which Varna pointed out: we wrote that anonymous visitors could read member ids from profiles. They can't; anon has no select on that table. Someone would have needed an account before they could target other members.
How it was fixed
Production needed no change. PR #1418 makes the repository match it:
- The missing migration, committed under its original version. It revokes
EXECUTEfromPUBLIC,anonandauthenticatedonnotify_userand the eight other functions, then grantsnotify_userback toservice_roleonly. Each statement is guarded withto_regprocedure, so a fresh build doesn't stop on a function that a later migration creates. - A repeat of the revoke in the later migration that creates
update_streak, so a fresh build ends in the same state as production. - A comment above
notify_userpointing to the migration that locks it down. - A changelog entry crediting the report.
The shape of the committed migration, simplified:
do $$
declare sig text;
begin
foreach sig in array array[
'public.notify_user(uuid, text, text, text, text, jsonb)'
-- ...and the other definer functions
] loop
if to_regprocedure(sig) is not null then
execute format('revoke execute on function %s from public, anon, authenticated', sig);
end if;
end loop;
if to_regprocedure('public.notify_user(uuid, text, text, text, text, jsonb)') is not null then
grant execute on function public.notify_user(uuid, text, text, text, text, jsonb) to service_role;
end if;
end $$;
Revoking from all three roles is the safe default. On some projects anon and authenticated only inherit EXECUTE through PUBLIC. On others, Supabase's default privileges also grant it to them directly, and then a revoke from PUBLIC alone leaves the function open; the Kagelin case study is that case.
Is my repository out of sync with production?
Migrations applied but never committed. With the CLI linked to your project, list both sides:
supabase migration list --remote
A version with a value under REMOTE and nothing under LOCAL was applied to the project but isn't in supabase/migrations. That's exactly what ImpactMojo's 20260819110149 would have shown. (Older CLI versions spell the flag --linked.)
Changes made in the SQL editor. These leave no entry in the migration history, so the list above can't see them. For permissions, which is where drift hurts most, run the same query on production and on a local database freshly built from your migrations (supabase db reset), and compare:
select p.oid::regprocedure as function,
has_function_privilege('anon', p.oid, 'execute') as anon_can_run,
has_function_privilege('authenticated', p.oid, 'execute') as authenticated_can_run
from pg_proc p
join pg_namespace n on n.oid = p.pronamespace
where n.nspname = 'public' and p.prosecdef
order by 1;
Any row that differs is a fix that lives in only one place. The same comparison works for tables: select relname, relrowsecurity from pg_class where relnamespace = 'public'::regnamespace and relkind = 'r';
The habit that prevents it: whenever you fix something in the dashboard or SQL editor, put the same SQL in a migration file the same day, and commit it.
Does GuardLayer catch this?
Yes, from both sides. The code scan reads the repository, so before PR #1418 it flags notify_user() as a SECURITY DEFINER function that anon can call and that never checks who is calling. With the committed migration in place, the finding clears: the scanner reads the guarded revoke loop. Live check reads the running project's real grants instead, so on a production database like ImpactMojo's, where the function is already revoked, it isn't flagged.
When the two disagree, that disagreement is the drift. Running both is how you find a fix that only exists in one place. For how common the underlying pattern is, see our study of 844 Supabase projects: 19% had at least one definer function anyone could call.
FAQ
If production is fixed, why does the repository matter? Because new databases are built from it: staging, branches, local stacks and rebuilds. A fix that only exists in production disappears the next time you build from the repository.
How do I find migrations that were applied but never committed?
Run supabase migration list --remote. A version listed under REMOTE but not LOCAL was applied to the project without a file in supabase/migrations.
Do SQL editor changes show up in supabase migration list?
No. They leave no history entry. Compare the state itself instead, for example function grants and RLS flags on production against a fresh local build.
Is revoke ... from public enough for a definer function?
Not always. Revoke from public, anon and authenticated, then grant back only the role that should call it, such as service_role.
See which of your Supabase tables anyone can read, free
Connect your Supabase project read-only. GuardLayer checks RLS, policies, grants and functions as they are right now, and gives you the SQL to fix each problem. It never reads your rows and can't change anything.
Check my Supabase projectPrefer to check code instead? Scan your repo, no signup.