All articles

Back-end13 min read

App built with AI: what to check before you ship

Security checklist for apps generated in Lovable, Bolt or Cursor: Supabase RLS, secret key out of the front end, AI key on the server, storage and a 5-minute test.

Also in Português, Español, Français

Tools like Lovable, Bolt and Cursor put an app online in an afternoon: login screen, sign-up, database, all working. And that's where the trap is. Working is not the same as being protected. An app can log in, save and list things just fine and, at the same time, hand every user's data to anyone who knows how to ask.

This isn't a hypothesis. In early November 2026, research published together with the German newspaper Handelsblatt analyzed more than 150 thousand projects built on Lovable and found thousands of sites returning user data with no login at all. This post explains why that happens and brings the checklist I would run before shipping any AI-generated app.

An honest warning: I didn't test anyone's app. The numbers come from the sources linked at the end, and the SQL and code examples follow the Supabase documentation. The images are illustrations I drew to explain each part.

TL;DR#

  • The problem is almost never the AI writing "hackable" code. It's the app going live without the database access rules, because nothing on screen shows they're missing.
  • In Supabase, the key that goes to the browser is public by nature. What protects the data is Row Level Security (RLS): rules in Postgres that say who can read and write each row.
  • RLS on every exposed table, with a real policy (no using (true) on private data).
  • The secret key (formerly service_role) and AI or payment keys never go to the front end. A variable with the VITE_, NEXT_PUBLIC_ or EXPO_PUBLIC_ prefix ends up in the bundle, and the bundle is public.
  • Do the 5-minute test: take the URL and the key your own site already sends and query a table with curl, without logging in. If other people's data comes back, don't ship.
  • Repeat after every change. The AI touches a table and the rule may go with it.

What happened#

The research is by Crissy Field, a German security company, in partnership with Handelsblatt. They used Common Crawl (a public archive of the web) to find Lovable-built sites published between December 2025 and September 2026:

  • 159,041 projects analyzed, of which 34,545 used Supabase as their database.
  • 24,664 sites returned database records right on page load, without login. That alone isn't a flaw: a blog shows posts to everyone on purpose.
  • Doing only reads with the same public key the site already uses, they found emails in 10,560 tables across 7,403 sites. That's not a confirmed leak rate either, but it's a strong signal.
  • Among the examples: a German forum with more than 80 thousand profiles and more than 200 thousand chat messages, more than a thousand records with passport numbers, ticket data and restaurant data with payment information.

The cause they point to is access control mistakes. And it's not the first time: in 2025, a similar problem became CVE-2025-48757, scored 9.3 (critical), described as insufficient Row Level Security policies in Lovable-generated sites, allowing tables to be read and written without authentication. Lovable disputes the record, arguing that protecting the data is each customer's responsibility.

Both readings hold a piece of truth, and that's why this post exists: the tool generates it, but whoever ships it answers for what they shipped.

Why it happens: the front end talks straight to the database#

In a traditional app, the browser talks to your server, and the server decides what to return. In the model Lovable and Bolt usually generate with Supabase, there's no server in between: the browser talks straight to the database API, using a key that's embedded in the site's JavaScript.

That key is the publishable key (sb_publishable_..., formerly anon). It's public on purpose: anyone who opens DevTools sees it. The Supabase documentation uses a good image: the public key is the one taped to the front door, and it only opens the lobby. What separates the lobby from the apartments is RLS.

The public key is the same for everyone. What decides what each person sees is each table's RLS policy

Without RLS, a table in the exposed schema (public, by default) can be read and written by any role that has permission on it, and Supabase grants broad permissions by default to the anon (visitor) and authenticated (logged in) roles. In other words: a table without RLS is an open table.

And notice that the app works the same in both cases. The "my orders" screen filters by user in JavaScript, so it looks right. But the filter is in the front end, and whoever calls the API directly skips the front end.

The 5-minute test#

Before the checklist, a test anyone can do on their own app:

  1. Open your site, open DevTools and go to the Network tab.
  2. Find a request to https://<your-project>.supabase.co/rest/v1/.... Its headers have the project URL and the public key (apikey).
  3. Without being logged in, query a table that stores user data:
# Use your own project URL and the publishable key your site already sends.
curl "https://YOUR_PROJECT.supabase.co/rest/v1/profiles?select=*&limit=5" \
  -H "apikey: YOUR_PUBLISHABLE_KEY"
Same query, no login. An empty list is what you want to see

If you get [] back (or a permission error), great. If profiles, emails or orders from other people come back, the app isn't ready. Do the same logged in as a test user and check that only that user's data shows up.

Important: do this only on your own app. Querying the database of a site that isn't yours, even with the key it exposes, may be a crime depending on the country.

The checklist#

1. RLS on for every exposed table#

In the Supabase SQL Editor, this query lists the tables in the public schema that have no RLS:

select schemaname, tablename
from pg_tables
where schemaname = 'public'
  and not rowsecurity;

Every table that shows up here is open. Turning RLS on is one line:

alter table public.notes enable row level security;

With RLS on and no policy, nothing is reachable through the API with the public key. That's the safe behavior: close everything, then open only what's needed. The Supabase dashboard also has Advisors, which flag tables without RLS and other slip-ups. Worth opening before you ship.

2. A real policy, one per operation#

Turning RLS on closes the door. The policy says who gets in. The pattern for data that belongs to one person:

create policy "Users read their own notes"
on public.notes for select
to authenticated
using ((select auth.uid()) = user_id);
 
create policy "Users create notes for themselves"
on public.notes for insert
to authenticated
with check ((select auth.uid()) = user_id);
 
create policy "Users update their own notes"
on public.notes for update
to authenticated
using ((select auth.uid()) = user_id)
with check ((select auth.uid()) = user_id);

Two details the AI often gets wrong:

  • using (true) opens everything. It makes sense on a table of public posts, not on a table of orders. If the AI "fixed" a permission error by writing using (true), it turned off security for that table.
  • with check on insert and update. using says which rows the person can see or touch. with check says what the row may look like afterwards. Without it, someone can create a note with another person's user_id.

3. Permissions don't live in a column the user edits#

RLS works by row, not by column. If the policy lets a person update their own profile, they can update any column of that profile. So if the profile has is_admin or plan, a simple update through the API turns any user into an admin or a premium subscriber.

The way out is to keep privileges in a separate table that the user can only read:

create table public.user_roles (
  user_id uuid primary key references auth.users on delete cascade,
  role text not null default 'member'
);
 
alter table public.user_roles enable row level security;
 
create policy "Users read their own role"
on public.user_roles for select
to authenticated
using ((select auth.uid()) = user_id);
 
-- No insert, update or delete policy: only your server, with the secret key, changes roles.

The same goes for Supabase Auth's user_metadata: users can change that field themselves. A policy that trusts a role stored there is a policy the user controls.

4. Views bypass RLS#

A view created the default way runs with the permissions of whoever created it, and that's why it ignores the RLS of the tables underneath. The AI loves creating a view to "gather the dashboard data". On Postgres 15 or newer, the fix is:

create view public.order_summary
with (security_invoker = true)
as select id, user_id, total, created_at from public.orders;

With security_invoker, the view respects the policies of whoever is querying.

5. The secret key stays on the server#

The secret key (sb_secret_..., formerly service_role) ignores RLS completely. It exists to run on your server, in an Edge Function, in a scheduled job. In the browser or inside a mobile app, it hands the whole database to whoever opens the bundle.

Two ways it leaks without anyone noticing:

  • Public prefix. Every variable with VITE_, NEXT_PUBLIC_ or EXPO_PUBLIC_ is copied into the code that goes to the user. A secret key with that prefix is a published key.
  • Error "fix". A permission error shows up, the AI swaps the public key for the secret one and everything works. It works because it turned security off.

After the build, search what's about to be shipped:

npm run build
grep -rEo "sb_secret_[A-Za-z0-9_-]+|sk-[A-Za-z0-9_-]{20,}" dist/ | head

If anything shows up, the key was published. Remove it from the front end and rotate the key in the dashboard, because the old one may already be in some cache.

6. AI, payment and email keys too#

An app built with AI often uses AI, and the AI API key is the one that shows up in the front end the most. The OpenAI SDK, for example, only agrees to run in the browser with an option called dangerouslyAllowBrowser. The name says it all:

// Bad: this key ships in the bundle, and anyone can spend your quota with it.
const client = new OpenAI({
  apiKey: import.meta.env.VITE_OPENAI_API_KEY,
  dangerouslyAllowBrowser: true,
})

With the key in the front end, anyone uses your quota, and the bill comes to you. Its place is a function on the server, which checks who is calling and validates the input before passing it on:

// supabase/functions/summarize/index.ts
import { createClient } from 'npm:@supabase/supabase-js@2'
 
Deno.serve(async (req) => {
  // Act as the caller, so RLS still applies to anything this function reads.
  const supabase = createClient(Deno.env.get('SUPABASE_URL')!, Deno.env.get('SUPABASE_ANON_KEY')!, {
    global: { headers: { Authorization: req.headers.get('Authorization') ?? '' } },
  })
 
  const {
    data: { user },
  } = await supabase.auth.getUser()
  if (!user) return new Response('Unauthorized', { status: 401 })
 
  const { text } = await req.json()
  if (typeof text !== 'string' || text.length > 5000) {
    return new Response('Invalid input', { status: 400 })
  }
 
  // The AI key lives only in the function's secrets, never in the client.
  const response = await fetch(Deno.env.get('AI_API_URL')!, {
    method: 'POST',
    headers: {
      Authorization: `Bearer ${Deno.env.get('AI_API_KEY')}`,
      'Content-Type': 'application/json',
    },
    body: JSON.stringify({ input: `Summarize: ${text}` }),
  })
 
  return new Response(await response.text(), {
    status: response.status,
    headers: { 'Content-Type': 'application/json' },
  })
})

The same rule applies to payment gateway keys, email service keys and anything that costs money or speaks on behalf of your company.

7. A server function doesn't trust what the front end sends#

When the logic moves to an Edge Function or API route, the mistake changes place. The most common ones:

  • Taking the user_id from the request body. Whoever calls the API chooses what to send. The user is who the token says they are (auth.getUser()), not who the JSON says.
  • Using the secret key for everything inside the function. Then RLS doesn't apply in there, and the function becomes the back door. Use the secret key only in the part that needs it.
  • Hiding the admin button and thinking that's a permission. A hidden button is interface. The check has to be in the database or on the server.

8. Storage: a public bucket is public#

A file in a public bucket can be reached by anyone with the URL, without login. That's fine for avatars and product images, not for documents, receipts or photos of an ID card.

For private files, use a private bucket and policies on the storage.objects table. The pattern where each user has their own folder:

create policy "Users read files in their own folder"
on storage.objects for select
to authenticated
using (
  bucket_id = 'documents'
  and (storage.foldername(name))[1] = (select auth.uid()::text)
);

Do the same for insert, update and delete, and to show the file on screen, generate a signed URL, which expires.

9. Secrets out of the repository#

  • .env in .gitignore before the first commit.
  • If a key was already committed, deleting the file doesn't fix it: it's still in the Git history. Rotate the key.
  • Public GitHub repositories are scanned by bots looking for keys all the time.

10. Usage limits#

Sign-up, login, sending email and AI calls are the targets of abuse. Check the Auth rate limits in the Supabase dashboard, turn on captcha at sign-up if the app is open to the public and put a per-user limit on the functions that cost money.

11. Repeat after every change#

This is the item that weighs the most day to day. You ask the AI to "add a phone field to the profile", it recreates the table, and the policies may not come along. The research's own recommendation goes the same way: review permissions and separation between accounts before putting in real data, and repeat the check after every change.

You can ask the AI to write the policies, and it usually writes them well when asked explicitly. But the checking is yours: the query for tables without RLS and the curl test take five minutes.

What if it isn't Supabase?#

The idea is the same in any architecture where the front end talks straight to the database. In Firebase, the role of RLS belongs to Security Rules, and allow read, write: if true is exactly the same open door. If the app has its own server in between (which Cursor often generates, depending on the request), the checklist changes place but not subject: authentication on every route, never trusting the id that comes from the front end, secrets only on the server.

Automated tools help and are worth using, but they don't replace a real review when the app is going to store other people's sensitive data, like documents, health or payment information.

Checklist#

  • The query for tables without RLS comes back empty.
  • Every table with user data has a policy per operation, with with check on insert and update.
  • No using (true) policy on private data.
  • Privileges (admin, plan, balance) outside the columns the user edits, and outside user_metadata.
  • Views with security_invoker = true.
  • Secret key and AI, payment and email keys only on the server, with no public prefix.
  • grep on the build finds no key.
  • Functions check the user through the token and validate the input.
  • Private bucket for private files, with a per-folder policy and a signed URL.
  • .env out of Git, and any leaked key was rotated.
  • Rate limits on Auth and on the functions that cost money.
  • curl test without login and with a test user, repeated after every change.

References#

  • Back-end
  • security
  • supabase
  • ai
  • lovable
  • postgres
  • rls

Written by

Software engineer and designer. I write about what I run into while building apps, APIs and products.