Vibe coding is now the default way many teams write software. A developer describes what they want in plain English, an AI tool generates the code, and the result gets committed. The feedback loop is fast, the output looks reasonable, and the security problems are invisible until they are not.

This post covers the three most common security failures in AI-generated code, what the research shows, and what teams can do about each one.


What the Data Shows

The numbers are hard to ignore.

A large-scale scan by Escape.tech of 5,600 publicly deployed AI-generated applications found 2,000 highly critical vulnerabilities, 400 exposed secrets including API keys and access tokens, and 175 instances of exposed personal data including medical records and payment information.

An IEEE-accepted study from 2025 found something counterintuitive: iterative refinement made things worse. After just five rounds of AI-based code improvements, critical vulnerabilities increased by 37.6%. The model optimised for correctness, not safety (arxiv.org/html/2506.11022).

These are not fringe results. They are consistent across research groups, models, and languages.


Problem 1: Insecure Default Libraries and Dependencies

AI models are trained on public code. A large portion of that code uses outdated libraries, deprecated cryptographic functions, and packages with known vulnerabilities. The model has no strong incentive to suggest the secure alternative when the insecure one appears more often in training data.

The pattern is consistent: models pick what looks familiar, not what is secure. In Java, RSA without OAEP padding is common. In Python, models reach for custom password hashing rather than bcrypt or argon2. In authentication flows, some models generate code that checks whether a user is logged in but leave permission validation unenforced for anonymous requests — granting unrestricted access to protected operations.

What to do:

Write a security context block into every project’s AI system prompt or CLAUDE.md / .cursorrules file. Something like: “Always use bcrypt or argon2id for password hashing. Never use MD5 or SHA-1 for passwords. Always use parameterised queries. Always apply OAEP padding for RSA. Flag any use of deprecated cryptography.”

Run a software composition analysis (SCA) tool such as Dependabot, Snyk, or OWASP Dependency-Check on every pull request. Do not rely on the model to choose secure versions.

Review cryptographic choices in every AI-generated PR. Look specifically for: custom hashing, use of ECB mode, missing IV or nonce, hardcoded secrets, and insufficiently random values.

Pattern: an approved libraries list. Your team keeps a short list of the libraries you use for crypto, auth, and validation. The AI prompt says to use only those. Anything outside the list needs a human decision. This is a simple version of the security patterns idea: decide once, reuse everywhere, instead of letting every generated file make its own choice.

Free tools: Semgrep has free rules that flag weak crypto and insecure functions in CI. Dependabot and OWASP Dependency-Check are free for the dependency side.


Problem 2: Hallucinated Packages and Supply Chain Attacks

AI models sometimes invent package names. The model generates an import or pip install statement referencing a package that does not exist. The developer copies it, runs it, and moves on.

This has become an attack vector.

A USENIX-published analysis of 576,000 AI-generated Python and JavaScript samples found that roughly 20% referenced packages that did not exist. For commercial models the rate was lower, around 5%, but the critical finding was this: 43% of hallucinated package names were reproduced consistently across repeated runs of the same prompt (bleepingcomputer.com).

If a hallucination is predictable, it is exploitable. Attackers register the expected package names on npm and PyPI before developers notice. When the developer runs the install command, they pull down malware. This attack has been named slopsquatting.

In April 2026, this became concrete. Bitwarden’s CLI was hijacked in a supply chain attack where the malware specifically searched for credentials belonging to Claude, Cursor, Aider, and Codex CLI. The attack chain started with a compromised package and ended with AI tool credentials being exfiltrated (stateofsurveillance.org).

The problem is hard to catch with standard tooling. A hallucinated package does not appear in any vulnerability database. The scanner has nothing to match against.

What to do:

Verify every package reference before running any install command. Search the registry manually. Check that the maintainer, download count, and publish date make sense.

Lock your dependency files. Use package-lock.json or requirements.txt with pinned versions, and verify hashes where supported. In Python, pip install --require-hashes enforces this.

Add a pre-commit hook or CI step that checks all new dependencies against a known-good allowlist. Raise a review flag on any package added via an AI-generated suggestion.

Run SCA tools continuously, not just at audit time. Set alerts for newly published CVEs against your dependency tree.

Pattern: dependency checks as a pipeline gate. Checking packages is not a one-time audit, it is a step that runs on every build. A bad or invented package gets stopped before deploy, not found after the incident.

Free tools: OSV-Scanner checks your lockfile against the open vulnerability database, one command in CI. Lockfiles with pinned versions and hashes are built into npm and pip already. And the npm v12 changes coming in July add an install-time allowlist on top, prepare for it now.


Problem 3: Missed Business Logic Vulnerabilities

This is the hardest one to catch with automated tools.

AI models generate code that is syntactically correct and functionally plausible. What it frequently misses is the business context. The model does not know that a user should not be able to access another user’s data. It does not know that an order quantity should never be negative. It does not know that a URL preview feature should not be allowed to reach internal infrastructure.

A December 2025 study by security startup Tenzai tested five major AI coding agents — Cursor, Claude Code, Codex, Replit, and Devin — by having each build three identical web applications. When quantity validation was not explicitly specified in the prompt, four out of five agents allowed orders with a negative total. Three allowed products to be created with a negative price. All five introduced an SSRF vulnerability in a link preview feature, allowing requests to be directed at internal services. The agents built exactly what was asked and nothing more (blog.tenzai.com).

The most widely reported real-world example this year was Lovable, a vibe coding platform valued at $6.6 billion. A researcher discovered a Broken Object Level Authorization (BOLA) flaw: the platform verified that a user was logged in but never checked whether they owned the project they were accessing. Every user’s source code, database credentials, and AI chat histories were accessible to any authenticated user for 48 days. BOLA is the first item on the OWASP API Security Top 10. The vulnerability was reported to HackerOne in March 2026, marked as a duplicate without escalation, and left open. It was not patched until the story became public (The Next Web, April 2026).

BOLA and business logic flaws do not show up in static analysis or most scanners. They require a human to understand what the application is supposed to do and test whether the code actually enforces it.

What to do:

Write authorisation requirements explicitly into your AI prompts. For any data access function, include: “Every database query must filter by the authenticated user’s ID. Never return data belonging to other users. Authorisation must be enforced server-side on every request.”

After generation, manually review every API endpoint that reads or modifies user data. Ask: does this check that the requesting user owns the resource, not just that they are logged in?

Run a dedicated business logic review before any release involving user data, payments, or access controls. Automated scanners will not find these.

Add negative test cases to your test suite. Test that a user cannot access another user’s records. Test that quantities cannot be negative. Test that internal URLs cannot be reached through public-facing features.

Pattern: centralised authorization plus input validation at the boundary. Ownership checks live in one policy layer that every endpoint passes through, so the AI cannot forget one. Every request body is checked against a schema before your logic sees it, so a negative quantity or an unexpected field never gets in. These two patterns together would have prevented both the Lovable breach and the Tenzai findings above.

Free tools: Casbin or Open Policy Agent for the authorization layer, both open source. zod for TypeScript and pydantic for Python at the boundary. On Supabase or Postgres, row level security adds the same ownership check at the database itself, so even a broken endpoint cannot leak another user’s rows.


How We Can Help

These problems are consistent and testable. A focused security review of AI-generated code covers the areas that automated tools miss.

Secure prompts and configuration. We review your AI tool configuration, system prompts, and CLAUDE.md or .cursorrules files and produce a hardened baseline that steers the model away from common insecure patterns. This is a one-time change that reduces risk across every future generation.

Dependency and supply chain review. We audit your dependency tree for hallucinated, spoofed, or vulnerable packages. We help you implement SCA tooling and pre-commit checks that catch supply chain risk before it reaches production.

Business logic and authorisation testing. We test the application logic the model generated, not just the syntax. We look for broken authorisation, missing ownership checks, unsafe input handling, and logic gaps that scanners cannot find.

AI code review process design. We help your team build a lightweight review process for AI-generated PRs. This does not mean reviewing every line. It means knowing which patterns to look for and which tools to run.

If you are shipping AI-generated code and have not reviewed the authorisation logic, the dependency choices, or the cryptographic implementation, the problems above are likely already present. They are not edge cases. They appear in the majority of vibe-coded applications examined by researchers.

A short review now is cheaper than an incident later.

Get in touch to book a free discovery call.


References