PatchPaste · Guides

Last updated 14 November 2026

Supabase Realtime security: is your live chat open to anyone with the anon key?

Lovable and Bolt apps often use Supabase Realtime for chat, live notifications, presence ("who's online") or a feed that updates by itself. Your tables can have perfect RLS and a Realtime channel can still be open. Here is how Supabase decides who can listen, the fix, and how to test it.

Short answer: Realtime channels are public unless you make them private. With the default setting, Supabase says anyone holding your anon key can subscribe to and broadcast on any public channel, and that key is in your app's JavaScript. To lock it down: write RLS policies on realtime.messages, create channels with config: { private: true }, and turn off Allow public access in Realtime Settings. Separately, make sure every table you stream with Postgres Changes has RLS scoped to the caller.

Three kinds of Realtime, two kinds of risk

Broadcast and Presence are controlled by the channel: public or private, and the policies on realtime.messages. Postgres Changes is controlled by the RLS on the table being streamed. A Lovable app can get one right and the other wrong.

Public channels: the default

Supabase's Realtime Settings docs list a toggle called Allow public access to channels, default Enabled. When it is enabled, "no policy check runs, but anyone holding your project's anon key can subscribe to and broadcast on any public channel." Supabase's own Realtime security policy lists "Channels that are not private" under "By design": joining one is not a bypass.

So if your app does supabase.channel('room-1') without private: true, a stranger who reads your JavaScript can join that topic, see the messages and send their own. Guessable topic names (a room id, a user id) make that easier.

The fix: private channels with RLS

Supabase's Realtime Authorization docs describe two steps, plus the setting above:

  1. Policies on realtime.messages. A select policy controls who can receive, an insert policy controls who can send. The extension column is 'broadcast' or 'presence', and realtime.topic() returns the topic being joined.
  2. Private channels in the client: supabase.channel('room-1', { config: { private: true } }).
  3. Turn off Allow public access in Realtime Settings. The docs say private channels are only enforced once it is off; then clients that don't set private: true are rejected with PrivateOnly.

This is the receive policy from Supabase's docs, where rooms_users links users to the rooms they belong to:

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

Add a matching for insert ... with check (...) policy for sending, and the same pair with 'presence' if you use Presence.

Two traps from the docs. RLS is already on for realtime.messages, so don't put alter table realtime.messages enable row level security in a migration: it fails with 42501 must be owner of table messages and the policies after it never run. And with public access off but no policies, clients connect but receive nothing, which looks like a bug but is the lock working.

Postgres Changes: your table RLS is the gate

Supabase's Postgres Changes and Authorization docs say that on tables with RLS, records are sent only to clients allowed to read them. That cuts both ways: if a table in the supabase_realtime publication has RLS off, or a using (true) policy, its changes go to anyone who can read it, live.

Supabase also warns that RLS policies are not applied to DELETE events, because Postgres can't check access to a deleted row. By default only the new record is sent; the old record on updates and deletes needs the table's replica identity set to full. Think before turning that on for a table with private columns.

Revoked users keep listening for a while

Realtime checks access when a client joins a channel and caches it for the connection. Supabase's docs say a client whose access you revoke keeps receiving messages until its JWT expires or a new one is sent, and advise keeping the JWT expiry short. If you remove someone from a private room, expect a delay unless you also end their session.

Fixes to refuse

Check it worked

  1. Settings: Realtime Settings shows Allow public access turned off.
  2. Logged out: in a private browser window with the app signed out, try to join and send on each channel. It should be refused.
  3. As a second test user: sign in as an account that is not in the room and try the same. It should be refused, while a member still gets messages.
  4. Postgres Changes: for each streamed table, insert a row as user A and confirm user B and a signed-out window receive nothing.
  5. From outside: scan the live URL to confirm common tables don't answer to your public key and no secret key is in your JavaScript. PatchPaste does not test Realtime, so steps 1 to 4 are the real test for channels.

A prompt to paste into Lovable

Review this app's Supabase Realtime security. Do not disable RLS on any table, do not add using (true) policies and do not use the service_role key in the client. 1) List every supabase.channel(...) call, its topic name, whether it uses Broadcast, Presence or Postgres Changes, and who should be able to receive and send on it. 2) For Broadcast and Presence channels that carry anything private, create them with config: { private: true } and write a migration with select and insert policies on realtime.messages, scoped with (select realtime.topic()) and (select auth.uid()) and filtered by realtime.messages.extension. Do not add "alter table realtime.messages enable row level security". 3) For every table in the supabase_realtime publication, confirm RLS is enabled and its select policy only returns rows the caller should see. 4) Tell me to turn off "Allow public access" in Realtime Settings once the private channels work. 5) Tell me how to test each channel signed out and as a second user.

Related: Supabase RLS check, is the anon key safe?, Supabase select returns an empty array and Is my Lovable app secure?

Supabase Realtime security FAQ

Can anyone join my Supabase Realtime channel?

On a public channel, yes. Supabase's Realtime Settings docs say the "Allow public access to channels" toggle is Enabled by default, and that when it is enabled "no policy check runs, but anyone holding your project's anon key can subscribe to and broadcast on any public channel". Your anon (publishable) key is in your app's JavaScript, so treat a public channel as readable and writable by anyone.

How do I make a Supabase Realtime channel private?

Three steps from Supabase's Realtime Authorization docs: write RLS policies on the realtime.messages table (select to receive, insert to send), create the channel in your client with config: { private: true }, and turn off "Allow public access" in Realtime Settings so public joins are refused.

Does Postgres Changes respect RLS?

Yes, for inserts and updates: Supabase's docs say records are sent only to clients allowed to read them under your RLS policies. So a table with RLS off, or with a using (true) policy, streams its changes to anyone who can read it. Supabase also notes that RLS is not applied to DELETE events, because Postgres cannot check access to a row that no longer exists.

I removed a user from a room but they still get messages. Why?

Supabase caches each client's Realtime access for the connection. It is checked when the client joins a channel and refreshed when a new JWT is sent. A client whose access was revoked keeps receiving messages until its JWT expires or a new one is sent, so keep the JWT expiry short.

Is the anon key in the WebSocket URL a leak?

No. Supabase's Realtime security policy says the publishable (anon) key in the WebSocket URL is public by design and is not authorization. What protects your data is RLS on your tables and on realtime.messages, with public channel access turned off.

Can PatchPaste check my Realtime setup?

No. PatchPaste's free scan does not open WebSocket connections, join channels or read your Realtime settings or policies. It checks what the live site serves to strangers: secret keys in the shipped JavaScript, whether common Supabase tables answer to the public anon key (read-only, at most one row, discarded), exposed .env, .git and source maps, and security headers. Use the tests on this page for Realtime.

Channels locked? Check the rest of the live app for free

Paste your live URL for a free A to F report. PatchPaste checks whether common Supabase tables answer to your public anon key without a login (read-only, at most one row, discarded), searches the JavaScript your site sends for secret keys, and flags exposed .env/.git/source maps and missing headers. It does not sign in, join Realtime channels or read your database settings. Fix prompts for that report are a one-off £9 (or £29 for 10). Scans are free to rerun after each change.

Free. No login. No code access.

Want to see one first? View a sample report.

Sources (checked 14 Nov 2026): Supabase Realtime Settings (Allow public access to channels, default Enabled, and what Enabled and Disabled do); Realtime Authorization (policies on realtime.messages, private: true, the 42501 migration trap, Postgres Changes and RLS, cached access until the JWT expires); Postgres Changes (RLS not applied to DELETE, replica identity full); supabase/realtime security policy (anon key in the WebSocket URL and non-private channels are by design). Screen wording varies between Supabase Studio and Lovable.