Skip to content

[ Anolilab — Article / AI ]

Is AI-generated code secure? What an audit finds

AI code runs but is often insecure. What studies show, which gaps an audit finds in Lovable, Cursor and Bolt apps, and how to check your own app.

Article by
Daniel Bannert · Founder · Anolilab

Advertising notice: Links marked with * or “Paid link” are affiliate links (advertising). If you buy through them I earn a commission, at no extra cost to you. Recommendations that pay nothing are marked too. More in the privacy policy

In short

Not by default. AI tools write code that runs. They only think about security when someone asks for it. In tests by Veracode, 45% of AI-generated code samples contained a security flaw in 2025; in October 2026 the tested models passed 62% of tests on average. In 2025, parts of the database of 170 Lovable apps could be fetched without logging in. Before your prototype handles real customer data or payments, check at least for keys in the frontend, database permissions, login checks on the server and your Git history.

How often this goes wrong in real apps shows in two studies of publicly reachable projects. Escape scanned more than 5,600 apps, most of them built with Lovable, and found over 2,000 vulnerabilities, more than 400 exposed secrets such as API keys, and 175 cases of personal data, including medical records and IBANs (Escape, October 2025). Because the scan was passive, Escape itself calls this a lower bound. A preprint on arXiv examined 200 deployed apps built with Claude Code or Lovable: 91% had at least one vulnerability, and about two thirds of the 1,186 findings were rated critical or high (Deng et al., 2026).

This article is for founders who built a prototype with Lovable, Cursor or Bolt and want to know whether they can hand it to real users. Which AI tool fits which job is covered in the comparison of AI coding tools. This one is about what comes after.

What research says about the security of AI-generated code

Several studies reach the same result: AI models write working code but often pick the insecure way, and people review it less than they should.

StudyWhat was measuredResultLimit of the finding
Veracode, GenAI Code Security Report (2025) and Fall 2026 update (October 2026)Code from over 100 language models in Java, JavaScript, Python and C#, 18 current models in the updateIn 2025, 45% of the code samples contained a risky security flaw, and larger and newer models did no better. In October 2026 the models passed 62% of tests on average, the best ones 73%.Single coding tasks, not whole apps. Veracode sells security testing.
Perry et al., Stanford, ACM CCS 202347 people solve security tasks, 33 of them with an AI assistantThe group with AI wrote significantly less secure code and more often believed it was secure. When signing messages, 3% of the solutions with AI were secure, 21% without AI.Small sample, older model (Codex from 2022).
Spracklen et al., USENIX Security 2025576,000 code samples from 16 models in Python and JavaScriptCommercial models invented on average at least 5.2% of the packages they recommended, open-source models at least 21.7%. In total 205,474 distinct invented package names.Measures recommendations, not installed packages.
GitGuardian, State of Secrets Sprawl 2026Public GitHub commits in 2025 (28.6 million new secrets found)Commits co-authored by Claude Code leaked a secret about twice as often as the average across all public commits.Shows a correlation, not proof that the AI wrote the key. The overview page does not give the exact rate.

The most important finding is in the Stanford study: people who work with AI feel more secure even though their code is less secure. That gap between feeling and reality is exactly what an audit finds.

The Lovable case: CVE-2025-48757

In 2025, Lovable apps usually had a Supabase database behind them, and the browser talked to it directly, using a public key in the frontend. With Supabase that is by design and only safe if every table has Row Level Security (RLS): rules in the database that decide which rows a user may read or change.

Since 13 May 2026, Lovable has built new apps with TanStack Start. These apps can run code on the server, for example server functions that access the database with the secret key. Database and login still run on Supabase. Wherever the browser still queries the database directly, only RLS protects the data.

In March 2025 the security researcher Matt Palmer checked the home pages of 1,645 Lovable projects. In 170 of them, about 10%, he found 303 endpoints with RLS that was too weak. According to his report, names, phone numbers, API keys, payment details and other personal data could be fetched through them without logging in. In one app he could insert a record with "payment_status": "paid", in other words fake a payment.

Lovable introduced a "Security Scan" in April 2025. Palmer criticises that it only checks whether any RLS policy exists, not whether it is correct. The flaw is published as CVE-2025-48757. According to that entry, Lovable disputes that it is a flaw in the platform: each customer is responsible for the security of their own app. The pattern is not limited to Lovable: every app whose frontend talks to Supabase or Firebase directly depends on correct database rules, whichever tool built it.

What an audit typically finds in AI-built apps

The following seven points are the gaps an audit of a Lovable, Cursor or Bolt app looks for first. They match the most common risks in the OWASP API Security Top 10.

In the public scans, points 1 and 2 come up most. Symbiotic Security checked 1,072 apps with a Supabase backend and found a critical issue in 173 of them (16%). Almost all of these were tables that could be read, changed or deleted without logging in; in 172 apps anyone could delete records (Symbiotic Security, June 2026). Symbiotic also sells security testing.

What that means in practice shows in the case of Moltbook, a social network for AI agents. In January 2026, Wiz found a Supabase key in the site's JavaScript just by browsing it. Because RLS was missing, the key gave anyone read and write access to the whole database, including 1.5 million API tokens and 35,000 email addresses. Every account could be taken over with a single API call (Wiz).

1. Secret keys in the frontend

Anything that reaches the browser can be read by anyone. With Vite, which Lovable projects are built on, every variable with the VITE_ prefix ends up in the shipped code, and the Vite documentation explicitly warns against putting API keys there. The most dangerous ones are Supabase's service_role or secret key, which according to the Supabase documentation bypasses all database rules, and keys for Stripe or OpenAI. Supabase's public anon or publishable key may sit in the frontend, but only with RLS. According to its documentation, Supabase is retiring the legacy anon and service_role keys by the end of 2026 (as of November 2026); their successors start with sb_publishable_ and sb_secret_.

2. Missing or overly open Row Level Security

A table without RLS can be read and written by anyone who has the public key. Often there is a rule for reading but none for inserting, updating or deleting, or a rule such as using (true) that allows everything. Supabase's advice: enable RLS on every table in a publicly exposed schema.

3. API routes without login checks

The interface hides the admin area, but the endpoint behind it does not check who is asking. A second pattern: the route checks the login but not whether the record belongs to that user. Change the number in /api/invoices/123 and you see someone else's invoices. OWASP lists this as Broken Object Level Authorization, in first place.

4. No input validation

Form data goes into the database unchecked or is shown again unfiltered. That opens the door to cross-site scripting: an attacker stores script code that runs in other users' browsers. In the 2025 Veracode test the models failed to protect against cross-site scripting in 86% of cases, and in the October 2026 update they passed only 18% of these tests on average. Validate every input on the server with a schema, for example with Zod, and not only in the form. Against cross-site scripting, also make sure user input is only ever output escaped: React does this on its own, except with dangerouslySetInnerHTML.

5. Outdated or invented packages

AI models suggest packages in versions with known flaws, or packages that do not exist at all. Attackers register those invented names and put malicious code in them. This is called slopsquatting. The USENIX study above shows why it works: when the researchers asked the same question ten times, 43% of the invented packages came back in all ten answers. An attacker can therefore predict which names are worth registering.

6. No rate limiting

Login, password reset, contact form and endpoints that call an AI API can be called as often as anyone likes. That allows password guessing and, for AI features, can run up a large bill with the provider. OWASP calls this Unrestricted Resource Consumption.

7. Secrets in the Git history

A key that was committed once stays in the history, even after it has been deleted from the current file. According to the GitGuardian 2026 report, 64% of the valid secrets leaked publicly in 2022 were still usable four years later. A deleted key is not dealt with: it has to be revoked with the provider and replaced.

Self-check: how to check your prototype yourself

These steps do not replace an audit, but they uncover the biggest gaps. For some of them you need a terminal and access to the Supabase dashboard.

Only check your own app

Run every step only against your own app and your own database, or with the operator's written permission. Querying other people's systems is not allowed, even with a public key, and can be a criminal offence (in Germany §§ 202a ff. StGB). Not legal advice.

  1. Search the frontend for keys

    Open your app in the browser, then the developer tools, "Sources" or "Network" tab. Search for sb_secret_, sk_live_ and sk-. Older Supabase keys start with eyJ: only the decoded content shows whether one of them is the service_role key. The easiest way is to build locally and search the build folder (commands below).

  2. Check RLS for every table

    In the Supabase dashboard, the "Table Editor" shows for each table whether RLS is enabled. Or run the query below in the SQL editor: every row with false is open.

  3. Query your own database without logging in

    Fetch a table of your own app with its public key without being logged in. If data comes back that should not be public, the RLS policy is too open.

  4. Open another test account's records

    Create two test accounts in your own app. With account A, open a record, copy the URL or the ID from the Network tab and open it with account B. If you see the data, the check on the server is missing.

  5. Check packages

    Run npm audit. Look up every package in your package.json that you do not recognise on npmjs.com: how old is it, who maintains it, is there a repository?

  6. Scan the Git history

    Run Gitleaks (open source, no commission) over the whole history. Revoke and replace every key it finds with the provider.

  7. Test repeated login attempts

    In your own app, enter a wrong password for a test account ten times in a row. If you are never slowed down, a limit is missing. Check this for endpoints that call an AI API too.

Self-check in the terminal
# 1. Search the build for secret keys (folder depends on the project: dist, build, .next/static)
npm run build
grep -rhoE "sb_secret_[A-Za-z0-9_-]+|sk_live_[A-Za-z0-9]+|sk-[A-Za-z0-9_-]{20,}" dist/

# 1b. Show the role of every Supabase JWT in the build: "service_role" must not appear
grep -rhoE "eyJ[A-Za-z0-9_-]+\.eyJ[A-Za-z0-9_-]+" dist/ | cut -d. -f2 | tr '_-' '/+' \
  | while read -r p; do echo "$p==" | base64 -d 2>/dev/null; echo; done | grep -o '"role":"[a-z_]*"'

# 3. Query your own table without logging in (insert URL, table and public key of your own project)
curl "https://YOUR-PROJECT.supabase.co/rest/v1/TABLE?select=*" \
  -H "apikey: YOUR_PUBLIC_KEY"

# 5. Known flaws in dependencies
npm audit

# 6. Search the whole Git history for secrets
gitleaks git -v .
RLS status of all tables (Supabase SQL editor)
select tablename, rowsecurity
from pg_tables
where schemaname = 'public';

If any of these steps turns something up, fix it before you build more features. And only test your own app, as the note above says.

When an audit is worth it

The self-check finds open doors. An audit also checks whether the rules fit the logic of the app, and that is something no automatic scan can do: whether a team member may see the whole team's invoices is decided by your business model.

An audit is worth it above all:

  • before real customer data goes in, especially health, financial or children's data;
  • before the app handles payments or unlocks access that costs money;
  • before a launch, a funding round or an enterprise customer who asks about security;
  • when nobody on the team can read the code the AI wrote.

For an AI-built app I do this as a Vibe-Code-Audit: a written report on security, code quality and performance, with a prioritised list of what to fix first. If the codebase is larger or was built by an agency, a technical audit fits better.

After that, you decide who fixes the points: you, your team, or me. If you don't code yourself, I go through the list with you step by step until you can launch the app. I change design and features only after we have agreed on it.

What helps between two audits

An audit is a snapshot. Every new instruction to the AI can reopen a gap. Two things help for good: Gitleaks as a pre-commit hook, so no key gets into the repository again, and a review of every pull request before it goes live.

The review gets easier when the diff is clean. That is why I wrote the skill deslop: it removes what AI agents typically leave behind in a branch's changes, such as narrating comments, needless defensive code and type casts that hide errors. The code's behaviour stays the same. It is open source under the MIT licence and runs in Claude Code, Codex, Cursor and other agents. It does not replace a security check.

For a more thorough review of the code I maintain deepsec (open source under the Apache 2.0 licence, no commission), a fork of the tool of the same name from Vercel Labs. It first searches the code with fixed patterns for suspicious spots, such as route handlers, dangerouslySetInnerHTML or environment variables holding secrets, and then has an AI agent read and assess each one. With deepsec process --diff origin/main it checks only the files a pull request changes. The AI review needs access to a language model, for example your own API key or a Claude or Codex subscription, and costs money depending on the size of the codebase. --max-cost-usd sets an upper limit. Because deepsec only reads the repository, it does not see the rules in the Supabase dashboard, and it does not replace an audit either.

[ Anolilab — Blog ]

More hands-on writing on AI, web development and infrastructure.

Related articles.

[ Anolilab — Contact ]

Tell me what you're building. I'll tell you how I can help.

Let's talk.

Quick response.
If you're ready to create and collaborate, I'd love to hear from you.
Clear next steps.
After the consultation, I'll give you a detailed plan.
Alternatively, you can email me directly at hello@anolilab.com