Row level security
In Postgres, row level security (RLS) attaches policies to a table. For each database role, they decide which rows a query may return and which rows an insert, update or delete may touch.1 Grants still apply: without a grant a role cannot perform the operation on the table in the first place, and the policy then limits the rows it reaches.2
How it works
A table starts with no policies, so a role that may read it reads every row. For a table that needs row level security, that gap is the weakness called Missing Authorization,3 filed under Broken Access Control.4 Once row level security is enabled, Postgres denies by default: with no policy, no row is visible or can be changed.1 Policies created while it is off have no effect.5
USING is checked against existing rows, and rows that fail it drop out of the result, usually with no error. WITH CHECK is checked against rows that an INSERT or UPDATE would write, and a failure raises an error.5 Permissive policies combine with OR, restrictive ones with AND. In this example from the PostgreSQL documentation, each member of the managers role sees only the accounts they manage:1
CREATE TABLE accounts (manager text, company text, contact_email text);
ALTER TABLE accounts ENABLE ROW LEVEL SECURITY;
CREATE POLICY account_managers ON accounts TO managers
USING (manager = current_user);Superusers (Postgres administrator accounts) and roles with the BYPASSRLS attribute skip policies, and so does the table's owner unless the table is set to FORCE ROW LEVEL SECURITY.1
In Supabase
Supabase runs browser requests as the anon role, or as authenticated once the user signs in.2 The browser sends the project's anon key with them, a key Supabase makes public by design.6 The Supabase API serves the tables in its exposed schemas (named groups of tables, public among them), and any role holding a grant on such a table can read and change it when row level security is off. On existing projects, anon, authenticated and service_role receive all privileges on each table newly created in public.2 That default is changing so new objects no longer get these grants; existing tables keep them. Tables created in the dashboard have row level security on, and tables created in the SQL Editor or by another tool need it turned on by hand.7
Enable it on every table in public, grant only what the app uses, and write one policy per operation that names its role:2
alter table public.profiles enable row level security;
revoke all on table public.profiles from anon, authenticated;
grant select, insert, update, delete on table public.profiles to authenticated;
create policy "Users can view their own profile."
on profiles for select
to authenticated
using ( (select auth.uid()) = user_id );
create policy "Users can update their own profile."
on profiles for update
to authenticated
using ( (select auth.uid()) = user_id )
with check ( (select auth.uid()) = user_id );Insert and delete policies follow the same form. When nobody is signed in, auth.uid() returns null and the comparison fails silently. Users of anonymous sign-in also get the authenticated role. A policy written to authenticated admits them too, unless it checks the is_anonymous field in the user's login token.2
Policies must not read user_metadata, which any signed-in user can change with a call such as updateUser({ data: { is_admin: true } }).8 Data used for access decisions belongs in raw_app_meta_data, which users cannot update.2
Objects policies do not cover
| Object | Why the policies do not apply | Fix |
|---|---|---|
| View | Runs with the rights of its creator, usually postgres | Create it with (security_invoker = true) on Postgres 15 and later |
| Materialized view, foreign table | Cannot have row level security | Revoke select from anon and authenticated |
| Function | Row level security does not apply to functions; a security definer function runs as its creator | Grant execute only to the roles that call it, set search_path = '', keep it out of exposed schemas |
| Request with the secret key | The service_role role has the bypassrls attribute | Use the key only on the server |
Testing policies
The Security Advisor in Supabase Studio, or supabase db advisors on the command line, reports a public table without row level security as an error, warning that anyone who has the project URL can read, change and delete every row in it. It also flags policies on a table where row level security is off, views that ignore policies, and always-true policies such as USING (true).8
Database tests check which rows each role reaches. supabase test new creates a test file, supabase test db runs the tests, and set local role anon; inside a test acts as a signed-out visitor. A read blocked by USING returns zero rows, so assert an empty result. Prove an allowed write with returning, never with lives_ok, which passes when the write matched no rows.2
Notable incidents
Lovable apps, CVE-2025-48757 (2025)
On 20 March 2025, Matt Palmer, who worked at Replit, changed a query on Linkable, a site built with the Lovable app builder, and received all the data in its users table. A scan of the home pages of 1,645 Lovable projects then found 303 endpoints in 170 of them with inadequate row level security, exposing names, phone numbers, payment details and API keys. Palmer wrote that the public key, which Supabase provides by design, was not the cause; the cause was "the absent RLS configuration". He also wrote that the security scanner Lovable offered looked only for whether some policy existed, without testing whether it was correct. On 24 May 2025 a signed-out request could still write to Linkable's data: a test record set payment_status to paid without any Stripe payment.6 CVE-2025-48757, the public vulnerability record published on 30 May 2025, rates the flaw 9.3, Critical, on CVSS 3.1. Lovable disputes it, saying each customer is responsible for the data of their own application.9
Scans of Supabase apps (2026)
UpGuard published a scan in September 2026 that found 16,326 Supabase databases with readable tables among about 300,000 domains; 55.8 percent of them exposed fields with personal data. It noted that coding agents make tables with API calls, and a table made that way has row level security off by default.10 In November 2026, Crissy Field and the newspaper Handelsblatt reported on 159,041 Lovable projects: 34,545 used Supabase, and 24,664 of those sent database records to visitors without a login, which the firm said is not a problem in itself when the data is meant for display. Further read-only requests found email addresses in 10,560 tables on 7,403 of those sites, and the firm warned against treating that number as a confirmed rate of leaked data.11
Prompt for a coding agent
List every table, view, materialized view and function in the public schema of this Supabase project, from the migrations and SQL files. For each table, say whether row level security is enabled, which roles have grants, and which policies exist for select, insert, update and delete. Flag tables with row level security off, policies that use true as their condition, policies that read user_metadata, views without security_invoker = true, and security definer functions that anon or authenticated can execute. Write the missing policies so each user reaches only their own rows, using (select auth.uid()) and naming the role with the to clause, and add a test per table with supabase test new that checks a second user sees none of the rows of the first user. Show me each change before you make it.
In SecFlash
SecFlash reports the issues in Table 2 from the Supabase project it is connected to and from the SQL files in the app's code. On the Exposure page it reports SF-EXP-213 when a table returns rows to a request made without signing in, SF-EXP-504 when one test account receives another account's details, and SF-EXP-303 for the anon key found in the frontend.
| Problem | Live project (Cloud) | Code (Security) |
|---|---|---|
Table in public without row level security | SF-CLD-501 | SF-SEC-721, SF-SEC-754 |
| Sensitive columns readable without row level security | SF-CLD-504 | |
| Policies written, row level security off | SF-CLD-502 | |
| Row level security on, no policy | SF-CLD-503 | SF-SEC-722 |
| Policy that always allows | SF-CLD-508 | SF-SEC-723 |
Policy reads user_metadata | SF-CLD-507 | SF-SEC-753 |
| Anonymous sign-ins reach user data | SF-CLD-522 | |
| View runs with its creator's rights | SF-CLD-506 | SF-SEC-752 |
| Visitors can run a privileged function | SF-CLD-509 | SF-SEC-751 |
| Materialized view or foreign table in the API | SF-CLD-513, SF-CLD-514 | |
Role with BYPASSRLS | SF-SEC-755 |
See also
- Authorization
- Insecure direct object reference
- Privileged key in client-side code
- Principle of least privilege
- Securing a Next.js and Supabase application
- Category: Supabase
References
- a b c d PostgreSQL Global Development Group. "5.10. Row Security Policies". PostgreSQL 19 Documentation.
- a b c d e f g h "Row Level Security". Supabase Docs. Supabase.
- back "CWE-862: Missing Authorization". Common Weakness Enumeration. MITRE.
- back "A01:2025 Broken Access Control". OWASP Top 10:2025. OWASP Foundation.
- a b PostgreSQL Global Development Group. "CREATE POLICY". PostgreSQL 19 Documentation.
- a b Palmer, Matt (29 May 2025). "Statement on CVE-2025-48757". mattpalmer.io.
- a b Supabase (19 November 2026). "Securing your API". Supabase Docs.
- a b c Supabase (2 October 2026). "Advisors". Supabase Docs.
- back "CVE-2025-48757", published 30 May 2025. OpenCVE (copy of the CVE and NVD record).
- back Pollock, Greg (23 September 2026). "Everything Everywhere: Systemic Data Exposure in Supabase Apps". UpGuard.
- back Crissy Field GmbH (undated; reported with Handelsblatt on 2 November 2026). "Lovable: Many Apps Built on the Platform Expose Sensitive Data". Crissy Field research.
External links
- Authorization Cheat Sheet, OWASP Cheat Sheet Series