← Back to blog
Architecture·9 min read

AI-Generated Code Security: The Vibe Coding Vulnerabilities That Can Cost You

Your AI-built MVP works, but that does not make it secure or compliant. The real risks of vibe coding — phantom dependencies, data leaks, GDPR — and a protocol to fix them.

Let’s be direct: if you built your MVP prompt by prompt, your code very likely carries three systematic problems. First, secrets and credentials exposed in the repository itself. Second, dependencies nobody has verified, including packages the AI made up or that exist but are malicious. Third, personal data handling that does not meet GDPR because nobody stopped to think about it while building. It is the usual pattern when you iterate fast without senior technical review behind you (this is our experience with this kind of project, not a third-party study).

In business terms, that means three concrete scenarios: a security breach at the worst possible moment, a data-protection fine that lands while you are closing a funding round, or a customer losing trust after finding out their data was not where they thought. These are the reasons a product that “works” in a demo falls over once real users arrive, as we covered in why vibe coding never reaches production.

Your app working and your app being secure and compliant are different things. The first is validated by a user clicking around. The second is validated by an audit, a lawyer and, when needed, a pentest. This guide is the map from one to the other.

The Real Risks of AI-Written Code Without Senior Review

The first and most frequent flaw is hardcoded secrets: Stripe API keys, OpenAI tokens, database credentials written straight into the code and pushed to a repository without anyone noticing. The AI generates what works right now, and “works” usually means putting the key wherever is fastest, not wherever is safest. If the repository is public, or accidentally becomes public, automated bots scan for exposed credentials.

The second problem is insufficient input validation. Models write the happy path: the form that receives the expected value and processes it. What they do not write by default is the defence against the unexpected value, the one deliberately crafted. That opens the door to SQL injection, to file uploads that should never be allowed, or to breaking business logic with one poorly validated text field.

The third pattern is excessive permissions on databases and cloud services. It is common to see Firebase rules or S3 policies in “just make it work” mode, with read and write open to everyone, because tightening permissions requires understanding the data model, and prompting rarely invests that time. The result: any authenticated user, sometimes not even that, can read or modify other users’ data.

These are not one-off mistakes by a careless developer. They are the logical outcome of iterating with prompts while nobody with senior technical judgement reviews what lands in the repo. The AI optimises for code that compiles and a screen that shows what you expect, not for code that survives an attack.

Hallucinated Packages: When the AI Installs a Backdoor for You

There is a lesser-known but equally serious risk: hallucinated software packages. When you ask a model to solve something, it often recommends installing a library. Sometimes that library simply does not exist, or exists under a slightly different name. Attackers can register those invented names on npm or PyPI with malicious code inside. The technique is known as slopsquatting, a variant of typosquatting aimed at the hallucinations of language models.

The effect is direct: you, or your developer, run npm install or pip install with the name the AI gave you and unknowingly put a backdoor into your codebase. The package can run at build time or in production, and from there the attacker reaches whatever that process can touch: environment variables, the file system and, sometimes, the cloud infrastructure itself.

The risk is especially high in vibe coding because the workflow encourages blind trust: the prompt suggests, you accept, the code runs. Nobody checks whether the package has real downloads, an active maintainer or a coherent version history. Mitigation is simple:

  • Manually review every new dependency before accepting it.
  • Run a vulnerability and typosquatting scanner in your pipeline.
  • Pin versions in a lockfile instead of installing “the latest” every time.

It takes minutes and prevents a problem that can take weeks to detect.

GDPR for Startups: The Bare Minimum, Not the Full Theory

You do not need to read the whole regulation. For most startups in the validation stage, GDPR comes down to four product and code decisions you either get right early or pay for later. This is technical guidance, not legal advice: for your specific case, validate it with a lawyer.

Legal basis. Before storing a single piece of personal data you need to know why you store it and on what justification. If your sign-up form asks for a phone number “just in case”, that is not a legal basis, it is data capture without a purpose.

Data minimisation. This is where vibe coding tends to do the opposite of what it should: schemas that store everything the form captures without asking whether it will ever be used. Every extra column in your users table is extra risk surface. If your product does not need a date of birth, do not store it. It is an architecture decision that limits the damage in a breach.

Right to erasure. The technical question is concrete: when a user asks you to delete their data, can your system really do it, or is it scattered across logs, backups and third-party services with no process to remove it? Doing it properly means designing cascading deletion and a log retention policy that does not keep personal data longer than necessary.

Security of processing. The encryption, access control and secrets management in the next section are part of what GDPR expects from you.

“We’ll fix it when we grow” is the most expensive sentence in the book: by the time you grow you have thousands of records with a badly designed schema, months of logs holding data that should never have stayed there, and a personal-data migration far costlier than doing it right in the first sprint.

Protecting Sensitive Data in Your App: Encryption, Secrets and Access

Protecting sensitive data is not a giant project: it is a concrete checklist.

  1. Encryption in transit. TLS properly configured on every endpoint, with no exceptions and no forgotten self-signed certificates in production. It is surprisingly common to find internal APIs running unencrypted because “it’s only between our services”.
  2. Encryption at rest. Sensitive data (ID documents, financial information) should not sit in plain text in your database. Passwords get proper hashing, never reversible encryption.
  3. Secrets management. Not in the code, and not in loose environment variables with no control. The right answer is a secrets manager with rotation and audited access, so if a credential leaks you know what an attacker can see and can revoke it without touching the rest of the system.
  4. Least-privilege access control. Every service, role and integration reaches only what it strictly needs.

Doing this properly now is usually a matter of days of senior engineering; patching it later, with active users and data already in production, tends to cost weeks and adds the risk of a breach in the meantime (these are rough estimates: they depend on the product). Designing a secrets manager from the first commit is not the same as migrating credentials live while the app is running. And if you are also at the stage of not knowing what to do next with your AI-built app, this checklist is a solid first priority.

Step-by-Step Protocol to Audit and Secure Before You Launch

Knowing the risks is not enough without an order to tackle them in. The protocol we follow on a product born from vibe coding has five steps, and the order matters:

  1. Dependency audit. Scan the package tree, identify versions with known vulnerabilities, detect typosquatting and hallucinated packages, and pin versions in a lockfile.
  2. Secrets review. Trace the full repository history, not just the current code: an API key deleted three commits ago is still in Git history if nobody rotated it. Everything moves to a secrets manager and any credential that was ever exposed gets revoked.
  3. Permissions and attack surface. Audit database rules, bucket policies, API roles and public endpoints that should not be public. This is where most real problems turn up, because it is usually the most ignored area when you build prompt by prompt.
  4. GDPR checklist for the data the product handles. What is stored, on what legal basis, for how long, and whether real deletion exists when a user asks for it.
  5. Light pentesting or a targeted review. Once the product handles sensitive data or is about to take investment: a review focused on the most critical flows, not a generic hundred-page audit nobody will read.

The initial diagnosis (steps 1 to 3) can be completed in a few days: well-configured scanning tools plus senior eyes on what the tools miss. Full remediation depends on the amount of code and how many data flows the product has; a one-month MVP is not a platform with a year and a half of accumulated prompts. You can see how this fits into a full transformation in from vibe coding to a scalable product.

When to Bring in Senior Help and What to Expect on Cost and Timing

There are three moments when senior technical oversight stops being optional: when you are about to open the product to real users, when you enter a funding process and a technical due diligence will look at exactly what we have described, and when you handle sensitive EU user data and nobody has validated compliance.

This is not about selling fear. In any of those scenarios, the cost of a breach or a fine is far higher than the cost of a well-run review done in time. Our Fractional CTO service is built for this: step in with senior judgement, diagnose without fluff, and give you a fixed budget and timeline before touching a line of code, with no lock-in and no fine print. The goal is to leave your product ready to scale with confidence, not with the hope that nobody looks too closely.

If you want to know where your code stands, request a free technical audit and we will tell you what is at risk and what to prioritise.

by Divolut

Let's talk →