Dev.to Security 🔐 Cybersecurity 👁 0 📖 2 min read

Supabase Realtime and RLS: why DELETE events still reach every subscriber

Supabase Realtime and RLS: why DELETE events still reach every subscriber If you stream database changes with Supabase Realtime, your table's Row Level Security decides who gets inserts and updates. Deletes are differen

Supabase Realtime and RLS: why DELETE events still reach every subscriber

If you stream database changes with Supabase Realtime, your table's Row Level Security decides who gets inserts and updates. Deletes are different, and a reader pointed this out on one of my earlier posts. Here is the correction.

What happens

Postgres Changes checks RLS against the row the subscriber is allowed to read. When a row is deleted, it no longer exists, so there is nothing left to check a policy against. Every subscriber to that table receives the DELETE event. The event carries the primary key of the deleted row. A filter on DELETE events only works if the table has replica identity set to full.

The GitHub issue supabase/realtime #585 shows this clearly: a subscriber with a row filter still received delete events with the old record holding the id.

Why it matters

With sequential ids, a stranger who can subscribe sees how often rows are deleted and which ids are going away. That tells them how busy a private table is. If your primary key is built from private values, such as an email or a document title, each delete leaks that value.

How to check your own app

  1. List the tables your app subscribes to for changes.
  2. For each, look at the primary key. Is it a random UUID, a sequential number, or a value built from user data?
  3. Open your app signed out or as a second user and subscribe to the same table. Delete a row you own from another session and see what arrives.
  4. Check whether the table has replica identity set to full, and what you rely on in the delete payload.

How to fix it

  • Use random UUIDs as primary keys on tables you stream.
  • Never build a primary key from an email, a name or a title.
  • If deletes must respect access rules, use a soft delete: an update that sets a deleted_at column. Updates go through RLS like any other change.
  • Send sensitive changes over a private Broadcast channel with its own authorization policy instead of raw table changes.

Credit to Sunnatulla E. for the catch. I work on ProofForge. The free scan covers what a visitor can see and says plainly what it could not check.

Check your own app from the outside, free. Run the free ProofForge scan on your live URL. No account needed for the first scan. It looks at your public site the way a stranger would and says pass, fail or inconclusive, so you know what is confirmed and what it could not see. One-time reports start at $9: see pricing. Building with an AI agent? There is an MCP server so it can check before it deploys.

📰 Read the original article on Dev.to Security

Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.