Vibe Coding Security Risks: What Security Teams Need to Know About AI-Generated Code
Vibe coding — the practice of prompting an AI assistant to generate code and shipping it with minimal review — is now mainstream. GitHub Copilot, Cursor, Claude, and Gemini are embedded in developer workflows at scale. The productivity gains are real. The security implications are also real and largely unaddressed. AI code generators reproduce vulnerable patterns from training data, hallucinate package names that malicious actors register, miss context that a human reviewer would catch, and produce code that passes unit tests while containing exploitable logic flaws. The problem is not that AI-generated code is inherently worse than human-written code — it is that it is being shipped at a speed that eliminates the review time that previously caught these issues. This guide covers what security teams need to know to govern AI-assisted development without blocking it.
The Vibe Coding Problem: Speed Without Security Review
The term "vibe coding" was coined by Andrej Karpathy in early 2025 to describe a development mode where developers describe what they want in natural language, accept the AI's output, and iterate based on whether it runs — not on whether it is correct or secure. This is not fringe behavior. A 2025 survey found 78% of developers accept AI suggestions without fully understanding the generated code.
Why this is different from prior tooling:
Volume and velocity: A developer using Copilot might accept 30-50 code completions per hour. Each is a potential attack surface that previously would have been written with conscious intent and reviewed with some attention. At that rate, it is not possible to review each suggestion with the attention a security engineer would give a pull request.
The training data problem: AI coding models are trained on public code repositories. Those repositories contain substantial amounts of insecure code — Stack Overflow answers that are technically correct but not security-hardened, older codebases with known vulnerability patterns, and examples written before current security guidance existed. The model reproduces these patterns probabilistically. It will generate SQL queries with string concatenation because it has seen that pattern many times. It will use deprecated cryptographic primitives because that is what the training data contained.
Context blindness: AI code generators often lack the full context of what the code will do in production. A Copilot suggestion for a file upload handler may be syntactically correct but miss that the application is publicly exposed and needs MIME type validation, size limits, and path traversal prevention. The model generates what it sees, not what the security posture of the application requires.
The OWASP LLM Top 10: OWASP's Top 10 for LLM Applications includes Insecure Output Handling (LLM02) and Sensitive Information Disclosure (LLM06) as specific risks from AI-generated code that executes downstream. The list is a useful framework for categorizing the risk surface.
Hallucinated Dependencies: The Sleeper Threat
AI code generators hallucinate package names — they invent plausible-sounding npm, PyPI, or Maven package names that do not exist. This has become an active attack vector. Threat actors monitor AI forums, GitHub discussions, and security research to identify commonly hallucinated package names, register those packages with malicious payloads, and wait for developers to install them.
How the attack works:
- Developer asks an AI assistant to implement a specific function (e.g., "parse CSV with these specific options")
- AI generates code that imports a package with a plausible name (e.g.,
csv-parse-advancedorreact-secure-form) - The package does not exist — but it has been registered by a threat actor with a malicious payload
- Developer runs
npm installorpip install, installs the malicious package, and either the developer environment is compromised or the malicious code ships to production
Scale of the problem: More than 500 malicious packages were published in 2025 with names matching commonly hallucinated package names from popular AI coding assistants. The attack is particularly effective because the hallucinated package names are specific enough to appear legitimate — they are not typosquatting common packages, they are exact matches for names the AI invented.
Detection and prevention:
# Before installing any AI-suggested package, verify it exists and check:
# 1. Publication date — newly published packages warrant scrutiny
# 2. Download count — hallucinated packages have zero or near-zero downloads
# 3. Repository — legitimate packages link to a real GitHub/GitLab repository
# 4. Maintainer — new accounts with no history are a red flag
# npm: check before installing
npm info <package-name>
# PyPI: check publication date and download stats
pip index versions <package-name>
# Or check pypi.org/project/<package-name> manually
Policy control: Require developers to verify package existence and legitimacy before installing any AI-suggested package. Add this as a step in the pull request template: "Confirm all new dependencies were verified before installation." Lock dependency versions with lockfiles and scan them with SCA tooling (Snyk, Socket, Dependabot) on every commit.
Socket Security is specifically designed to detect malicious packages including those targeting AI hallucination attacks. It monitors package behavior rather than just CVE databases and flags newly published packages with suspicious characteristics.
Briefings like this, every morning before 9am.
Threat intel, active CVEs, and campaign alerts, distilled for practitioners. 50,000+ subscribers. No noise.
Vulnerability Classes AI Models Reliably Generate
Research from multiple academic and industry sources identifies specific vulnerability classes that AI coding assistants generate at higher rates than human-written code. The Pearce et al. IEEE Security & Privacy study found that approximately 40% of Copilot-generated code suggestions for security-relevant tasks contained at least one vulnerability. The most common classes:
SQL injection via string concatenation: AI models frequently generate database queries using string formatting rather than parameterized queries, reproducing the pattern from the large volume of Stack Overflow answers and tutorial code in their training data.
# AI commonly generates (vulnerable):
query = f"SELECT * FROM users WHERE username = '{username}'"
# What it should generate (parameterized):
query = "SELECT * FROM users WHERE username = %s"
cursor.execute(query, (username,))
Path traversal in file operations: File handling code generated by AI frequently fails to sanitize file paths, particularly when the developer prompt focuses on the happy path and does not specify security constraints.
# AI commonly generates (vulnerable):
with open(f"uploads/{filename}", "rb") as f:
return f.read()
# Attacker input: filename = "../../etc/passwd"
Hardcoded credentials and secrets: AI assistants often generate example code with hardcoded API keys, database passwords, or tokens — particularly in configuration files, test scripts, and infrastructure-as-code. They frequently reproduce secrets that appear in their training data (public repositories where secrets were accidentally committed).
Insecure cryptographic choices: AI models trained on older code reproduce deprecated cryptographic primitives: MD5 for password hashing, ECB mode for AES, SHA-1 for integrity verification. The model generates what it has seen the most, not what is current best practice.
Race conditions in concurrent code: AI-generated concurrent code often lacks proper synchronization. The model generates code that is functionally correct in sequential execution but introduces race conditions under load.
Missing authorization checks: AI models generate code that implements the requested functionality but may not implement authorization checks the developer did not explicitly specify. A Copilot suggestion for "fetch user profile" may return any user's profile given their ID, without checking whether the requester has permission to access that profile.
Security Review Practices for AI-Generated Code
The correct response to AI-generated code security risk is not to ban AI assistants — it is to adapt the review process to account for the specific failure modes AI code exhibits.
SAST on every commit (non-negotiable with AI code): Static application security testing must run on every commit when AI assistants are in use. The velocity of AI-generated code makes manual review insufficient as the primary control. Configure your CI/CD pipeline to block merges on high and critical SAST findings:
# GitHub Actions SAST gate example
- name: Run Semgrep
uses: returntocorp/semgrep-action@v1
with:
config: >-
p/security-audit
p/owasp-top-ten
p/sql-injection
generateSarif: "1"
- name: Upload SAST results
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: semgrep.sarif
Dependency scanning with behavioral analysis: Standard SCA tools (Snyk, Dependabot) check CVE databases. For AI-generated code, add behavioral package scanning (Socket Security, Phylum) that detects malicious packages regardless of whether they have a CVE assigned.
Prompt security review: Train developers to include security constraints in their prompts. "Write a file upload handler" will generate less secure code than "Write a secure file upload handler that validates MIME type, enforces a 10MB size limit, prevents path traversal, and stores files outside the web root." The output quality correlates with the specificity of the security requirements in the prompt.
Code review checklist for AI-assisted PRs: Add a specific checklist item to pull request templates when AI assistance was used. Key items:
- All new dependencies verified as legitimate before installation
- No hardcoded secrets or credentials (confirm with
git secretsordetect-secretspre-commit hook) - SQL queries use parameterized statements
- File paths sanitized against traversal
- Authorization checks present for all data access operations
- Cryptographic operations use current recommended algorithms
Semgrep rules targeting AI-common patterns:
Semgrep's community registry includes rules specifically targeting common AI-generated vulnerability patterns. The p/security-audit pack covers most categories. Add custom rules for patterns specific to your stack that Copilot/Cursor tends to generate incorrectly in your codebase.
Governance Controls: Policy Without Blocking Productivity
The governance challenge with AI-assisted development is that blanket bans are unenforceable and counterproductive — developers will use these tools regardless of policy, and bans push usage underground where it receives no security oversight. Effective governance works with the tools, not against them.
Approved tool list with security review: Maintain a list of approved AI coding assistants that have been evaluated for data handling, output security, and privacy implications. GitHub Copilot, Cursor, and JetBrains AI Assistant store prompts and code differently — understand what goes to which vendor before organization-wide deployment. Prohibit use of unapproved AI tools with access to production code or sensitive data.
Data classification and tool boundaries: Define which data classifications can be included in AI prompts. Code handling PII, credentials, cryptographic material, or proprietary algorithms should not be submitted to external AI services. Use local models (Ollama, locally-deployed LLMs) for code touching sensitive data.
Security gates in CI/CD (the enforcement layer): Policy is unenforceable without technical controls. The CI/CD pipeline is where governance becomes real: SAST gates that block vulnerable patterns, SCA gates that block known-malicious dependencies, and secrets scanning that blocks committed credentials. These gates apply to all code regardless of how it was generated.
Developer training on AI security risks: Include AI-specific content in security awareness and secure coding training. Developers need to understand: what types of prompts generate insecure suggestions, how to verify AI-suggested dependencies, and what security review steps are mandatory regardless of code origin. Security champions in development teams are the most effective vector for spreading this knowledge.
Audit logging of AI tool usage: For high-sensitivity development environments, enable audit logging of AI assistant queries. GitHub Copilot Business and Enterprise support audit log exports. This creates a forensic record if AI-assisted code introduces a security incident.
Emerging Risk: MCP Server Supply Chain and AI Agent Code Execution
The AI coding security landscape has expanded beyond static code generation to AI agents that write and execute code autonomously. Model Context Protocol (MCP) servers — which give AI agents access to tools, databases, and external systems — introduce a new supply chain risk surface.
The MCP supply chain problem: MCP servers are typically installed via npm or pip and given significant permissions: access to the filesystem, database connections, API keys, and external network. A malicious or compromised MCP server can exfiltrate secrets, modify code, or pivot into connected systems. The attack surface is similar to a malicious VS Code extension but with broader system access.
Prompt injection in code agents: AI agents that browse the web, read files, or process external data can be manipulated via prompt injection — malicious content in a file or web page that instructs the agent to take a different action than intended. An agent asked to summarize a document that contains hidden prompt injection instructions might exfiltrate credentials or execute unintended commands.
Security controls for agentic AI development tools:
- Review MCP server permissions before installation — principle of least privilege applies
- Prefer MCP servers from established vendors with security track records over community-created servers
- Run AI agents in isolated environments with no access to production credentials or systems
- Implement human-in-the-loop confirmation for any agentic action that involves code execution, file modification, or external API calls
- Monitor AI agent activity logs for anomalous behavior
This is an emerging area with evolving tooling. The OWASP Top 10 for LLM Applications covers the most relevant attack classes including prompt injection (LLM01) and excessive agency (LLM08).
The bottom line
Vibe coding is not going away — the productivity benefits are too significant and developer adoption is too widespread to reverse. The security response is to adapt the review and tooling pipeline, not to fight the adoption. Mandatory SAST gates in CI/CD, behavioral dependency scanning for hallucinated packages, secrets scanning pre-commit, and developer training on AI-specific vulnerability patterns are the minimum viable security controls for an organization where AI-assisted development is in use. The governance model that works is: approved tools, defined data boundaries, mandatory technical gates, and security champions who can coach developers on prompt security. Blocking AI tools without these alternatives leads to shadow usage with no oversight at all.
Frequently asked questions
What is vibe coding?
Vibe coding refers to the practice of using AI coding assistants to generate code based on natural language prompts and accepting the output with minimal review — iterating based on whether the code runs rather than whether it is correct and secure. The term was coined by Andrej Karpathy in 2025. The security concern is not that AI-generated code is inherently bad, but that the speed of AI-assisted development compresses the review time that previously caught security issues before they shipped.
What percentage of AI-generated code contains vulnerabilities?
A 2022 IEEE Security & Privacy study by Pearce et al. found that approximately 40% of GitHub Copilot suggestions for security-relevant coding tasks contained at least one CWE-identified vulnerability. The most common vulnerability classes were SQL injection via string concatenation, path traversal in file operations, insecure cryptographic choices, and missing authorization checks. The percentage varies by task type — security-critical functions (authentication, cryptography, file handling) generate vulnerable suggestions at higher rates than general utility code.
What are hallucinated package names and why are they dangerous?
AI code generators sometimes invent package names that do not exist in npm, PyPI, or other package registries. Threat actors monitor for these hallucinated names and register malicious packages with matching names, waiting for developers to install them via npm install or pip install. A developer who installs an AI-suggested package without verifying it exists and is legitimate risks installing malware directly into their development environment or production codebase. Verify package existence, publication date, download count, and repository link before installing any AI-suggested dependency.
Should I ban AI coding assistants for security reasons?
Blanket bans are generally counterproductive — developers will use these tools regardless of policy, pushing usage underground where it receives no security oversight. The more effective approach is to establish approved tool lists (with security-evaluated options), define data classification boundaries for what can be included in AI prompts, implement mandatory SAST and dependency scanning gates in CI/CD that apply to all code regardless of origin, and train developers on AI-specific vulnerability patterns. Technical controls in the pipeline provide real enforcement; policy alone does not.
What SAST tools work best for AI-generated code?
Semgrep with the security-audit and owasp-top-ten rule packs covers the most common AI-generated vulnerability patterns across multiple languages. CodeQL provides deeper semantic analysis. For dependency scanning, add Socket Security or Phylum alongside Snyk or Dependabot — Socket's behavioral analysis detects malicious packages that may not have CVEs assigned yet, including packages registered to exploit hallucinated package names. Run all of these as CI/CD gates that block merges on high and critical findings.
How do I write better prompts to get more secure AI-generated code?
Include explicit security requirements in the prompt rather than relying on the AI to infer them. Instead of 'write a file upload handler,' specify 'write a secure file upload handler that validates MIME type against an allowlist, enforces a 10MB size limit, prevents path traversal by resolving the path and verifying it is within the uploads directory, and stores files outside the web root.' The more specific the security constraints in the prompt, the less the AI relies on its training data defaults, which tend toward convenience over security. For authentication and cryptography specifically, always name the algorithm you want to use.
Sources & references
- Stanford HAI: Security Implications of AI-Assisted Coding 2025
- GitGuardian: State of AI Code Security 2025
- NIST AI Risk Management Framework 1.0
- OWASP Top 10 for LLM Applications 2025
- GitHub Copilot Security Research — Pearce et al., 2022 (IEEE S&P)
Free resources
Critical CVE Reference Card 2025–2026
25 actively exploited vulnerabilities with CVSS scores, exploit status, and patch availability. Print it, pin it, share it with your SOC team.
Ransomware Incident Response Playbook
Step-by-step 24-hour IR checklist covering detection, containment, eradication, and recovery. Built for SOC teams, IR leads, and CISOs.
Get threat intel before your inbox does.
50,000+ security professionals read Decryption Digest for early warnings on zero-days, ransomware, and nation-state campaigns. Free, weekly, no spam.
Unsubscribe anytime. We never sell your data.

Founder & Cybersecurity Evangelist, Decryption Digest
Cybersecurity professional with expertise in threat intelligence, vulnerability research, and enterprise security. Covers zero-days, ransomware, and nation-state operations for 50,000+ security professionals weekly.
The Mythos Brief is free.
AI that finds 27-year-old zero-days. What it means for your security program.
