</>RescueMyRepoFree scan

// guide · Supabase Realtime · published Nov 12, 2026

Supabase Realtime leaks: public channels and RLS-off tables anyone with your anon key can watch

Short answer

Realtime can leak data without anyone ever querying a table. If a table is in the supabase_realtime publication with Row Level Security off, anyone with your public anon key can subscribe and watch every insert and update live. And a Broadcast or Presence channel created without { config: { private: true } } is public: anyone who knows the topic name can listen and send. Enable RLS on published tables, make channels private, and add policies on realtime.messages.

How Realtime decides who gets what

Postgres Changes streams row changes from tables in the supabase_realtime publication. Supabase sends a change only to clients whose RLS policies let them read that row (Realtime Authorization). With RLS off, there is no policy to check, so every subscriber gets every row. Supabase's docs also warn that RLS is not applied to DELETE events (Postgres Changes).

Broadcast and Presence don't touch your tables at all. Access is controlled by RLS policies on the realtime.messages table, but only for channels created with private: true. A plain supabase.channel("room-1") is public, and the anon key it needs ships in your JavaScript bundle on purpose. To reject public channels completely, Supabase says to turn off Allow public access in Realtime settings.

AI builders hit both: “make the chat live” adds a table to the publication, and the generated chat uses a public Broadcast channel named after the room ID.

Check it in 2 minutes

1. In the Supabase SQL editor, list what Realtime streams. Any row with rls_enabled = false is visible live to everyone:

-- Supabase SQL editor: which tables does Realtime stream, and is RLS on?
select p.schemaname, p.tablename, c.relrowsecurity as rls_enabled
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'
order by rls_enabled, p.tablename;

2. In your code, find channels that use Broadcast or Presence without private: true:

# Channels that use Broadcast or Presence
grep -rnE "\.channel\(|on\(['\"](broadcast|presence)" src app components lib 2>/dev/null
# Files that create channels but never set private: true
grep -rlE "\.channel\(" src app components lib 2>/dev/null | xargs grep -L "private: true"

This is what a public channel looks like:

// Public channel: anyone with the anon key who guesses "chat-room:42" can read and send
const ch = supabase.channel(`chat-room:${roomId}`);
ch.on("broadcast", { event: "msg" }, (p) => show(p.payload)).subscribe();
ch.send({ type: "broadcast", event: "msg", payload: { body } });

The fix

Make the channel private on the client:

// Private channel: Realtime checks your realtime.messages policies on join
const ch = supabase.channel(`chat-room:${roomId}`, { config: { private: true } });
ch.on("broadcast", { event: "msg" }, (p) => show(p.payload)).subscribe();

Then add the policies. This example uses a room_members(room_id, user_id) table and topics like chat-room:<room_id>; adapt the names to your schema. Policies are cached per connection, so a user you remove keeps receiving messages until their JWT refreshes. Keep the JWT expiry short.

-- 1) Tables: enable RLS on every published table (or drop it from Realtime)
alter table public.messages enable row level security;
create policy "members read room messages" on public.messages
  for select to authenticated
  using (exists (select 1 from public.room_members m
                 where m.room_id = messages.room_id and m.user_id = (select auth.uid())));
-- not needed live? remove it:
-- alter publication supabase_realtime drop table public.audit_log;

-- 2) Channels: who may join (select) and send (insert) on a topic like "chat-room:<room_id>"
create policy "members receive on their rooms" on realtime.messages
  for select to authenticated
  using (
    realtime.messages.extension in ('broadcast', 'presence')
    and exists (select 1 from public.room_members m
                where m.user_id = (select auth.uid())
                  and 'chat-room:' || m.room_id::text = (select realtime.topic()))
  );
create policy "members send on their rooms" on realtime.messages
  for insert to authenticated
  with check (
    realtime.messages.extension in ('broadcast', 'presence')
    and exists (select 1 from public.room_members m
                where m.user_id = (select auth.uid())
                  and 'chat-room:' || m.room_id::text = (select realtime.topic()))
  );
-- Do NOT add "alter table realtime.messages enable row level security" (already on; fails with 42501)

Once the private channels work, turn off Allow public access under Realtime settings so nobody can fall back to a public channel.

Tell your AI coding tool

Paste this into Lovable, Bolt, Cursor or Claude Code:

Audit this Supabase project for Realtime data exposure.
1. In migrations, list every table added to the supabase_realtime publication (alter publication supabase_realtime add table ..., or "for all tables"). For each, confirm Row Level Security is enabled and SELECT is limited to rows the user may see (auth.uid()). Remove tables from the publication if the app does not need live updates for them.
2. Find every supabase.channel(...) that uses broadcast or presence. Create them with { config: { private: true } } unless the data is intentionally public.
3. Add RLS policies on realtime.messages (SELECT to receive, INSERT to send) that check the user may access (select realtime.topic()), and filter realtime.messages.extension in ('broadcast','presence'). Do not add ALTER TABLE realtime.messages ENABLE ROW LEVEL SECURITY.
4. Remind me to turn off "Allow public access" in Supabase > Realtime > Settings after the private channels work.
5. Show me before/after for each table and channel.

Check your repo automatically

RescueMyRepo's free scan reads your migrations and flags tables added to supabase_realtime (including for all tables) without RLS, and browser code that opens Broadcast or Presence channels without private: true, with a fix prompt for each. It also checks tables without RLS, permissive and login-only policies, leaked keys and Stripe webhooks.

Scan my repo freePublic GitHub repos · no signup · about a minute

FAQ

Does Supabase Realtime respect Row Level Security?

For Postgres Changes, yes: Supabase only sends a database change to clients whose RLS policies allow them to read that row. If RLS is off on a table in the supabase_realtime publication, there is nothing to filter, so anyone with your public anon key can subscribe and receive every change. Supabase's docs also note that RLS policies are not applied to DELETE events.

Are Supabase Broadcast channels private by default?

No. A channel created with supabase.channel('room-1') is public. Realtime Authorization (RLS policies on the realtime.messages table) only applies to channels created with config: { private: true }, and to reject public channels entirely you turn off 'Allow public access' in the Realtime settings.

Is the anon key a secret?

No. The anon (publishable) key is meant to be in your browser bundle, which is why access control has to come from RLS and private channels, not from hiding the key.

Do I need to enable RLS on realtime.messages?

No. RLS is already enabled on realtime.messages, and adding ALTER TABLE realtime.messages ENABLE ROW LEVEL SECURITY to a migration fails with 42501 'must be owner of table messages' and aborts the rest of that migration. Just create the policies.

Is a public channel ever fine?

Yes, for data that is meant to be public, such as anonymous cursors on a demo or a public live counter. Never for chat, notifications, per-user updates, or anything you would not post on a billboard. Anyone can also send messages on a public channel, so do not trust payloads from it.

Sources