Supabase Realtime leaking rows or not receiving changes: fix RLS and the publication
Updated · Applies to: Supabase, Lovable, Bolt, Cursor
TL;DR fix: Realtime Postgres Changes sends an INSERT or UPDATE to a subscriber only if that subscriber could select the row under your RLS policies. So the two classic bugs are mirror images. Leaking: a table in the supabase_realtime publication with RLS off or using (true) streams every change to anyone holding your public key. Silence: the table isn't in the publication, the role has no SELECT grant, or the policy blocks the row, and Realtime still reports SUBSCRIBED. Run the check query below, give each published table an owner-scoped select policy, remove tables you don't need, and for Broadcast/Presence turn off Allow public access and use private: true channels with RLS policies on realtime.messages.
Steps
- List what Realtime publishes. Run the check query in the SQL Editor. It lists every table in the supabase_realtime publication with RLS status, replica identity, whether anon can select it, and its SELECT policies.
- Flag leaking tables. Any published table with rls_enabled = false, or a SELECT policy using true, sends every INSERT and UPDATE to every subscriber who has your public key.
- Scope SELECT policies to the owner or members. Enable RLS and replace using (true) with a policy like using ((select auth.uid()) = user_id) for authenticated, or a membership check for shared rooms.
- Remove tables you don't need live. alter publication supabase_realtime drop table public.your_table; Only tables the UI actually subscribes to should be in the publication.
- Fix silent subscriptions. Add the table to the publication, grant SELECT to authenticated, confirm the same user can select the row with supabase.from(...).select(), check the filter syntax (room_id=eq.123), log the subscribe status, and remove channels on unmount.
- Lock Broadcast and Presence. Add select/insert policies on realtime.messages for the broadcast and presence extensions, create channels with config: { private: true }, then turn off Allow public access to channels in Realtime Settings.
- Retest as two users. Open the app as user A and user B in two browsers. A change to A's row must reach A and not B; B must not be able to join A's private channel.
Two bugs, one rule
Supabase Realtime Postgres Changes streams database changes from tables in the supabase_realtime publication. Before it sends an INSERT or UPDATE to a subscriber, it checks whether that subscriber’s role could select the row under your RLS policies. That one rule explains both symptoms vibe-coded apps hit:
- Leaking. The AI builder (or you) toggled Realtime on for
messages,ordersornotifications, but RLS is off or the policy isusing (true). Every change now goes to anyone who opens a channel with your public key, which ships in your frontend:
// Anyone, from any browser, with the URL and publishable/anon key from your app's JS bundle
supabase.channel('x')
.on('postgres_changes', { event: '*', schema: 'public' }, (p) => console.log(p.new))
.subscribe()
- Silence. The table isn’t in the publication, the role has no
SELECTgrant, or the policy hides the row from that user. Nothing errors, and the channel still saysSUBSCRIBED.
Supabase’s own Postgres Changes quick start uses using (true) for anon to get a demo working and says to secure it in production. That’s the line that tends to survive into production. A builder on X put it plainly: tables in the realtime publication with RLS off stream every row change to anyone with the anon key.
Step 1: the 2-minute check
Run this in the Supabase SQL Editor:
select pt.schemaname, pt.tablename,
c.relrowsecurity as rls_enabled,
case c.relreplident when 'd' then 'default (pk only)' when 'f' then 'full'
when 'n' then 'nothing' else 'index' end as replica_identity,
has_table_privilege('anon', c.oid, 'SELECT') as anon_can_select,
(select string_agg(p.policyname || ' [' || p.cmd || ' to ' || array_to_string(p.roles, ',')
|| '] using ' || coalesce(p.qual, '-'), '; ')
from pg_policies p
where p.schemaname = pt.schemaname and p.tablename = pt.tablename
and p.cmd in ('SELECT', 'ALL')) as select_policies
from pg_publication_tables pt
join pg_class c on c.oid = format('%I.%I', pt.schemaname, pt.tablename)::regclass
where pt.pubname = 'supabase_realtime'
order by 1, 2;
-- Broadcast / Presence authorization policies (empty = none)
select policyname, cmd, roles, qual, with_check
from pg_policies where schemaname = 'realtime' and tablename = 'messages';
How to read it:
| What you see | What it means |
|---|---|
rls_enabled = false | Leak. Every insert/update goes to every subscriber with table access. |
select_policies contains using true | Leak. Same thing, with RLS technically on. |
anon_can_select = true on private data | Logged-out visitors can subscribe too (and query it over the REST API). |
| Your table isn’t in the list | Silence. Realtime can’t see it. |
| No rows from the second query | Broadcast/Presence have no authorization policies. Check whether public channel access is still on (Step 5). |
Fix 1: stop the leak
Turn RLS on and scope reads to the owner (or to room members for shared data):
alter table public.messages enable row level security;
drop policy if exists "Enable read access for all users" on public.messages;
create policy "Users read their own messages"
on public.messages for select to authenticated
using ( (select auth.uid()) = user_id );
-- Shared rooms: members only
-- using ( exists (select 1 from public.room_members m
-- where m.room_id = messages.room_id and m.user_id = (select auth.uid())) )
-- If logged-out visitors never need this table:
revoke select on public.messages from anon;
Then take out every table the UI doesn’t actually subscribe to:
alter publication supabase_realtime drop table public.notes;
The same select policy also protects the table over the normal REST API, so this fixes two exposures at once. See USING (true) policies for the wider audit.
DELETE events are different. Supabase docs say RLS is not applied to DELETE events because Postgres can’t check access to a row that’s gone. With RLS on, the delete payload carries only the primary key, so treat a delete event as a signal (“row 42 is gone”), not as data.
Fix 2: nothing arrives
Work through these in order (this is the order in Supabase’s own troubleshooting guide):
-- 1. Is the table published?
select * from pg_publication_tables where pubname = 'supabase_realtime';
alter publication supabase_realtime add table public.messages;
-- 2. Can the subscribing role read it at all? Supabase's quick start includes the grant.
-- New tables since Supabase's Oct 30, 2026 change may lack it.
grant select on public.messages to authenticated;
// 3. Is RLS hiding the row from THIS user? Run as the signed-in user, not in the SQL Editor
const { data } = await supabase.from('messages').select('*').eq('id', changedRowId)
console.log(data) // [] means the policy blocks it, and Realtime will too
// 4. Correct filter syntax, logged status, and cleanup on unmount (React)
useEffect(() => {
const channel = supabase
.channel(`room:${roomId}`)
.on('postgres_changes',
{ event: '*', schema: 'public', table: 'messages', filter: `room_id=eq.${roomId}` },
(payload) => console.log(payload))
.subscribe((status, err) => console.log(status, err))
return () => { supabase.removeChannel(channel) }
}, [roomId])
More traps from the Supabase docs:
UPDATEthat moves a row out of the policy (for examplestatusfromactivetoarchivedwhen the policy only allowsactive) can fail to deliver. RLS generally has to allow both the old and new state.- Writing immediately after
SUBSCRIBEDcan be missed. Supabase calls this a confirmed timing gap. Tests are where it shows up most. - Tables outside
publicneedgrant select ... to authenticated(there’s no dashboard toggle for that). payload.oldis empty.alter table messages replica identity full;adds old values, but on a table with RLS enabled the old record still contains only the primary key. Re-fetch instead of diffing.- Signed in, still nothing. Realtime authorizes using the JWT the client sends. Subscribe after the session has loaded. A channel opened before sign-in finishes most likely joins with the anon role and never sees owner-only rows. That part is our inference and isn’t stated in Supabase’s docs. Supabase’s docs call
await supabase.realtime.setAuth()before joining private channels. A bad or expired JWT is a common cause ofCHANNEL_ERROR, and loggingerrshows the reason.
Realtime doesn’t guarantee delivery, so re-fetch on reconnect and treat events as “something changed”. Don’t use them as your only source of truth.
Fix 3: lock Broadcast and Presence (Realtime Authorization)
Broadcast and Presence don’t use your table policies. According to Supabase’s Realtime Settings docs, Allow public access to channels is enabled by default, and then anyone holding your anon key can subscribe to and broadcast on any public channel. To restrict them, add policies on realtime.messages:
-- Who may join/receive on a topic
create policy "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')
)
);
-- Who may send / track presence on a topic
create policy "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')
)
);
Do not add alter table realtime.messages enable row level security;. RLS is already on, and the statement fails with 42501 must be owner of table messages. That aborts the migration and skips the policies after it.
await supabase.realtime.setAuth()
const channel = supabase.channel('room:1', { config: { private: true } })
.on('broadcast', { event: 'message' }, (p) => console.log(p))
.subscribe((status, err) => console.log(status, err))
Then turn off Realtime → Settings → Allow public access to channels. Do it last: after that, any client that doesn’t set private: true is rejected with PrivateOnly, and a private channel with no matching policy connects but receives nothing. Changing Realtime settings disconnects all connected clients.
Two more things Supabase documents:
- Access is cached per connection. A user you remove from
room_memberskeeps receiving messages until their JWT expires or a new one is sent, so keep JWT expiry short. - For many subscribers, use Broadcast instead of Postgres Changes. Supabase recommends Broadcast (with a trigger calling
realtime.broadcast_changes()into a private channel) for scale and security, and suggests it above roughly 3,000 concurrent subscribers to the same changes.
Paste this into Lovable, Bolt or Cursor
Audit and fix Supabase Realtime security in this app.
1. List every table in the supabase_realtime publication
(select * from pg_publication_tables where pubname = 'supabase_realtime')
and every place the code calls .on('postgres_changes', ...).
2. Remove tables from the publication that the UI doesn't subscribe to
(alter publication supabase_realtime drop table ...).
3. For each remaining table: RLS must be enabled, and the SELECT policy must be
scoped to the owner ((select auth.uid()) = user_id) or to members via a join table.
Never using (true). Revoke SELECT from anon unless logged-out users need it.
4. Make sure each subscribed table has GRANT SELECT to authenticated, subscriptions
use the correct filter syntax (column=eq.value), log the subscribe status and error,
and call supabase.removeChannel(channel) on unmount.
5. Don't compare payload.old to payload.new on RLS-protected tables (old only has the
primary key). Re-fetch the row instead.
6. For Broadcast and Presence: add SELECT and INSERT policies on realtime.messages
using realtime.topic() and a membership table, create channels with
{ config: { private: true } } after await supabase.realtime.setAuth().
Do not run "alter table realtime.messages enable row level security".
Tell me when it's safe to turn off "Allow public access to channels".
7. Show me the SQL before running it, then help me test with two different users.
What we verified
- Docs-based (fetched Nov 13, 2026): how Realtime decides delivery (Postgres Changes sent only to clients allowed to read the row; DELETE not RLS-filtered; old record is primary key only with RLS on), the publication commands, the private-schema grant, the “Allow public access to channels” default and
PrivateOnlybehavior,realtime.messagespolicies withrealtime.topic()andextension, themust be owner of table messagestrap, per-connection policy caching, and the troubleshooting order. Sources are linked below. - Reproduced on Postgres 17 (PGlite) with Supabase-style
anon/authenticatedroles, anauth.uid()stand-in and asupabase_realtimepublication: the check query correctly flagged a published table with RLS off and one withusing (true), and both were fully readable byanon(the read Realtime authorizes against). After Fix 1,anongotpermission denied, user A saw only their own row,drop tableremoved a table from the publication, andreplica identity fullshowed up in the check. For Fix 3 we used a mockrealtime.messagestable and arealtime.topic()stand-in: the member could read and send on their room, and was blocked from reading or sending on another room. A non-member was blocked on both. - Not reproduced: Realtime itself (WebSocket delivery,
SUBSCRIBED/PrivateOnlystatuses, the timing gap, JWT caching), and nothing was run on a live Supabase project. Those behaviors are from Supabase’s docs and labeled as such above. The claim that a channel opened before sign-in uses the anon role is our reading of how Realtime uses the client’s JWT, not a documented statement.
Related: USING (true) policies, permission denied on new tables (Oct 30, 2026), views that skip RLS, and Check your Supabase RLS in two minutes.
When to get help
Get help if private messages, orders or user data were already published to a table with RLS off, if you have many published tables and don't know which the UI uses, or if switching to private channels breaks your chat or presence features.
Want us to look at your app?
VibeCPR Rescue Reports are launching soon: we scan your repo and live app, and a human verifies every critical finding. Join the waitlist for early access and founder pricing. You'll also get Patch Notes, our weekly fixes newsletter.
FAQ
Does Supabase Realtime respect Row Level Security?
For Postgres Changes, yes, but only as well as your policies. Supabase docs say records are sent only to clients allowed to read them under RLS, checked as the subscribing role. If RLS is off on a published table, or the SELECT policy is using (true), that check lets everyone through, so every INSERT and UPDATE goes to anyone with your public key. DELETE events are not RLS-filtered at all; with RLS on they carry only the primary key.
Why does my Supabase Realtime subscription say SUBSCRIBED but never receive changes?
SUBSCRIBED only means the WebSocket joined. The usual causes, in Supabase's own order: the table isn't in the supabase_realtime publication; RLS blocks the row for that user (test with supabase.from(table).select().eq('id', changedId) as the same user, not in the SQL Editor); filter syntax (room_id=eq.123, not room_id = 123); stale channels not removed on unmount; or writing immediately after SUBSCRIBED. Tables outside public also need GRANT SELECT to authenticated.
How do I see which tables Supabase Realtime is broadcasting?
Run select * from pg_publication_tables where pubname = 'supabase_realtime'; or open Database → Publications in the dashboard. Every table listed is streamed by Postgres Changes, so each one needs RLS enabled and a SELECT policy scoped to the owner or members.
Why is payload.old empty on UPDATE or DELETE?
By default Postgres only sends the primary key for the old row. alter table your_table replica identity full; adds the previous values, but Supabase docs say that on a table with RLS enabled the old record still contains only the primary key. Don't build logic that compares payload.old to payload.new on a protected table; re-fetch the row instead.
Are Supabase Broadcast and Presence channels public?
By default, yes. Supabase's Realtime Settings docs say that with "Allow public access to channels" enabled (the default), anyone holding your anon key can subscribe to and broadcast on any public channel. To restrict them, add RLS policies on realtime.messages, create channels with config: { private: true }, and disable public access. With public access off, clients that don't set private: true are rejected with PrivateOnly.
I removed a user from a room. Why do they still get Realtime messages?
Realtime caches a client's access when it joins a channel and refreshes it only when a new JWT is sent. Supabase docs say a revoked user keeps receiving messages until their JWT expires or a new one is sent, so keep JWT expiry short and have the client re-subscribe after membership changes.
Creating Realtime policies fails with "must be owner of table messages".
Remove alter table realtime.messages enable row level security; from your migration. RLS is already on for realtime.messages, and that statement fails with 42501 and aborts the transaction, which also skips the create policy statements after it. Policy statements on realtime.messages are allowed.
Sources
- Supabase docs: Postgres Changes (publication, replica identity, DELETE caveat, private schemas)
- Supabase docs: Realtime Authorization (realtime.messages policies, private channels)
- Supabase docs: Realtime Settings (Allow public access to channels)
- Supabase docs: Subscribing to database changes (Broadcast vs Postgres Changes)
- Supabase KB: Realtime Postgres Changes troubleshooting
- Supabase KB: Realtime messages not arriving
- @amlim13 on X: tables in the realtime publication with RLS off
Related fixes
- AI agent pushed API keys to GitHub? git commit --no-verify skipped your pre-commit hook
- Fix a surprise AI API bill: rate limits and spend caps
- Your app is public to anyone with the link: a share link is not a login
- Triage Bolt's "RLS Policy Always True" warning: when it's fine and how to fix it
- Fix secrets leaked via Claude Code .claude/settings.local.json
- Fix "Your Cloud Firestore database has insecure rules" (Firebase email)
- Login lockout keyed only on email? Rate-limit by IP and account without locking users out
- Fix Lovable "Invalid API key" after rotating Supabase keys (anon, publishable, secret)
- Lovable won't publish because of security findings? What each finding means and how to fix it
- "Sign in with Google" lets anyone in: restrict who can use your app (allowlist, domain check, RLS)
- Fix Stripe sk_live keys left in MCP or agent config
- Fix Stripe webhook "No signatures found matching the expected signature for payload"
- Fix Supabase auth redirecting to localhost after deploy
- Fix Supabase Edge Function "blocked by CORS policy" (preflight)
- Fix Supabase "infinite recursion detected in policy for relation" (42P17) in RLS
- Form says success but no row in Supabase (or Stripe webhook returns 200 but writes nothing)
- Fix "new row violates row-level security policy for table" (Supabase)
- Supabase only returns 1,000 rows? Fix the silent max rows limit in Lovable and Bolt apps
- Fix Supabase "permission denied for table" (42501) on new tables after Oct 30, 2026
- Fix a Supabase public Storage bucket that lets anyone list or download your files
- Supabase RLS not working on the server? Your API uses the service_role or secret key
- Fix Supabase RLS policy USING (true) that makes a table publicly readable
- Your app's rules only live in the frontend: move them into Supabase
- Fix a Supabase SECURITY DEFINER function anyone can call through /rest/v1/rpc
- Fix Supabase .single() "JSON object requested, multiple (or no) rows returned" (PGRST116)
- Stop Supabase users from upgrading their own plan or making themselves admin
- Fix a Supabase view that bypasses RLS: security_invoker and revoking anon write grants
- Fix "404: NOT_FOUND" on refresh in a React/Vite app on Vercel (vercel.json rewrite)
- Fix "Module not found: Can't resolve" on Vercel (works locally)
- Is my Vite dev server exposed? Check --host / server.host and patch the RCE (GHSA-p4f5-76q4-ffq7)