Vibe coding with APIs: security risks and best practices before you ship
01Introduction
Vibe coding means building software by describing what you want to an AI coding assistant, such as Claude, Claude Code, Cursor, Lovable, Bolt, Replit or GitHub Copilot, and shipping what it writes. It gets a prototype live in an afternoon. It also ships security gaps at the same speed, because the AI writes code that works long before it writes code that is safe.
This guide covers the most common vibe coding security risks and seven best practices to fix them before your users find them for you.
02What goes wrong
In February 2026, Wiz researchers found that Moltbook, a social network for AI agents, had exposed 1.5 million API tokens, 30,000 email addresses and thousands of private messages (Infosecurity Magazine, February 3, 2026). The app was vibe coded. A database key sat in the browser code, and the database had no access rules, so anyone with the key could read everything.
That pattern is common. A Cloud Security Alliance research note (March 31, 2026) pulled together the numbers:
- AI-generated code introduced a security vulnerability in 45% of tasks tested (Veracode).
- AI-assisted commits leaked secrets at 3.2%, more than double the 1.5% baseline (GitGuardian).
- CVEs formally attributed to AI-generated code rose from 6 in January 2026 to 35 in March.
03Seven vibe coding best practices
1. Keep API keys out of the browser
Any key in frontend code is public. Call third-party APIs from your server, store keys in environment variables, and rotate any key that has ever touched a commit.
2. Turn on database access rules before launch
Moltbook's leak came down to one missing setting. If you use Supabase or Firebase, enable row-level security or security rules on every table, then test it by querying as a logged-out user.
3. Read what the AI wrote
Nothing ships unread. Ask the AI for a security review of its own code, then check the parts that handle login, payments and user data yourself.
4. Don't let the AI invent your security checks
Ask Claude or Cursor for a fraud check or an email filter and it will write one from scratch. It will also get the edge cases wrong. Use a tested API for the jobs where mistakes cost you.
The Disposable Email Checker API blocks throwaway signups. The IP Address Lookup API flags VPNs, proxies and Tor, and returns a risk score with a recommendation:
{
"IP": {
"is_vpn": false,
"is_tor": false,
"risk_level": "low",
"recommendation": "accept"
}
}5. Build with fake data
Never paste real customer data into a prompt or a test database. The Generate Fake Person Info API returns up to 50 realistic test profiles per call, with names, emails, addresses and birth dates that belong to nobody.
6. Check every package the AI adds
AI tools install dependencies without asking twice, and package registries are a favorite target for attackers. Review new packages before they ship. OpenClaw skills and AI agent security shows how this plays out with AI agents.
7. Add the basics the AI skips
The same CSA note found that every production app in one study lacked CSRF protection and security headers. Add both. Most frameworks need a few lines.
04Build with ready-made endpoints through ApyHub MCP
Every time your assistant writes an integration from scratch, it spends tokens and produces a slightly different version. Run the same prompt twice and you get two implementations to review.
ApyHub MCP changes what your assistant does. Connect it to Claude, Claude Code, Cursor or any MCP-ready assistant, and the assistant calls ready-made endpoints from the ApyHub catalog instead of generating the logic itself. It searches the catalog, reads each endpoint's schema and calls it, with no wrapper or tool definition to write.
- 75% fewer tokens on the same task, because the assistant calls an endpoint instead of writing and debugging code.
- 100% consistent results. The same endpoint returns the same output shape every time.
- Under 5 minutes to set up.
- One subscription for the whole catalog, priced in atoms, a per-call unit that reflects the compute work behind each request. Your assistant sees the cost before it calls.
On security, ApyHub hosts everything in dedicated EU and US regions. Call the EU endpoints and your users' data is processed in the EU, which keeps you on the right side of GDPR. Each service also carries machine-readable information on how it handles data, and ApyHub matches every service against your organization's policy. You know where your users' data goes before your assistant sends it.
05Conclusion
Vibe coding is a fast way to build. The risks are predictable: exposed keys, open databases, unreviewed code and AI-written security logic. Fix those seven things before launch, and give your assistant ready-made endpoints through ApyHub MCP for everything it doesn't need to invent. You keep the speed and spend fewer tokens on code you would have to review anyway.
06FAQ
Is vibe coding safe for production apps? It can be, if you review the code and fix the common gaps first. Exposed keys, missing database rules and missing security headers cause most incidents.
What are the biggest vibe coding security risks? API keys in frontend code, databases without access rules, hardcoded secrets in commits, and vulnerable dependencies added by the AI.
How do I keep API keys safe when vibe coding? Call APIs from your server, keep keys in environment variables, and tell the AI explicitly never to put keys in client code.
Should I let AI write my fraud or validation logic? Use a tested API for checks where mistakes are costly, such as disposable email detection or IP risk scoring. Let the AI wire it in.
Where does ApyHub process my users' data? In dedicated EU and US regions. Use the EU region and data is processed in the EU, which supports GDPR compliance.
How can I test an API before adding it to my app? Use the playground on the API's ApyHub page, Voiden (an open-source API client that keeps requests as Markdown in your repo), or curl.
Can Claude or Cursor call ApyHub APIs directly? Yes. Connect ApyHub MCP and any MCP-ready assistant, including Claude, Claude Code and Cursor, can search the catalog and call endpoints without custom wrappers.
Why use MCP endpoints instead of letting the AI write the code? The assistant uses 75% fewer tokens on the same task and gets the same output shape every time. You review one integration instead of new generated code on every run.
07About ApyHub
ApyHub is a curated API catalog for developers and AI agents. Instead of signing up with a new vendor for every capability, you get over 1,500 endpoints and capabilities, with more added continuously, under one subscription and one API key. Pricing is in atoms, a per-call unit that reflects the actual compute work, so you see the cost before you call. Every endpoint is ready for AI agents through ApyHub MCP, with no wrappers or tool definitions to write. Every service carries machine-readable certification aligned with GDPR, SOC 2 and ISO 27001 and runs in dedicated EU and US regions, so you know where your data goes. More than 65,000 developer workspaces use ApyHub every month. Start free, no credit card needed. Built an API of your own? Publish it to the catalog through the provider program.
