Deutsch
GuideSupabase · Realtime

Supabase Realtime security: who can listen to what

How to keep Supabase Realtime private: RLS for Postgres Changes, private channels and policies on realtime.messages for Broadcast and Presence, with tested SQL.

By Tim GeithnerPublished 6 min read

Short answer

Supabase Realtime has two kinds of security. Postgres Changes only delivers inserts and updates a subscriber’s role is allowed to read, so the RLS of the table is what protects it. Broadcast and Presence are protected by Realtime Authorization: use private channels, add select and insert policies on realtime.messages that check membership against realtime.topic(), and turn off public access in the Realtime settings so nobody can fall back to an open channel.

Ask an AI about this page:ChatGPTClaude

On this page

Key takeaways

  • Postgres Changes follows the RLS of the table you subscribe to. A table without RLS, or with using (true), streams every row to every subscriber.
  • Delete events skip RLS. With RLS on, they carry only the primary key, so keep secrets out of primary keys.
  • Broadcast and Presence are only protected on private channels with policies on realtime.messages.
  • Turn off “Allow public access” in the Realtime settings, or clients can simply use a public channel.
  • Policies are checked when a user joins and cached for the connection. Removing someone takes effect on reconnect.

Two features, two kinds of security

Supabase Realtime is what makes chat, live cursors and “someone is typing” work. It offers three features that look alike in client code but are protected very differently:

FeatureWhat it sendsWhat protects it
Postgres Changesinserts, updates and deletes in your tablesthe RLS policies of the table
Broadcastmessages clients (or the database) send to a topicpolicies on realtime.messages, private channels only
Presencewho is online in a topicpolicies on realtime.messages, private channels only

If you only remember one thing: Postgres Changes is as safe as your table’s row level security, and Broadcast and Presence are as open as a public chat room unless you set up Realtime Authorization.

Postgres Changes: your table’s RLS decides

Here is a typical chat in an AI-built app: messages belong to rooms, and only members of a room should see them.

The chat tables
create table public.chat_messages (
  id bigint generated always as identity primary key,
  room_id uuid not null,
  user_id uuid not null default auth.uid(),
  body text not null
);
create table public.room_members (
  room_id uuid not null,
  user_id uuid not null,
  room_topic text generated always as ('room:' || room_id::text) stored,
  primary key (room_id, user_id)
);
alter table public.room_members enable row level security;
create policy "Members see their memberships" on public.room_members for select
  to authenticated using ((select auth.uid()) = user_id);

To receive changes, the table must be part of the supabase_realtime publication:

Publish the table to Realtime
alter publication supabase_realtime add table public.chat_messages;

Supabase’s docs say Realtime sends an insert or update only to a subscriber whose role can read the row, and it checks the policy as that user, using the access token the client sent. That is good news and a trap at the same time: chat_messages above has no RLS, so every signed-in user can read every row, and Realtime will stream every message of every room to them. The docs make the same point about using (true): such a policy sends every row to every signed-in user. If policies are new to you, the Supabase row level security guide covers the basics.

This query lists every table that Realtime publishes without RLS:

Published tables without RLS
select p.schemaname, p.tablename
from pg_publication_tables p
join pg_namespace n on n.nspname = p.schemaname
join pg_class c on c.relnamespace = n.oid and c.relname = p.tablename
where p.pubname = 'supabase_realtime'
  and not c.relrowsecurity;

The fix is the same policy you would write for normal reads:

SafeOnly room members can read messages
alter table public.chat_messages enable row level security;

create policy "Room members can read messages"
  on public.chat_messages for select
  to authenticated
  using (
    exists (
      select 1 from public.room_members m
      where m.room_id = chat_messages.room_id
        and m.user_id = (select auth.uid())
    )
  );

In our test, the room member read the message, a signed-in non-member and a visitor got nothing, and the check query came back empty. Since Realtime checks every event against each subscriber, Supabase recommends keeping these policies cheap and indexed: an index on room_members (user_id, room_id) is worth adding for busy rooms.

Broadcast and Presence: private channels and realtime.messages

Broadcast and Presence don’t read your tables, so table policies can’t protect them. Supabase’s Broadcast docs are explicit that on a public channel anyone can subscribe without authentication. Realtime Authorization closes that with three pieces.

1. Policies on realtime.messages. Realtime uses this table to decide who may join a topic. select lets a user receive, insert lets them send. realtime.topic() returns the topic the user is trying to join, and the extension column says whether the check is for broadcast or presence:

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

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

The generated room_topic column makes the comparison a plain equality, which is the shape Supabase’s own examples use. In our test, a member could join room:<id> and send, a non-member could do neither, and the member could not join a different room’s topic.

2. Private channels in the client. The policies only apply when the client asks for a private channel:

Client (sketch)
const channel = supabase.channel(`room:${roomId}`, {
  config: { private: true },
});
channel.on("broadcast", { event: "typing" }, handleTyping).subscribe();

3. No public fallback. As long as public channels are allowed, nothing stops a client from opening the same topic without private: true. Supabase says that to enforce private channels you have to disable “Allow public access” in the Realtime settings. Do it once your app only uses private channels.

Three details that surprise people

Joins are checked once. Supabase’s docs say the policies are evaluated when the user connects and cached for the duration of the connection. If you remove someone from a room, they keep receiving until they reconnect. For sensitive rooms, have the client close and reopen the channel when membership changes, and keep the access token lifetime short.

Membership tables need their own protection. Every policy above trusts room_members. If users can insert themselves into any room, the policies protect nothing. In our test, a signed-in user’s attempt to add themselves failed because the table has RLS and no insert policy. Add members through an invite flow on the server.

Presence shows what clients track. Whatever a client passes to track() is visible to everyone else in the channel. Track a user ID and a display name, not e-mail addresses or anything only the user should see. The policies decide who is in the room; they don’t filter what members share with each other.

Database broadcasts are private by default. If you send messages from the database with realtime.send or realtime.broadcast_changes, Supabase’s docs say they are private unless you choose otherwise, and a private broadcast only reaches private channels. You still need the select policy above so the right users can receive them.

For shared data in general, the multi-tenant data isolation guide covers membership checks in depth, and our guide on testing RLS policies shows how to check what each user really gets.

A fix prompt for your AI builder

Lock down Supabase Realtime

Review how this project uses Supabase Realtime.

  1. List every table in the supabase_realtime publication and every client subscription to postgres_changes. For each table, show its RLS status and select policies. Enable RLS where it is missing and add select policies so that only users who may see a row receive it (for chat: members of the row’s room). Never use using (true) on a published table with private data.
  2. List every Broadcast and Presence channel. Open each one as a private channel (config option private set to true) and add policies on realtime.messages for the authenticated role: select to receive and insert to send, both checking membership with (select realtime.topic()) and realtime.messages.extension in (‘broadcast’, ‘presence’).
  3. Make sure users cannot insert themselves into membership tables from the client.

Afterwards, remind me to turn off “Allow public access” in the Realtime settings. Show me the migration before applying it.

Frequently asked questions

Does Supabase Realtime respect row level security?

For Postgres Changes, yes: Realtime sends an insert or update only to subscribers whose role can read the row. Delete events are the exception, because a deleted row can’t be checked; with RLS on, they only carry the primary key. Broadcast and Presence don’t read tables, so they need Realtime Authorization instead.

What is a private channel in Supabase Realtime?

A channel the client opens with config private: true. Realtime then checks the RLS policies on realtime.messages before letting the user join, send or track presence. To stop clients from using public channels instead, turn off ‘Allow public access’ in the Realtime settings.

If I remove a user from a room, are they kicked out of the channel?

Not immediately. Realtime checks the policies when the user connects and caches the result for the duration of the connection. Removing the membership takes effect when they reconnect, so design for that delay or close the connection from the client.

Can anyone with my anon key listen to my Realtime channels?

On public channels, yes: Supabase’s docs say anyone can subscribe to a public topic without authentication. Private channels require a signed-in user who passes your policies.

Sources

  1. 1.Realtime Authorization — Supabase Docs
  2. 2.Postgres Changes — Supabase Docs
  3. 3.Broadcast — Supabase Docs
  4. 4.Presence — Supabase Docs
  5. 5.Row Level Security — Supabase Docs

Find this in your own app

ShipRely reads your repository (read-only), proves each finding with file and line, and gives you a fix prompt to paste into your AI builder.

Run a demo audit
  • Read-only access to your repository
  • Every finding with file and line
  • Fix prompts for Lovable, Cursor, Claude Code and Bolt