Turing Registry

Postgres Row-Level Security, Explained for Supabase Apps

Open the developer tools on almost any app built on Supabase and the JavaScript bundle hands you two strings: a project URL ending in supabase.co and a key. The key is meant to be there. On older projects it is a JSON Web Token, and if you decode the middle section you find a payload that says, in plain text, "role": "anon". Anyone can copy it into curl and talk to the database directly, from a laptop, a script or a scraper running in a datacentre, with no browser and no app in the way.

What stops that person from reading every row is a few lines of SQL that somebody may or may not have written. That mechanism is Postgres row-level security, and it sat underneath this site's report on Lovable apps leaking passport data earlier today. This piece is the companion explainer: what RLS does, what it was designed for, and the specific ways a database with RLS "on" still gives its contents away.

The key in the bundle and the role it names

Supabase's client libraries do not talk to Postgres. They talk to PostgREST, a server that turns HTTP requests into SQL. PostgREST connects with a deliberately weak login role, the authenticator, and for each request it switches identity. Its documentation is direct about the mechanism: PostgREST "will switch to the database role with that name for the duration of the HTTP request", using SET LOCAL ROLE. A request with no token, or a token with no role claim, runs as the anonymous role.

So the anon key does not unlock anything by itself. It names a Postgres role, anon, and from then on two ordinary Postgres layers decide what happens. The first is the grant: does the role have SELECT on this table at all. The second is row security: of the rows in that table, which ones may this role see or change.

Until this year, Supabase's defaults made the first layer a formality. Its own changelog, published April 28 2026, describes the old behaviour: on a default project, select, insert, update and delete were granted on every table in the public schema to anon, authenticated and service_role, so "every table you create becomes reachable via the Data API on creation." Everything rested on the second layer.

What Postgres does once the switch is on

Row security arrived in PostgreSQL 9.5, released January 7 2016, sold in the announcement as a headline feature alongside UPSERT. It was built for multi-tenant servers and for administrators who wanted the database itself, rather than every application in front of it, to enforce who sees which rows. Exposing a database to the open internet through a public key was a later use.

The rules are short. ALTER TABLE ... ENABLE ROW LEVEL SECURITY flips the table into a mode where, in the manual's words, "all normal access to the table for selecting rows or modifying rows must be allowed by a row security policy." If no policy exists, "a default-deny policy is used, meaning that no rows are visible or can be modified." That default is sound. A table with RLS enabled and no policies returns nothing to anon, which is the safest broken state a database can be in.

Policies then open holes on purpose. A USING expression decides which existing rows a query can see or touch; a WITH CHECK expression decides which new or modified rows are allowed, and if you omit it, Postgres reuses the USING clause. Several permissive policies on one table combine with OR, so any one of them is enough to let a row through. Restrictive policies combine with AND. The canonical Supabase example reads:

create policy "Individuals can view their own todos."
on todos for select
to authenticated
using ( (select auth.uid()) = user_id );

auth.uid() pulls the user id out of the verified token. For an anonymous request it returns null, and a comparison with null is never true, so the row stays hidden.

Some roles sit outside the rules altogether. Superusers and roles with BYPASSRLS "always bypass the row security system", and table owners normally do too, unless someone runs FORCE ROW LEVEL SECURITY.

COMPARISON
Who row security applies to on a typical Supabase project
anonauthenticatedservice_roletable owner
Subject to RLS policies✓✓bypassesbypasses unless FORCE is set
Meant to be used from a browser✓✓nevernever
Reached with the public key✓after loginnevernever

How a table with RLS enabled still leaks

The Lovable story and its 2025 predecessor were mostly about tables where RLS was never enabled, which is the easy case to detect. The harder cases are tables that pass a checkbox audit.

A policy of using (true) for anon turns up constantly in generated and tutorial code. It is often written to make an error go away during development, and it means what it says: every row, for everyone holding the public key. Because permissive policies OR together, one such policy left on a table overrides every careful policy beside it.

Row security also says nothing about columns. A policy that lets users update their own profile row lets them update every column in it, including is_admin or plan, unless column grants or a WITH CHECK expression forbid it. Supabase's docs add a related trap: raw_user_meta_data "can be updated by the authenticated user", so a policy that trusts a role stored there is trusting the attacker's own input. The docs point to raw_app_meta_data, which users cannot write.

Views get around the policies from the other side. Supabase's guide warns that "Views bypass RLS by default because they are usually created with the postgres user", the table owner. On Postgres 15 and later, security_invoker = true makes a view respect the caller's policies. A carefully locked table with a convenience view on top is an open table.

Then there is the master key. The service_role key bypasses RLS entirely, and the docs say flatly: "Never use a secret key in the browser or expose it to customers." Generated front-end code that needs to do something the policies forbid has an obvious and catastrophic shortcut available.

A subtler leak matters mostly to people storing secrets worth inferring. The manual notes that unique, primary key and foreign key checks "always bypass row security", and warns of "covert channel" leaks: an insert that fails on a duplicate email tells you the email exists in a row you cannot read.

Enabled is a different property from correct

The distinction this site keeps holding to applies here with some force. When Matt Palmer and his co-researchers published their statement on CVE-2025-48757 in May 2025, they reported scanning 1,645 Lovable projects and finding 170 with inadequate RLS, across 303 vulnerable endpoints, from homepages alone. Lovable 2.0 shipped with a security scan on April 24 2025. The researchers' complaint about it is the one that matters for every audit tool since: in their account, it "merely checks for the existence of any RLS policy." A using (true) policy exists. So does a policy on the table while the view beside it reads as owner.

Supabase's own changelog makes the platform-side argument plainly. "When Supabase launched, a human reviewed each schema change and enabled RLS on new tables as they went," it says, and "that model doesn't scale", because "agents, CLI scripts, and AI platforms create tables too, and many of those operations do not have a human reviewing the diff." Its fix moves the first layer back into play: from May 30 2026 for new projects and October 30 2026 for existing ones, new tables in public get no grants to anon or authenticated until someone writes a GRANT. That is a platform owning its default, which this site has argued for. It also has a stated limit, in the same document: "Existing tables are not affected in your project, they keep their current grants and stay reachable." Every table created before the switch, with or without a policy, is exactly as exposed as it was in September.

The only audit that tests correctness is the attacker's. Take the public key, skip the app, and ask PostgREST for each table as anon, then as a freshly signed-up user asking for someone else's rows, then try an update that changes a column the user should not own. Inside the database, set local role anon in a transaction and a select count(*) on each table answers the same question in a few seconds. Any count above zero on a table holding personal data is a finding, whatever the dashboard badge says.

The open number is the one Supabase has not published: how many existing projects, after October 30, still carry default grants to anon on public tables that have RLS disabled or a policy of using (true). Its Security Advisor already flags those tables per project, so the platform can count them. Until that figure is public, nobody outside Supabase can say whether the old defaults have been closed or simply stopped growing.

Sources