realtime icon indicating copy to clipboard operation
realtime copied to clipboard

Filtered postgres_changes fail with "permission denied for function check_equality_op"

Open Ruud14 opened this issue 4 months ago • 2 comments

Bug report

  • [x] I confirm this is a bug with Supabase, not with my own application.
  • [x] I confirm I have searched the Docs, GitHub Discussions, and Discord.

Describe the bug

Tenant migration 20260616120000_add_postgrest_filter_ops (re-applied by 20260626120000_readd_postgrest_filter_ops) introduces a new 5-arg overload of realtime.check_equality_op(op, type_, val_1, val_2, negate) sourced from walrus_migration_0015 (supabase/walrus#81). The migration creates the function with no GRANT statements, so it only receives default privileges (postgres, dashboard_user).

The old 4-arg overload has EXECUTE for anon, authenticated, service_role, and PUBLIC, but realtime.is_visible_through_filters now calls the 5-arg overload (negate := coalesce(f.negate, false)). When realtime.apply_rls evaluates filters while impersonating the subscriber's role, the call is denied and the whole list_changes poll fails:

PoolingReplicationError: %Postgrex.Error{
  postgres: %{
    code: :insufficient_privilege,
    pg_code: "42501",
    message: "permission denied for function check_equality_op",
    where: "SQL function \"is_visible_through_filters\" statement 1
            PL/pgSQL function realtime.apply_rls(jsonb,integer) line 191 at FOR over SELECT
rows
            SQL function \"list_changes\" statement 1"
  }
}

Because the batch is retried and keeps failing, no subscriber on the affected table receives events while the condition holds.

To Reproduce

  1. Hosted project with realtime migrations ≥ 20260626120000 applied.
  2. Enable RLS on a table and add it to the realtime publication.
  3. Open more than 10 postgres_changes subscriptions on that table as authenticated, each with a filter (e.g. filter: 'user=eq.<uuid>').
  4. INSERT or UPDATE a row.
  5. Realtime logs show the PoolingReplicationError above; no subscriber receives the event. With ≤10 subscriptions, everything works.

Expected behavior

The 5-arg overload should carry the same grants as the 4-arg overload it supersedes. Hosted users cannot fix this themselves: the function is owned by supabase_admin and postgres has EXECUTE without grant option.

Screenshots

Image

System information

  • Hosted Supabase (cloud), realtime tenant migrations through 20260626120000 (applied to our project 2026-07-02)
    • Affects: Realtime postgres_changes with server-side filters
    • Observed continuously since 2026-07-02

Ruud14 avatar Jul 05 '26 12:07 Ruud14

Hi @Ruud14 thanks for the report. A fix is available on main now.

leandrocp avatar Jul 06 '26 13:07 leandrocp

:tada: This issue has been resolved in version 2.112.5 :tada:

The release is available on GitHub release

Your semantic-release bot :package::rocket:

realtime-release-bot avatar Jul 06 '26 13:07 realtime-release-bot