Short answer: Supabase Realtime is only as private as you make it. Postgres Changes sends rows only to clients whose RLS policies allow them to read those rows, so every table in the supabase_realtime publication needs RLS turned on with tight select policies. Broadcast and Presence channels are public by default: anyone with your public anon or publishable key can join a channel by name and read or send messages. To make them private, add RLS policies on realtime.messages, create channels with config: { private: true }, and turn off "Allow public access" in your project's Realtime settings. Also remember that RLS is not applied to DELETE events.
Chat apps, live dashboards, multiplayer cursors and notification bells are some of the most common things people build with Lovable, Bolt, v0 and Cursor on top of Supabase. The generated code usually works on the first try, which is exactly the problem: it works for everyone, including people who should not see the data.
The three ways Realtime leaks data
1. Postgres Changes on a table without RLS
When you toggle a table on under the supabase_realtime publication, every insert, update and delete on that table becomes an event. Supabase checks the subscriber's RLS policies before sending each row. If RLS is off on that table, or the select policy is using (true), every connected client gets every change.
An attacker doesn't need your UI. With the public key from your JavaScript bundle they can subscribe to the whole schema:
const supabase = createClient(projectUrl, publicKey);
supabase
.channel("anything")
.on("postgres_changes", { event: "*", schema: "public" }, (p) => console.log(p))
.subscribe();
If any published table lacks RLS, its rows stream into their console in real time. Your client-side filter option (for example filter: "room_id=eq.42") does not protect anything, because the attacker can simply leave it out.
2. Public Broadcast and Presence channels
Broadcast (client to client messages) and Presence (who's online) do not touch your tables, so table RLS doesn't apply. A channel named room-42 is joinable by anyone who knows or guesses the name, unless you've set up Realtime Authorization. That means someone can read private chat messages sent over Broadcast, see who is online in a workspace through Presence, or send fake messages that look like they came from another user.
Channel names like user-${userId} are not secrets. User IDs show up in URLs, API responses and logs.
3. DELETE events skip RLS
Supabase's docs are explicit: RLS policies are not applied to DELETE events, because Postgres has no way to check whether a user had access to a row that no longer exists. By default a delete event carries little more than the primary key. If you set replica identity full on a table to get old values, think carefully before doing it on a table with sensitive columns.
Step 1: Lock down tables in the realtime publication
First, see which tables are published:
select schemaname, tablename
from pg_publication_tables
where pubname = 'supabase_realtime';
Remove anything that doesn't need live updates:
alter publication supabase_realtime drop table public.payments;
For each table you keep, make sure RLS is on and the select policy limits rows to the people who should see them:
alter table public.messages enable row level security;
create policy "members can 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())
)
);
Then subscribe with a filter for efficiency, knowing that the policy, not the filter, is what keeps other rooms private:
supabase
.channel(`room-${roomId}`)
.on(
"postgres_changes",
{ event: "INSERT", schema: "public", table: "messages", filter: `room_id=eq.${roomId}` },
(payload) => addMessage(payload.new)
)
.subscribe();
If you only need some columns, newer client versions support a select option on a specific table subscription, and the listed columns must be readable by the subscribing role. Keeping sensitive columns in a separate table that isn't published is simpler and safer.
For more on writing these policies, see the Supabase RLS checklist and the guide to preventing IDOR in Next.js and Supabase.
Step 2: Make Broadcast and Presence channels private
Realtime Authorization uses RLS policies on the realtime.messages table. Supabase doesn't actually store your messages there. When a client joins a channel, Realtime runs a check against that table and your policies, then rolls it back. The realtime.topic() function returns the channel name the client is trying to join, and the extension column tells you whether it's broadcast or presence.
Allow members of a room to receive broadcasts and presence:
create policy "room members can listen"
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')
);
Allow members to send:
create policy "room members can send"
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')
);
Two details trip people up:
- RLS is already enabled on
realtime.messages. Don't addalter table realtime.messages enable row level securityto a migration. It fails with a "must be owner" error and the rest of the migration, including your policies, gets skipped. - Policies alone are not enough. Clients must opt in to private channels, and you must turn off "Allow public access" in Realtime settings so nobody can join the same topic as a public channel.
On the client:
const channel = supabase.channel(`room-${roomId}`, {
config: { private: true },
});
channel
.on("broadcast", { event: "message" }, ({ payload }) => addMessage(payload))
.subscribe((status, err) => {
if (status !== "SUBSCRIBED") console.error("Realtime join failed", err);
});
If a user who isn't a member tries to join, the subscription fails instead of quietly letting them listen.
Step 3: Don't trust what arrives over Broadcast
Even on a private channel, any member can send any payload. If a message says { "from": "admin", "text": "..." }, that from field is whatever the sender typed. A few rules:
- Never use Broadcast payloads to make authorization decisions, change balances or mark orders paid. Write to the database through a policy-protected insert, an RPC or an Edge Function that checks the user, then let Postgres Changes or a database-triggered broadcast notify clients.
- Render received text as text, not HTML. In React, avoid
dangerouslySetInnerHTMLfor chat content. - If you need a trustworthy sender, send from the server. Supabase lets you broadcast from the database with functions like
realtime.send(), so the message comes from a trigger rather than a browser.
Step 4: Handle revoked access
Realtime caches a client's permissions for the life of the connection. It recalculates them when the client joins a channel or sends a new access token. If you remove someone from a room while they're connected, they can keep receiving messages until their JWT expires or a new one is sent. Keep JWT expiry reasonably short, and when you remove a member, also call removeChannel on their client if you control it.
Step 5: Never use the service role key in the browser
Some generated code "fixes" a Realtime permission error by creating the client with the service role key. That key bypasses RLS entirely, so the subscription will see everything, and anyone who opens DevTools now has full database access. If you've shipped it, follow how to rotate leaked Supabase and OpenAI keys right away.
Quick test before launch
- Sign in as user A in one browser and user B in another. Subscribe B to A's room and confirm nothing arrives.
- In a private window with no session, subscribe to
schema: "public", event: "*"with only the public key. You should receive no rows from private tables. - Join a Broadcast topic you aren't a member of with
private: true. The join should fail. - Try the same topic without
private: true. If it connects and receives messages, "Allow public access" is still on. - Run the publication query above and confirm every listed table has RLS enabled.
Related guides
Get an automated check
PreflightPR reviews AI-built apps for tables without RLS, service role keys in client code, Edge Functions that trust the request body and leaked keys. Run a free scan on a public repo for a launch score and a prioritized fix list, or install the PreflightPR GitHub App to check every pull request before it merges.