Skip to content

Revoke anon and public EXECUTE on three invoker notification RPCs #755

Closed

Description

@HMarzban

Summary

On 2026-11-10, anon could run three SECURITY INVOKER notification RPCs on production: get_channel_notif_state, get_unread_notifications_paginated and get_workspace_notifications. The maintainer ruled the fix on #327 the same day. It is not built. The newest migration at HEAD 0b302b222 is 20261103120000.

This issue ships one paired change: packages/supabase/scripts/ plus one migration. It grants EXECUTE to authenticated and revokes it from anon and public. Part of #327. Priority P1.

Accepted: service_role may lose EXECUTE on the three RPCs (ruling 2026-11-11). It is recorded as a control column, with no bar.

Push by . The maintainer sets the date. Recommended: before 2026-11-15, so the #325 window can start after a clean 24 h.

Order. Push #755. Wait for a clean 24 h GlitchTip read (the Guard). Then start the #325 reset and the #324 window. The #325 window bans any db push. It must also land before the #322 baseline.

Why

Result of the read-only check, 2026-11-10, production SQL editor (#327 comment):

Function anon authenticated
get_channel_notif_state true true
get_unread_notifications_paginated true true
get_workspace_notifications true true
  • All three are SECURITY INVOKER, because none sets a security clause (packages/supabase/scripts/10-functions.sql:552 and :711, packages/supabase/scripts/07-1-notification-functions.sql:20).
  • has_function_privilege('anon', …) is true through the PUBLIC grant. So the revoke must name public too.
  • packages/supabase/scripts/check-grants.sql never covers invoker functions (packages/supabase/CLAUDE.md). Its clean production run on 2026-11-03 says nothing about these three.
  • What anon gets back from each call is not measured yet. The fix does not depend on it.

Callers, read from code on 2026-11-10:

  • get_channel_notif_state: apps/webapp/src/components/chatroom/hooks/useNotificationToggle.ts. The query runs only with a signed-in userId (enabled: Boolean(channelId && userId)).
  • get_unread_notifications_paginated: apps/webapp/src/components/notificationPanel/feed/useNotificationPanelFeed.ts. Every call returns early without a userId.
  • get_workspace_notifications: only apps/webapp/src/api/notification/getLastReadNotification.ts. Nothing imports that wrapper except the api/notification barrel, so it has no live caller.
  • No other app, extension or package calls them. apps/webapp/cypress/support/chatroomFixtures.ts stubs them.

So no signed-out path breaks when anon loses EXECUTE.

Maintainer ruling, 2026-11-10 (copied from #327)

On the three SECURITY INVOKER RPCs with browser callers: get_unread_notifications_paginated, get_channel_notif_state and get_workspace_notifications. Answer: "agree".

The deeper look, read from code and not checked on production:

  • All three are SECURITY INVOKER, because none sets a security clause (packages/supabase/scripts/10-functions.sql:552 and :711, packages/supabase/scripts/07-1-notification-functions.sql:20).
  • The local seed grants all three to authenticated through the user_facing_names list in packages/supabase/scripts/29-lint-hardening.sql §6.
  • packages/supabase/scripts/check-grants.sql does not cover invoker functions. So its clean production run on 2026-11-03 says nothing about these three.

The ruling:

  1. First, run one read-only has_function_privilege query on production, for anon and authenticated, on each of the three.
  2. If anon can run any of them, add one paired change in scripts/ and a migration: grant EXECUTE to authenticated, and revoke it from anon and public.
  3. If anon cannot, close this item as covered.

Notes for the builder (copied from #327, 2026-11-10)

  • The functions are SECURITY INVOKER, so the revoke must name public too. has_function_privilege('anon', …) is also true through the PUBLIC grant.
  • The grant to authenticated already sits in 29-lint-hardening.sql §6. The migration must carry it too, because production never ran the local sweep.
  • Run packages/supabase/scripts/check-grants.sql and this same query on production after the push. Expect anon false and authenticated true on all three.
  • get_workspace_notifications has no live caller. Dropping it with its wrapper is a separate question. It is not part of this change.

What to change

  1. Agent in the repo. Check the base: ls packages/supabase/migrations | tail -1 prints 20261103120000_email_payload_drop_document_slug.sql. If a newer migration exists, read it first.

  2. Agent in the repo. In packages/supabase/scripts/10-functions.sql, beside the named invoker grants (:922-928), add for the two functions defined in that file:

    revoke execute on function public.get_unread_notifications_paginated(character varying, text, integer, integer) from public, anon;
    grant execute on function public.get_unread_notifications_paginated(character varying, text, integer, integer) to authenticated;
    revoke execute on function public.get_channel_notif_state(character varying) from public, anon;
    grant execute on function public.get_channel_notif_state(character varying) to authenticated;
  3. Agent in the repo. In packages/supabase/scripts/07-1-notification-functions.sql, after the ALTER FUNCTION at :129, add the same pair for public.get_workspace_notifications(uuid, character varying, integer, integer, boolean).

  4. Agent in the repo. Add one migration, packages/supabase/migrations/<timestamp>_revoke_anon_invoker_notification_rpcs.sql, with the same six statements. End it with a DO block that raises an exception if anon can still run any of the three, or authenticated cannot. The block does not assert on service_role. Copy the assert shape of migration 20261014121000.

  5. Agent in the repo. Apply it locally without a reset:

    docker exec -i supabase_db_docsplus_supabase psql -U postgres -d postgres < packages/supabase/migrations/<timestamp>_revoke_anon_invoker_notification_rpcs.sql

    Run the query in the Benchmark section locally. Expect anon false and authenticated true on all three.

  6. Agent in the repo. Run bun run --filter @docs.plus/supabase_back check (functions parity and grant allowlists). Run bun run --filter @docs.plus/supabase_back types and include any change to apps/webapp/src/types/supabase.ts in the same change. Do not edit packages/supabase/seed.sql. Ask the maintainer whether this change regenerates it.

  7. Agent in the repo. Local UX check, signed in: open the notification panel and toggle chat notifications on a scratch pad you created. As a guest, open that pad's chat and read only. The console shows no 401, 403 or 42501. Delete the scratch pad after. Then stop at a review checkpoint.

  8. Maintainer. Commit through the commit-review skill. Before the push, run the Benchmark query read-only, with its service_role column, and post it here as the before. This before can only be read before the push. Also run packages/supabase/scripts/check-grants.sql read-only as a baseline. Follow packages/supabase/CLAUDE.md §db push history divergence: run bunx supabase migration list first. Then push this one migration.

  9. Maintainer. After the push, run check-grants.sql and the Benchmark query on production, read-only. Post a Measured comment here and tick the row on [Tracking] Supabase prod security and performance review, 2026-09-28 #327.

Benchmark

Field Value
Metric Notification RPCs that anon can EXECUTE on production, out of 3 (has_function_privilege). Control: RPCs that authenticated can EXECUTE, out of 3. Control: RPCs that service_role can EXECUTE, out of 3, recorded only
Before anon 3 of 3, authenticated 3 of 3. Read 2026-11-10, production SQL editor, #327 comment. service_role: not read yet. The maintainer reads it before the push (step 8)
After not measured yet
Condition Supabase production project, Postgres 15.8 (before #322). Read-only SQL editor session, within 1 hour of the push
How to run select p.proname, has_function_privilege('anon', p.oid, 'EXECUTE') as anon, has_function_privilege('authenticated', p.oid, 'EXECUTE') as authenticated, has_function_privilege('service_role', p.oid, 'EXECUTE') as service_role from pg_proc p join pg_namespace n on n.oid = p.pronamespace where n.nspname = 'public' and p.proname in ('get_channel_notif_state', 'get_unread_notifications_paginated', 'get_workspace_notifications') order by 1; Then packages/supabase/scripts/check-grants.sql
Pass rule anon 0 of 3, authenticated 3 of 3, and check-grants.sql returns 0 rows. service_role: recorded before and after, no bar. Stop rule: if authenticated reads false on any row, or a signed-in user gets 42501 or 403 from one of the three, push a fix migration that grants authenticated again, the same day. A fix push restarts the clean 24 h before the #325 reset may start. Never grant anon back without a maintainer ruling
Guard Step 7 UX check, again on production after the push. GlitchTip shows no new 42501 or permission denied for function event in 24 h
Owner Steps 1-7: agent in the repo. Steps 8-9: maintainer
Claim Security ledger: "Signed-out visitors can no longer call 3 of 3 notification functions on the docs.plus production database: 3 → 0, verified ."

Out of scope

  • Dropping get_workspace_notifications and its wrapper.
  • A check-grants.sql arm for invoker functions. refuse_connected_app_request and hook_block_password_tokens are invoker on purpose, and revoking anon from the first fails every Data API request (packages/supabase/CLAUDE.md).

Related

#327 (parent tracker; its ledger row "Notification RPCs anon can EXECUTE"). #325 and #324 (push before their windows start). #322 (push before its baseline). #570 (pgmq and storage default rights).

Activity

  1. added this to the v2.3.6 milestone on Nov 11, 2026
  2. added
    Security
    on Nov 11, 2026
  3. HMarzban commented on Nov 11, 2026

    @HMarzban
    CollaboratorAuthor

    Maintainer ruling, 2026-11-11

    Accept that revoking EXECUTE from public may also remove it from service_role on the three RPCs. No server code calls them; the only callers are signed-in webapp hooks and a Cypress stub. Add service_role as a control column in the before and after read, so the change is recorded. The migration still lands before the #325 reset.

  4. HMarzban commented on Nov 12, 2026

    @HMarzban
    CollaboratorAuthor

    Measured, 2026-11-12: production after the push.

    The maintainer pushed migration 20261112120000 to production on 2026-11-12 (supabase db push --remote; it was the only pending migration). The migration's own assert block passed inside production. Read-only read in the Dashboard SQL Editor afterwards (prod-read.sql, query 1):

    Function anon authenticated service_role
    get_channel_notif_state false true true
    get_unread_notifications_paginated false true true
    get_workspace_notifications false true true
    Metric Before (2026-11-10) After (2026-11-12)
    RPCs anon can EXECUTE 3 of 3 0 of 3
    RPCs authenticated can EXECUTE 3 of 3 3 of 3
    service_role (recorded, no bar) 3 of 3 3 of 3
    scripts/check-grants.sql rows baseline 0 (pass)

    service_role kept EXECUTE, so the accepted loss in the 2026-11-11 ruling did not happen. The commit is fbff54d6d, deployed with d4f80009c.

    Left before close: a clean 24 h GlitchTip read (no 42501 from a live signed-in session) on 2026-11-13.

  5. HMarzban commented on Nov 13, 2026

    @HMarzban
    CollaboratorAuthor

    Measured, 2026-11-13: clean 24 h GlitchTip read

    Result. 0 events contain 42501 in GlitchTip, from 2026-11-12 13:00Z to 2026-11-13 14:35Z. That window starts before the migration push and runs past 24 h. So no signed-in session lost access to the three notification functions.

    How. Read-only SQL on the GlitchTip database: every event with timestamp >= '2026-11-12 13:00Z' whose payload text contains 42501. Both browser and server events were in scope.

    The Guard holds, and the pass rule was met on 2026-11-12 (anon 0 of 3, authenticated 3 of 3, check-grants.sql 0 rows). Closing this issue. The #325 reset and the #324 window may start from here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Security

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions