Guide · November 9, 2026

Supabase Realtime security: lock Broadcast and Presence with private channels

Supabase Realtime has three features. Postgres Changes respects your table RLS: clients only get rows they're allowed to read. Broadcast and Presence are different — on a public channel there is no authorization at all. Any client with your project URL and public anon key that joins the same topic name can listen in and send messages, including fake ones that look like they came from your app.

The fix is Realtime Authorization: RLS policies on realtime.messages plus private channels. (Supabase: Realtime Authorization)

Quick check: search your client code for .channel(. Every Broadcast/Presence channel that carries anything user-specific should have config: { private: true }.

1. Find public channels in your code

grep -rnE "\.channel\(" src app components lib --include=*.{ts,tsx,js,jsx}

Channels created as supabase.channel('room-1') with no private: true are public. Topic names built from ids (chat:${roomId}) don't help much — ids leak through URLs and the network tab.

2. Add RLS policies on realtime.messages

Write one policy for receiving (select) and one for sending (insert). Use realtime.topic() for the channel name and realtime.messages.extension to tell Broadcast from Presence:

create policy "members can receive"
on realtime.messages for select
to authenticated
using (
  exists (
    select 1 from public.rooms_users
    where user_id = (select auth.uid())
      and room_topic = (select realtime.topic())
      and realtime.messages.extension in ('broadcast', 'presence')
  )
);

create policy "members can send"
on realtime.messages for insert
to authenticated
with check (
  exists (
    select 1 from public.rooms_users
    where user_id = (select auth.uid())
      and room_topic = (select realtime.topic())
      and realtime.messages.extension in ('broadcast', 'presence')
  )
);

Don't add alter table realtime.messages enable row level security to a migration. RLS is already on, and the statement fails with 42501 must be owner of table messages, which aborts the rest of the migration — including your policies.

3. Join as private in the client

const channel = supabase.channel('room-1', {
  config: { private: true },
})

4. Turn off public access

Policies alone don't force clients onto private channels. In the Supabase dashboard, open Realtime Settings and disable “Allow public access”. After that, a client that skips private: true can't join.

5. Know the caching gotcha

Realtime caches a client's permissions for the connection. If you remove someone from a room, they keep receiving messages until their JWT expires or a new one is sent. Keep JWT expiry short for apps where that matters.

While you're in RLS

Every policy should name its role with to authenticated — a policy without a TO clause applies to public, which includes logged-out anon users. The Supabase RLS check covers that, USING (true), and privileged columns. Or run the free live-site check to see which tables a stranger can read right now.

The VibePreflight team