Get the free coreGet core

Vibe coding security: how to ship an app without leaking keys or data

Updated 6 min readSection 03 / Is it safe?
SHORT ANSWER

Vibe coding security comes down to four places where apps break: keys, database access, packages and the reach of the agent on your Mac. Keep secret keys out of source code, restrict the API keys you must expose, check the access rules on your database, and read what the agent installs. If a key leaks, treat it as compromised. The checklist page turns these habits into numbered actions.

01Where vibe-coded apps leak

Vibe coding means building software by describing it to an AI agent and accepting what it writes, often without reading every line. That speed is the risk: nobody reviews the places that matter. The table maps each place to a real case and one fix. A CVE is a public ID number for a known vulnerability.

WhereEvidenceThe fix
Keys in the repoGitGuardian's 2025 report counted 23,770,171 new secrets in public GitHub commits in 2024Keep secrets in .env, and .env out of git
Database accessCVE-2025-48757: weak row-level security, meaning rules about which rows each user may read, let anyone without a login read or write tables of sites generated in LovableCheck access rules for every table
PackagesMalicious versions of popular npm packages, npm being JavaScript's package registry, ran a script right after install that harvested dataRead what the agent installs
Agent reachA founder claimed a Replit agent deleted a database despite instructions not to change codeKeep a Git history you can return to

02Secrets: the first thing to protect

An API key is an account credential, like a username and password. If a secret key is obtained, unauthorized charges and data access are possible. Stripe's rule is to never put secret keys in source code, because bad actors scan public repos. GitGuardian's 2025 report found that 70% of the secrets leaked in 2022 were still valid. In plain terms, a key leaked in 2022 still worked three years later.

What to do:

If a key already leaked, consider it compromised immediately, because deleting it from the code does not stop exploitation. Replace it, check logs for use, and rotate secrets regularly.

03Database access: the leak that is not in your code

Row-level security means rules that decide which rows each logged-in user may read or change. If they are missing or wrong, anyone can read the table. NVD's entry for CVE-2025-48757 describes insufficient row-level security in Lovable, through 2025-04-15, that let remote attackers without a login read or write arbitrary tables of generated sites. The supplier disputes that record, saying each customer is responsible for protecting their app's data. Lovable's docs put it plainly: misconfigured row-level security rules are a common cause of data leaks.

What to do: test your app while logged out and as a second user, and confirm you cannot see rows that are not yours.

04What the agent can do on your Mac

Your agent is a program with your user's access. In Claude Code's sandbox, a restricted area for shell commands, environment variables are inherited, secrets included. In auto mode, reading .env and sending credentials to a matching API is allowed by default. One npm attack even prompted installed AI tools to run with dangerous flags such as --dangerously-skip-permissions; the story is in the flag article.

Two habits help:

  1. Deny the agent access to secret files. A rule such as Read(./.env) matches reading the .env file.
  2. Add a hook, a script Claude Code runs before a tool call and that can block it. Anthropic's example script blocks edits to .env, package-lock.json and .git/.

Also keep host secrets like ~/.ssh out of any container you mount. The full setup is in how to run Claude Code safely. For the tool's own record, see Claude Code security.

05Undo: what saves you when the agent deletes

Some mistakes are not leaks but losses. Files changed only by Bash commands are not tracked by Claude Code's checkpoints, so use Git. Git's reflog is a local log of where your branches and other references pointed over time, which helps you find the commit you were on before. Be careful with git reset --hard: it overwrites files with the commit's version and may overwrite untracked files.

06Packages: what the agent installs for you

An agent picks libraries so you do not have to. Socket points out that vibe coders may never manually type or search for a package name. Slopsquatting is registering a non-existent package name that a model hallucinated, hoping someone installs it without noticing it is fake. Measured numbers are in AI-generated code vulnerabilities.

Real packages go bad too, as the npm case in the table shows. OWASP, a security project that lists common weaknesses, names traditional third-party package vulnerabilities as a supply-chain risk. Read the names the agent adds before you run an install.

07The code itself

Generated code can contain flaws. Veracode, a company that sells code scanning, tested code from over 100 language models on 80 coding tasks in Java, JavaScript, Python and C#. In its own 2025 report, 45% of the code samples failed security tests, scored with Veracode's static analysis tool. The figure is a vendor's claim about one 2025 test; methods, years and other studies are in AI-generated code vulnerabilities.

Review and test code thoroughly when it is security-sensitive.

08Before you ship

Check four things. Where are my keys, and are any in the repo history? Who can read my database when logged out? What did the agent install? What could the agent delete, and can I get it back from Git?

The vibe coding security checklist puts each of these into one action per line, and AI agent security covers the agent side. Tool pages: Is Claude Code safe?, Is Cursor safe?, Is Codex safe?, Is Copilot safe?, Is Claude safe?.

Vibe coding security covers the app you ship; it does not show what the agent already ran on the Mac you build on. When you ship fast, it helps to see what your agent ran: Artificial Immunity's free, open-source core watches agent sessions and program starts on your Mac and reports what it finds.

FAQ

How safe is vibe coding?

It depends on the checks you add. Apps tend to break in four places: keys, database access, packages and the reach of the agent on your Mac. GitHub's docs say to review and test generated code thoroughly when it is security-sensitive.

How to secure your vibe-coded app?

Start with secrets. Never put secret API keys in source code, because bad actors scan public repos. Then check database access rules, review new packages and keep the agent's reach narrow.

What are the downsides of using vibe coding?

Generated code can carry flaws, models can recommend packages that do not exist and attackers can register those names, and a platform's default setup can leave data open when access rules are misconfigured.

Is safe vibe coding possible?

Yes, with habits rather than a tool. Keep keys out of the repo, restrict API keys, rotate leaked secrets and read what the agent installs.

What do I do if I committed a key by mistake?

Treat it as compromised. GitHub's guidance is that removing it from the codebase does not prevent exploitation. Revoke and replace it, then check logs for use of the secret.

Does a vibe coding platform make my app secure?

Not on its own. Lovable's docs say misconfigured row-level security rules are a common cause of data leaks, and Replit billed itself as the safest place for vibe coding, yet a founder claimed a database deletion on it.

Sources

  1. GitHub docs: remediating a leaked secret
  2. GitGuardian: State of Secrets Sprawl 2025
  3. Stripe: API key best practices
  4. Google Cloud: API keys
  5. NVD CVE-2025-48757
  6. Lovable docs: security
  7. The Register: Replit incident
  8. Wiz: s1ngularity and Shai-Hulud
  9. Socket: slopsquatting
  10. Veracode: GenAI code security
  11. Artificial Immunity
Vibe coding with an agent on your Mac? Artificial Immunity watches the Mac where your agents work.Get the free core