Someone built an app with AI over a weekend, posted the link, and woke up to a $4,000 OpenAI bill. They didn’t run up the charges. A bot found their exposed API key and used their account as a free playground while they slept.
That story keeps repeating because vibe coding security almost never comes up in the tutorials. You learn to prompt, deploy, and celebrate. Nobody mentions the part where 45% of AI-generated code ships with security flaws. So here’s the checklist I run before any AI-built app goes live. It takes about 30 minutes, and it has saved me from exactly the bill above.
Why AI-built apps leak in the first place
The numbers are rough, and they explain why vibe coding security deserves 30 minutes of your time. Veracode’s 2025 report found that 45% of AI-generated code contains security vulnerabilities. A May 2026 scan of over 5,000 vibe-coded apps went further: 40% exposed sensitive data, including medical info, customer records, and full chatbot conversation logs.
The reason is structural, not bad luck. AI models write code that works when everything goes right. Security matters when things go wrong. Models reproduce patterns from training data, so if your prompt describes an API integration, the model happily generates a hardcoded key right in the file, because that’s what the examples looked like.
There’s also no review gate. A dev shop has someone whose job is to say “wait, don’t ship that.” You, your prompt, and a deploy button don’t.
The clearest cautionary tale is Moltbook, a social network for AI agents built entirely with vibe coding. Researchers at Wiz found its database wide open: 1.5 million API tokens and 35,000 email addresses exposed within 72 hours of launch. The cause wasn’t sophisticated. One misconfigured setting in Supabase.
Check 1: set a spending limit before anything else
This is the one that prevents the four-figure invoice. OpenAI, Anthropic, and Google all let you cap monthly API spending. Most people never touch the setting.
Log into your provider’s dashboard today and find the usage limits page. Set a hard monthly cap that matches what the app actually needs, plus a little headroom. If a leaked key gets abused, the damage stops at your cap instead of your savings account.
Think of it as the circuit breaker for your app. You hope it never trips. You’ll sleep anyway.
Check 2: get your API keys out of the code
Open your project and search for anything that looks like sk-, AIza, or a long random string. Found one sitting directly in your code? That’s the leak waiting to happen.
Keys belong in environment variables, not in files. Every host worth using (Vercel, Netlify, Railway, Render) has a settings page for them. Move the key there, reference the variable in code, and never paste the key itself anywhere visible.
Two extra rules from OpenAI’s own security guidance: never put a key in browser or mobile app code where anyone can read it, and never commit one to a repository. Public or private, repos get scraped.
Check 3: lock down your database (the Moltbook mistake)
If your app uses Supabase or Firebase, this check matters most. These tools give you a public anon key that lives in your app’s frontend code. That’s normal and fine, with one condition.
In Supabase, the setting is called Row Level Security. When it’s on, strangers with your public key can only touch the rows you explicitly allow. When it’s off, that same key opens the whole database to anyone who views your page source. Guess which setting Moltbook had missed.
Open your Supabase dashboard, check every table, and make sure RLS is enabled with real policies. If you’re still choosing a backend, our Supabase vs Firebase comparison covers how each handles this. Firebase’s equivalent rules live in the Security Rules tab. Same idea: deny by default, allow on purpose.
Check 4: protect anything with an admin view
Plenty of vibe-coded apps have an admin page with no login, because the builder never asked for one. The app “works,” so it ships. Then a stranger guesses the URL.
Test it yourself. Can you reach /admin, /dashboard, or /users while logged out? If yes, add authentication before anything else. Supabase and Firebase both include auth you can wire up with a prompt to your AI tool: “Add email login and require it on the admin route.” That’s usually all it takes.
While you’re at it, make sure regular users can’t read each other’s data. Create a second test account and try to open the first account’s records. If you can, your database rules from check 3 need work.
Check 5: scan the app before you ship
Here’s the part most vibe coding security advice skips: you don’t have to catch flaws by eye. Free scanners do the boring part. Point a tool at your running app and it probes for the classic mistakes: exposed keys, open databases, missing security headers.
Your AI coding tool can help too. Paste this into Claude or ChatGPT along with your repo: “Act as a security reviewer. Find hardcoded secrets, missing authentication checks, and any place user input reaches the database unvalidated. List findings with file names.” You’ll get a to-do list in under a minute.
Is that a professional penetration test? No. Does it catch the 80% that sinks hobby apps? Every week it does.
Check 6: watch your logs for the first week
After launch, spend two minutes a day in your provider’s usage dashboard. You’re looking for anything weird: requests at 4am, API usage that spikes for no reason, traffic from countries your users don’t live in.
Bots start probing new apps within hours of deployment. They knock gently at first, so the early signs are small. Catching a weird pattern on day two is a non-event. Discovering it on your monthly invoice is the $4,000 story from the start of this article.
What to do if a key already leaked
Even solid vibe coding security habits miss something sometimes. Don’t panic, and don’t just delete the key from your code. Do these in order:
- Rotate the key in your provider’s dashboard (revoke the old one, generate a new one)
- Update your environment variable with the new key and redeploy
- Check the usage logs to see what the leaked key was used for
- Review your database for changes you didn’t make
Rotation kills the leak instantly, even if the key is already in someone else’s hands. Old key revoked means every request using it starts failing. Total cost: about ten minutes.
Ship it safe
Vibe coding is genuinely amazing. You can build things now that used to need a co-founder who codes. Just build them with the seatbelt on, because vibe coding security comes down to six habits: spending cap, keys out of the code, database locked, admin pages behind a login, a scan before launch, and eyes on the logs.
Do those six and you’re ahead of most people shipping AI-built apps today. The bots can keep knocking. Meanwhile, if you want the fuller picture on locking down AI tools in general, our guide to AI agent security goes deeper. And if you haven’t picked a build platform yet, the Lovable review covers what it’s like to ship an app entirely from prompts.