Urgent.News

What's breaking now, across hundreds of outlets.

Tech

Your M-Pesa callback runs as service_role: where Supabase tenant isolation really breaks

RLS is enabled on every table. Tests pass. Then a payment callback writes a row to the wrong tenant: the handler runs as service_role, so RLS never sees it, and the callback carries no tenant, so the code guesses. 1. Why this matters now Supabase is changing public tables so new ones are no longer exposed to the Data API automatically. Its April 2026 changelog schedules this for all existing…

Supabase has introduced a change where public tables are no longer automatically exposed to the Data API, scheduled to take effect on 30th October 2026. While new tables will be restricted by Row Level Security (RLS), existing tables retain their current grants. Server-side paths of Supabase applications have been reported to have large-scale exposure issues. This article focuses on the server-side aspects that are not covered by the upcoming changes.

The source code for testing tenant isolation can be found at https://github.com/cal-me-j/tenant-isolation-lab. The tests use two tenants, membership and invoice tables, and simulate M-Pesa callbacks using Daraja-shaped payloads. The testing environment uses Supabase CLI 3.2.0, Postgres 17.12, and GitHub Actions on ubuntu-latest.

Three scenarios were identified where RLS does not prevent unintended tenant access:

1. User metadata can be edited, allowing users to select their tenant.

2. An INSERT policy only checks authorship.

3. An UPDATE policy uses ownership-based checks without WITH CHECK.

A specific M-Pesa-related issue arises from the fact that callbacks do not include tenant information. The handler in the vulnerable code matches payer phone numbers and amounts against open invoices across all tenants, a flawed approach as the callback carries no tenant reference. A better approach would be to store a record at the initiation of the checkout request and reject callbacks with no matching record.

The updated handler logic also includes a WITH CHECK on writes, views with security_invoker, and a SECURITY DEFINER function to restrict access.

Rewritten by urgent.news; may contain errors — check the original.

Source: dev.to

Read the original at dev.to →

Report a problem with this story

More in Tech

I built a waitlist for Calendly that works on the free plan

Calendly needs a waitlist and it's been asked for since 2024! When a client cancels, that slot usually just sits empty, unless the coach or tutor happens to remember who wanted an earlier time. I ran into this myself.

  • Ray developed NextUp, a waitlist solution for Calendly's free plan.
  • NextUp integrates with Calendly, allowing clients to view and select available appointment times.

More from Tuesday, 1 December 2026 →