Writing

Vibe coding security: the holes AI leaves in your app, and how to fix them

Updated 7 min read

AI has made it easy to build an app, and also easy to break into one.

On the building side, the numbers are bad. When researchers scanned 1,645 apps made with Lovable, 170 of them let anyone read and write their database, including personal data, payment details and API keys. In early 2026, Wiz found that Moltbook, a site built with AI, had its database key in the frontend code with no access rules, exposing 1.5 million API tokens and 4,060 private messages. Veracode tested more than 100 models on coding tasks and found they wrote insecure code 45% of the time.

On the attacking side, things are speeding up too. An AI pentester called XBOW reached number one on HackerOne's US leaderboard in 2025. Anthropic reported a state-backed group that used AI for 80 to 90% of a hacking campaign. And Mandiant's 2026 report estimates that, on average, attackers now exploit a vulnerability before the patch is even out.

So the gap between "it works" and "it's safe" matters more now. This post covers why AI-built apps have that gap and how to close it.

Why AI skips security

An AI coding tool aims for code that runs when you click the button. Security doesn't show at that moment, and an insecure app looks the same as a secure one in a demo.

Ask for "a login page" and you get a login page with no rate limit, because your demo works fine without one. Ask for "users can save notes" and you get notes with no check that user A can't read user B's, because your demo has one user. Any protection that doesn't affect the normal flow gets left out.

An attacker needs only one open hole, and you have to close all of them. Try it:

Attack your own app
6 of 6 doors open
Does the demo work?Yes
Copy the API key from the Network tabWorks
Change the id in the URL, read someone's notesWorks
Edit the price field to 1 and check outWorks
Type ' OR '1'='1 into the email boxWorks
Try 10,000 passwords against one accountWorks
Call your API from another websiteWorks
Turn defenses on one by one. The demo works the same the whole time, which is why these holes survive to launch. An attacker only needs one open door.

Here are the holes, most common first.

1. Logged in is not the same as allowed

This is the most common hole on the web. It is number one on the OWASP Top 10, the standard list of web security risks, under the name broken access control.

A logged-in user loads their notes with GET /api/notes?userId=123. They change 123 to 124 in DevTools. If they get someone else's notes, your app checks who you are (authentication) but not what you may touch (authorization).

Logged in is not the same as allowed
Session
userId: 123 (verified at login)
Request ยท change the id
GET /api/notes?userId=
where: { userId: req.query.userId }
Response200 OK
Owner: You

Buy milk. Call the bank on Monday.

You are logged in as user 123. Change the id the way an attacker would in DevTools, then switch the server to use the session instead.

The fix is for the server to ignore the id in the request and use the identity from the session.

// wrong: trusts the id the request asked for
const notes = await db.notes.findMany({ where: { userId: req.query.userId } })

// right: uses the verified identity from the session
const notes = await db.notes.findMany({ where: { userId: req.session.userId } })

If your frontend talks straight to Supabase or Firebase, the same rule lives in the database as row-level security. The public key in the browser is fine, since it is not a password. The rules keep the data safe, and missing rules are what exposed the 170 Lovable apps and Moltbook. Before launch, write one rule: a user can read and write only their own rows.

2. Secret keys in the frontend

AI tools often call a paid API straight from the browser:

fetch("https://api.openai.com/v1/chat/completions", {
  headers: { Authorization: "Bearer sk-proj-abc123..." }
})

Everything the browser sends is visible in the Network tab. Anyone can copy that key and spend your money. A scan of 5,600 public vibe-coded apps found more than 400 exposed secrets.

The fix is to move every call that needs a secret key to your own backend. The browser calls your server, and your server calls the paid API.

3. Secrets in git don't go away when you delete them

GitGuardian counted 28.65 million new secrets leaked on public GitHub in 2025, the biggest jump they have recorded. AI service keys alone rose 81%. Bots scan public repos for fresh keys within minutes, and deleting the file in a new commit doesn't help, because git keeps the history.

If a secret ever touched git:

  1. Rotate it first. Make a new key and assume the old one is stolen. This is the step that protects you.
  2. Then clean it up. Remove it from history with git filter-repo, and add .env to .gitignore.

4. Never trust what the client sends

A checkout form sends price=499. An attacker edits it to 1 in DevTools. If your server saves whatever arrives, you just sold it for one rupee.

A check that exists only in frontend JavaScript helps honest users and stops nobody else. The server must decide prices, totals, permissions and limits from its own data. For a price, look up the real amount from the product id and ignore the number in the form.

5. Injection: when input becomes instructions

If user input is pasted into a database query, the input can change the query.

Type into the email box
Email
What the database runs
SELECT * FROM users WHERE email = '' OR '1'='1'
Result4 rows
amit@example.com
priya@example.com
rahul@example.com
sara@example.com

The quote closed the string, and OR '1'='1' is always true. Every row comes back.

With concatenation, the input becomes part of the query. With parameters, the database gets the query shape first and the value second, so input can never change what runs.

The fix is parameterized queries. The database gets the query first and the values second, so input is only ever treated as a value.

db.query("SELECT * FROM users WHERE email = $1", [email])

AI apps have a newer version of this: prompt injection, number one on the OWASP Top 10 for LLM apps. If you put user text into a prompt, that text can override your instructions. You can't fully prevent it, so limit the damage. Never give the model more power than you would give the raw user. Don't let model output trigger real actions, run code or read private data on its own.

6. No rate limit means unlimited attempts

A login endpoint with no limit accepts thousands of password guesses a minute. An API that calls a paid model with no limit lets one script run up your bill overnight.

Time to try the 10,000 most common passwords
Attempts allowed
10,000 per minute
Whole list tried in
1 minutes
Log scale. Longer bar means a slower attack.
One script, one account. A rate limit doesn't make guessing impossible, it makes it slow enough to notice and stop.

The fix is to cap requests per client, for example five login attempts per minute per IP, at the server that receives all traffic. One catch: behind a proxy, every request arrives with the proxy's IP. Read the real client address from the X-Forwarded-For header, or you will block all your users at once.

7. CORS set to allow everyone

When an AI tool hits a CORS error, the quickest way to make it go away is Access-Control-Allow-Origin: *. That lets any website call your API and read the response. With cookies involved, a malicious page in another tab can act as your logged-in user.

The fix is to allow only your own site.

app.use(cors({ origin: "https://yourapp.com", credentials: true }))

8. Packages that don't exist

AI tools sometimes suggest installing packages that were never published. A USENIX 2025 study of 576,000 code samples found models invented package names 5% to 22% of the time. Attackers can register those names. When a researcher published one empty, made-up package that models kept suggesting, it got more than 30,000 downloads in three months.

The fix is to check, before you install anything an AI suggested, that the package exists, is popular, and is the one you meant.

The 30-minute pre-launch check

If you have half an hour before launch, go in this order. The most damaging comes first.

  1. Rotate any secret that ever touched git. Move all keys to environment variables.
  2. Move every paid API call behind your own backend. No secret keys in frontend code.
  3. Check access on every endpoint and table. Use the session identity, never the id in the request, and turn on row-level security.
  4. Re-check all input on the server and use parameterized queries. Treat the frontend and anything a user typed as hostile.
  5. Rate-limit login and anything expensive, and lock CORS to your own site.
  6. Verify every package an AI added before you ship it.

Then do one test by hand. Log in as one user, open DevTools, and change an id in a request to another user's. If you get their data back, fix that before anything else.

None of these problems are new. What has changed is how fast an app can go from prompt to production, and how fast someone can find the hole you left.