Diesen Artikel auf Deutsch lesen →
security · · · Streatix

Supabase RLS Disabled: How Our Lovable App Leaked Data

How a Lovable reference app shipped with Supabase RLS disabled, why we looked in the wrong place first, and the three SQL statements that close the leak.

We audit AI-generated codebases, and to learn what the tools ship by default we also build deliberately broken reference apps. One of them, a Lovable-built multi-tenant invoicing SaaS, shipped with Supabase RLS disabled on every table and leaked every user’s data to every other user on day one. The fix took three SQL statements. Finding the bug took most of an afternoon, mostly because we kept looking in the wrong place.

We built it the way a founder would

The reference app is small on purpose: Next.js App Router on the frontend, Supabase for auth and Postgres, deployed to Vercel. Three tables (users, invoices, customers) with the user_id foreign keys you’d expect. Two test accounts, Alice and Bob, each with a handful of invoices in their own dashboard.

We prompted Lovable with “build a multi-tenant invoicing tool with user accounts and an invoice list,” accepted the output, and deployed it. No schema review. We never opened the Supabase dashboard. The point was to see what the default produces, untouched.

Login worked. The dashboard rendered Alice’s invoices when Alice logged in, Bob’s when Bob logged in. Each user saw their own data and nothing else. It demoed cleanly.

The decision Lovable made for us

Lovable generated the schema with user_id columns on every table that needed tenancy: invoices.user_id, customers.user_id. The API routes filtered by the authenticated user. Every select had .eq('user_id', user.id) chained on.

That was reassuring. The data model knew about tenancy, the query layer used it, and we assumed row level security was enforcing ownership in the database itself. Why else would the user_id column exist?

That assumption is the bug.

The symptom: one curl, every user’s invoices

We logged Alice into the app, copied her session cookie, and ran a manual test:

curl https://reference-app.test/api/invoices \
  -H "Cookie: sb-access-token=ALICE_TOKEN"

Got Alice’s invoices back. Five rows. As expected.

Then we tried something the dashboard never would: the right session, plus a query parameter the frontend never sends. We’d spotted an exploitable line in the route handler in passing:

// app/api/invoices/route.ts
export async function GET(request: Request) {
  const supabase = createServerClient()
  const { data: { user } } = await supabase.auth.getUser()
  const userId = new URL(request.url).searchParams.get('user_id') ?? user.id
  const { data } = await supabase
    .from('invoices')
    .select('*')
    .eq('user_id', userId)
  return NextResponse.json({ invoices: data })
}

The searchParams.get('user_id') ?? user.id line lets the client override which user_id the query filters on. Sloppy, and the kind of line a prompt like “let admins view other users’ invoices” invites when it doesn’t spell out the authorization rules.

So we tried it:

curl "https://reference-app.test/api/invoices?user_id=BOB_USER_ID" \
  -H "Cookie: sb-access-token=ALICE_TOKEN"

Bob’s invoices came back. Alice, logged in, reading Bob’s data.

That alone is a serious API-layer bug, a missing authorization check we’d catch in any audit. It also led us to the real one.

The wrong first theory

We assumed the bug was the API handler. Fix it: ignore the query parameter, always use the authenticated user’s ID, ship the patch. Standard auth-layer audit finding.

We were about to file it that way when one of us stopped: “Wait. Even if the API is buggy, why is Supabase returning rows that don’t belong to Alice? Shouldn’t the database refuse?”

So we checked. Instead of going through the app, we hit Supabase’s REST endpoint directly with the anon key (the publishable key on newer projects), the same public key the browser ships with and nothing more:

curl "$SUPABASE_URL/rest/v1/invoices?user_id=eq.BOB_USER_ID" \
  -H "apikey: $SUPABASE_ANON_KEY"

Bob’s rows came back. No authorization error, no filtering. That by itself is the tell: a table with RLS enabled but no matching policy returns nothing, default deny, so rows coming back to the anon role means RLS isn’t enforcing at all. A bare SELECT in the SQL editor would have hidden it, because Dashboard queries run as the postgres admin role and return rows regardless. You’d have to SET ROLE anon first to see what a stranger sees. The anon REST path is the one a stranger can actually reach, and it was wide open.

That’s when we knew the real problem wasn’t in the API layer.

With Supabase RLS disabled, the database had no idea tenants existed

We opened the Supabase dashboard, went to the invoices table, and looked at the Authentication panel. There was a single toggle at the top:

Enable Row Level Security

RLS prevents anonymous access to rows by default.

The toggle was off.

We checked the other tables. customers: off. users: off. Every table Lovable created shipped with RLS disabled.

This is the failure mode we now call the open-database default. A table created with raw SQL starts with RLS off, Lovable’s migration didn’t turn it on, and the database became a public read endpoint for anyone holding the anon key, which every visitor’s browser already has.

The user_id columns Lovable created are decorative. They exist for the API layer to filter on. Without RLS the database enforces nothing.

The root cause: two systems, each assuming the other handled it

Supabase’s default depends on how the table gets created. Tables created through the dashboard have RLS enabled by default; tables created in the SQL editor or with other tools need it enabled explicitly, and a generated migration takes that second path. The RLS docs tell you to enable it, and say that once you do, no data is accessible through the API until you create policies. Our guess at why the SQL path stays open is that practical wall: RLS on with no policies returns nothing, and a new user bootstrapping a project doesn’t know why.

Supabase is also changing the platform default so that exposing new tables to the Data API becomes opt-in, and default privileges now differ by project age and settings. On a project with automatic exposure off, this table wouldn’t answer the curl above until someone granted a role access to it. That narrows the window without adding a policy. Grant the role and the table is open again.

Lovable, generating code on top of Supabase, didn’t enable RLS either. The migration it scaffolded for our reference app looks like this:

CREATE TABLE invoices (
  id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
  user_id uuid REFERENCES users(id),
  amount integer NOT NULL,
  customer_email text NOT NULL,
  created_at timestamptz DEFAULT now()
);

No ENABLE ROW LEVEL SECURITY. No CREATE POLICY. The schema acknowledges tenancy through the user_id column, but enforces nothing.

Each side has a defensible reason. The SQL path stays out of the way of a new project. Nothing in our prompt asked for row level security, and Lovable generated what was asked. You end up with a working dashboard, multi-tenant-looking code, and a database that has no idea tenants exist.

The fix: three SQL statements turn row level security on

One ALTER and two policies bring the database into agreement with the data model it pretends to have:

-- 1. Enable RLS on the table
ALTER TABLE invoices ENABLE ROW LEVEL SECURITY;

-- 2. Allow users to read only their own rows
CREATE POLICY "Users read own invoices"
  ON invoices
  FOR SELECT
  USING (auth.uid() = user_id);

-- 3. Allow users to insert only rows owned by themselves
CREATE POLICY "Users insert own invoices"
  ON invoices
  FOR INSERT
  WITH CHECK (auth.uid() = user_id);

The USING clause runs on SELECT (and on the read side of UPDATE / DELETE). It returns true only for rows where auth.uid() (the Supabase function that resolves to the JWT’s user ID) matches the user_id column. Any row that doesn’t match is silently filtered out.

The WITH CHECK clause runs on INSERT and UPDATE. It refuses to write a row where user_id doesn’t match the authenticated user. This blocks the other common bug: clients setting user_id to someone else on insert.

Repeat for customers and any other tenant-scoped table. You’ll also want UPDATE and DELETE policies for tables that need them, structured the same way.

After applying these, that same anon-key call comes back empty, and querying Bob’s rows with Alice’s JWT returns nothing. The API exploit above stops working with the buggy handler still in place. The database refuses.

A second fix: write the negative test

The negative test that would have caught this bug from the start:

// __tests__/rls.test.ts
import { describe, it, expect } from 'vitest'
import { createClient } from '@supabase/supabase-js'

describe('RLS enforcement on invoices', () => {
  // A client authenticated as Alice: the public anon key plus Alice's access
  // token. PostgREST runs the query as the `authenticated` role with
  // auth.uid() resolving to Alice's id, exactly what a stranger's browser does.
  const alice = createClient(SUPABASE_URL, SUPABASE_ANON_KEY, {
    global: { headers: { Authorization: `Bearer ${ALICE_ACCESS_TOKEN}` } },
  })

  it("user A cannot read user B's invoices via direct query", async () => {
    const { data } = await alice
      .from('invoices')
      .select('*')
      .eq('user_id', BOB_USER_ID)

    expect(data).toEqual([])
  })

  it('user A cannot insert an invoice owned by user B', async () => {
    const { error } = await alice
      .from('invoices')
      .insert({ user_id: BOB_USER_ID, amount: 100, customer_email: 'x@x.com' })

    expect(error).toBeTruthy()
  })
})

This test, run against the broken version of the app, would have failed on the first assertion. Lovable didn’t write it for us, and nothing in the prompt asked it to.

One query shows which tables still have RLS disabled

You don’t need to click through the dashboard table by table:

SELECT schemaname, tablename, rowsecurity
FROM pg_tables
WHERE schemaname = 'public'
ORDER BY rowsecurity, tablename;

rowsecurity is true when row security is enabled. Any false in public needs an answer. Supabase’s Security Advisor flags the same state as an error-level lint, 0013_rls_disabled_in_public, and warns that anyone with your project URL can read, edit, and delete the data in that table. Both checks only tell you RLS is on. A USING (true) policy passes this query and this lint.

An uneasy truce

RLS solves the “wrong user reads wrong row” pattern. It does not solve several adjacent ones, and a clean RLS policy is not the same thing as a hardened multi-tenant database. The things RLS doesn’t catch:

  • Service-role keys bypass RLS entirely. If your client bundle leaks the service_role key (a secret key on newer projects), the policies above protect nothing, because that role has BYPASSRLS. The same key handed to a route handler walks around these policies by design, which is its own finding. Fixing RLS without rotating leaked service keys is a half-fix.
  • Cascade leaks via joins. If invoices has RLS but customers does not, and your API joins them, the customer rows come back unprotected. RLS is per-table; coverage needs to be complete.
  • Policies that look right but aren’t. A USING (true) policy looks like a policy but lets everything through. A policy that compares user_id to a JWT claim that doesn’t exist silently allows nothing, which often gets “fixed” by making the policy more permissive, defeating the purpose.
  • Performance. RLS policies that aren’t indexed can turn cheap queries into table scans. A rollout can fix the security problem and break the latency budget on the same afternoon.
  • Storage is a separate boundary. RLS covers table rows, not stored files. A Supabase Storage bucket left public, or an S3 bucket the app opened, serves documents to anyone with the URL no matter how tight your row policies are. Public S3 buckets are the same failure one layer over.
  • Lovable security doesn’t end at your schema. CVE-2025-48757 describes insufficient RLS in sites generated by Lovable through 15 April 2025. Lovable disputes it, on the grounds that each customer is responsible for protecting their application’s data. Lovable’s docs now describe a Quick scan that checks for tables without row level security; we haven’t tested whether it would flag this reference app. A flaw in the platform itself is another boundary again, as the 76-day Lovable data leak shows.

The audit we’d ship for an app in this state would flag the API-layer bug, the missing RLS, the schema’s lack of policies, and at least three of the cascade and edge-case patterns above. The three statements are where that work starts.

The columns say tenancy; the database doesn’t

A Lovable-built app with user_id columns looks like it has tenancy. The data model says it does. The query code says it does. The database, by default, does not.

If you want this for your own app

Thirty-minute audit, free. We curl the same endpoints and read the same files. List in your inbox within forty-eight hours.

Book a free audit