AI threat catalogue Reliability and Responsible Use Development
Insecure AI-Generated Code and Hallucinated Software Dependencies
Code produced by AI assistants or coding agents contains vulnerabilities, hard-coded credentials or risky changes and is adopted without adequate review. Attackers can register invented package names and fill them with malicious code.
Description
Coding assistants reproduce insecure patterns from their training data, such as missing input validation, and write credentials straight into the code. As generation speeds up, review depth drops: large changes are waved through because they look plausible (automation bias, excessive trust in automated suggestions). Agents with write access sometimes apply changes and commands directly in production. A special case is slopsquatting: models recommend software packages that do not exist and repeat the same invented names. Attackers register these names in public package registries; once someone installs the package, the malicious code runs.
Possible impact
Vulnerabilities and credentials reach production unnoticed and widen the attack surface across many applications. The consequences are data leakage, operational disruption, costly rework and liability towards customers. If an agent deletes or alters production data, data loss and downtime follow. Hallucinated dependencies give malicious code a direct path into the company's own supply chain.
Example
A small team builds a customer application largely with a coding agent and reviews the changes only by spot checks. The generated code contains a database query without input validation and an API key in plain text that is published with the repository. The agent also installs a suggested helper package whose name an attacker registered shortly before.
- Main lifecycle phase
- Development and training
- Arises in
- Development and training
- Takes effect in
- Operation and monitoring
Recommended mitigations (7)
Compare effects and implementation levels. Expand each entry for the additional classification and rationale.
-
Mandatory review plus static code analysis (SAST) and secret scanning before every merge, including AI-generated changes
Technical- Effect
- Preventive, Detective
- Implementation level
- Supply chain, Application, API & agents
Classification and rationale
Complementary control typeOrganizational & process-based
Primarily technical: System-enforced inspection, transformation, or blocking rules stop or neutralize disallowed content before further processing; complemented by binding workflows.
Meaning, implementation and evidence
- What it means
- Every change, whether written by humans or AI, goes through human review plus automated static code analysis and secret scanning as mandatory checks before merging.
- Effect on the threat
- Vulnerabilities and hardcoded credentials in AI-generated code are caught before they reach the main branch unchecked.
- When it helps
- Useful where code, configurations or package dependencies are generated or suggested by AI assistants or coding agents and adopted into in-house software.
- Suggested implementation
- Enable branch protection with mandatory review.
- Add SAST and secret scanning as blocking pipeline checks.
- Allow exceptions only with a documented justification.
- Useful evidence examples
- Branch protection rules, pipeline configuration, scan reports or review records.
-
New dependencies only from an internal package mirror or allowlist; checked for existence, age and publisher
Technical- Effect
- Preventive
- Implementation level
- Supply chain, Infrastructure
Classification and rationale
Complementary control typeOrganizational & process-based
Primarily technical: Machine-enforced identity, permission, or scope rules constrain unauthorized access and actions; complemented by binding workflows.
Meaning, implementation and evidence
- What it means
- New packages are obtained only via an internal package mirror or allowlist; before adoption, checks confirm the package actually exists and assess its age and publisher.
- Effect on the threat
- Package names invented by AI and registered by attackers with malicious code do not enter builds, because unknown or new packages are not installed automatically.
- When it helps
- Useful where code, configurations or package dependencies are generated or suggested by AI assistants or coding agents and adopted into in-house software.
- Suggested implementation
- Route package retrieval through an internal mirror or allowlist.
- Define criteria for existence, age, publisher and adoption.
- Block direct installation from public registries in builds.
- Useful evidence examples
- Package mirror configuration, allowlist, review record of new dependencies or SBOM.
-
Coding agents without access to production environments and production data by default
Technical- Effect
- Preventive, Impact-limiting
- Implementation level
- Infrastructure, Application, API & agents
Classification and rationale
Complementary control typeGovernance & compliance
Primarily technical: Architectural and runtime boundaries separate data, execution, or tenants and limit the spread of failures; complemented by rules and oversight.
Meaning, implementation and evidence
- What it means
- By default, coding agents work only in development and test environments with test data; access to production systems and data is possible only by exception with approval and time limits.
- Effect on the threat
- Faulty or risky agent code cannot modify production systems or delete production data before it has been reviewed.
- When it helps
- Useful where code, configurations or package dependencies are generated or suggested by AI assistants or coding agents and adopted into in-house software.
- Suggested implementation
- Remove production credentials from agent environments.
- Block network access from agent environments to production systems.
- Define an exception process with approval and expiry.
- Useful evidence examples
- Network and permission configuration, exception log or test evidence of blocked access.
-
Developer training on typical flaws in AI-generated code and on automation bias
People & competence- Effect
- Preventive
- Implementation level
- Organization
Classification and rationale
Complementary control typeOrganizational & process-based
Primarily a people-and-competence control: Human knowledge, attention, or professional judgment produces the protective decision; complemented by binding workflows.
Meaning, implementation and evidence
- What it means
- Developers are trained on typical weaknesses of AI-generated code, such as insecure default patterns, invented libraries and outdated APIs, and on the tendency to trust plausible-looking suggestions without checking.
- Effect on the threat
- Developers who know common flaw patterns and their own automation bias are less likely to accept insecure code and unknown packages without critical review.
- When it helps
- Useful where code, configurations or package dependencies are generated or suggested by AI assistants or coding agents and adopted into in-house software.
- Suggested implementation
- Create training content with realistic examples of insecure AI code.
- Make the training mandatory for all developers.
- Update content regularly with findings from reviews.
- Useful evidence examples
- Training materials, attendance records, test results or update history.
-
Labelling of AI-generated changes in version control for targeted follow-up review
Organizational & process-based- Effect
- Detective
- Implementation level
- Supply chain, Organization
Classification and rationale
Complementary control typeTechnical
Primarily organizational and process-based: Defined selection, operating, or lifecycle procedures make the control binding and repeatable; complemented by technical implementation.
Meaning, implementation and evidence
- What it means
- Changes produced wholly or mainly by AI assistants or coding agents are labelled consistently in version control, for example via commit trailers or labels.
- Effect on the threat
- AI-generated changes can be reviewed specifically and found quickly when new flaw patterns become known.
- When it helps
- Useful where code, configurations or package dependencies are generated or suggested by AI assistants or coding agents and adopted into in-house software.
- Suggested implementation
- Define a consistent label for AI-generated changes.
- Apply the label automatically in agent workflows.
- Query labelled changes regularly for spot checks and analysis.
- Useful evidence examples
- Labelling rule, example of labelled commits, analysis or spot check record.
-
Regular security testing of the running application (dynamic testing, penetration tests)
Organizational & process-based- Effect
- Detective
- Implementation level
- Application, API & agents, Use & operations
Classification and rationale
Complementary control typeTechnical
Primarily organizational and process-based: A planned, repeatable assessment with ownership and documented follow-up creates the protective effect; complemented by technical implementation.
Meaning, implementation and evidence
- What it means
- The running application is tested regularly and after major changes with dynamic security tests and penetration tests to find vulnerabilities in its actual behaviour.
- Effect on the threat
- Vulnerabilities from AI-generated code that review and static analysis missed are uncovered in operation before attackers exploit them.
- When it helps
- Useful where code, configurations or package dependencies are generated or suggested by AI assistants or coding agents and adopted into in-house software.
- Suggested implementation
- Define scope, frequency and triggers for dynamic testing.
- Plan and conduct penetration tests for critical applications.
- Prioritise findings and track remediation.
- Useful evidence examples
- Test plan, test reports, findings list or evidence of remediated vulnerabilities.
-
Tested backups and rollback for code and data that agents may modify
Technical- Effect
- Impact-limiting, Restorative
- Implementation level
- Infrastructure, Data, Application, API & agents
Classification and rationale
Complementary control typeOrganizational & process-based
Primarily technical: Versioned states or rollback mechanisms enable controlled recovery; complemented by binding workflows.
Meaning, implementation and evidence
- What it means
- Code, configurations and data that agents are allowed to modify are backed up regularly; restoration and rollback to an earlier state are documented and tested.
- Effect on the threat
- If an agent causes damage through faulty code or commands, such as deleted data or broken deployments, the previous state can be restored quickly.
- When it helps
- Useful where code, configurations or package dependencies are generated or suggested by AI assistants or coding agents and adopted into in-house software.
- Suggested implementation
- Identify code and data assets that agents can modify.
- Set up backups and rollback procedures for these assets.
- Test restoration regularly and record its duration.
- Useful evidence examples
- Backup concept, restore test report, rollback log or list of protected assets.
Framework mappings
Verified locations in OWASP, NIST AI RMF, MITRE ATLAS, the EU AI Act and further frameworks. The mappings are taxonomic, not evidence of compliance.
Verified references (13)
Every reference states the framework, the exact location and the publishing organisation.
- OWASP Top 10 LLM04:2026 Supply ChainLLM04:2026 Supply Chain, OWASP Top 10 for LLM Applications 2026 v1.0, pp. 27-32 (doi:10.5281/zenodo.22109015); canonical text 2026/final/LLM04_SupplyChain.md at commit 7e144e05OWASP FoundationOriginal
- OWASP Top 10 LLM07:2026 MisinformationLLM07:2026 Misinformation, OWASP Top 10 for LLM Applications 2026 v1.0, pp. 43-45 (doi:10.5281/zenodo.22109015); canonical text 2026/final/LLM07_Misinformation.md at commit 7e144e05OWASP FoundationOriginal
- NIST AI RMF Section 2.2 ConfabulationSection 2.2, p. 6National Institute of Standards and Technology (NIST)Original
- NIST AI RMF Section 2.9 Information SecuritySection 2.9, pp. 10–11National Institute of Standards and Technology (NIST)Original
- EU AI Act Article 4(1) AI literacyArticle 4 as replaced by Article 1, point (5), of Regulation (EU) 2026/1744European Union (EUR-Lex)Original
- BSI R15 Platzierung von Malware (Text)Ch. 4, R15, p. 22Bundesamt für Sicherheit in der Informationstechnik (BSI)Original
- BSI R6 Fehlende Sicherheit von generiertem Code und codeähnlichen Texten (Text)Ch. 4, R6, p. 16Bundesamt für Sicherheit in der Informationstechnik (BSI)Original
- BSI R8 Automation Bias (Text, Bild, Video)Ch. 4, R8, p. 17Bundesamt für Sicherheit in der Informationstechnik (BSI)Original
- CoSAI Insecure Model Output Insecure Model OutputRisk Map, risk entryCoalition for Secure AI (CoSAI, OASIS Open Project)Original
- OWASP AI Exchange 4.4 Output contains conventional injection4_runtime_application_security_threats.md, section 4.4 Output contains conventional injectionOWASP Foundation (OWASP AI Exchange)Original
- MIT AI Risk Repository 2.2 AI system security vulnerabilities and attacksDomain Taxonomy, subdomain 2.2MIT FutureTech (MIT AI Risk Initiative)Original
- MIT AI Risk Repository 3.1 False or misleading informationDomain Taxonomy, subdomain 3.1MIT FutureTech (MIT AI Risk Initiative)Original
- ETSI EN 304 223 5.2.3 (Principle 7) Secure the supply chainClause 5.2.3, p. 13European Telecommunications Standards Institute (ETSI), TC SAIOriginal
Related threats (6)
How the catalogue relates this threat to others, with the reason.
-
Enables
Classic Security Flaws in the Application around the AI Model
AI code adopted without review brings vulnerabilities and secrets into the application.
-
Enabled by
Fabricated or Factually Wrong Statements in AI Outputs (Hallucinations)
Hallucinated package names are registered by attackers and filled with malicious code.
-
Enables
Compromised Infrastructure and Software Dependencies in the Supply Chain
Adopted invented dependencies pull malicious packages into one's own supply chain.
-
Enabled by
Overreliance
Automation bias leads to AI code being merged without adequate review.
-
Shares mitigations with
Attacks on AI Frameworks, Middleware and Model Gateways
Version pinning, SBOM and allowlists for packages work against both.
-
See also
Compromise of AI Coding Agents and Developer Tools
Both concern coding agents, once as attack target and once as source of insecure code.
EU AI Act obligations related to this threat
The obligations from the obligations compass whose articles the catalogue maps to this threat. Each leads to its entry with core, action step and evidence; whether it applies to you depends on role and risk class.
-
Support the AI literacy of your staff
Art. 4, applies from 2 February 2025, amended by Reg. 2026/1744
Statutory roles: Provider, Deployer, Product manufacturer, Provider of a general-purpose AI model. Classes: Prohibited practice, High-risk under Annex III, High-risk as a product or safety component, System subject to transparency obligations, General-purpose AI model, Model with systemic risk, Minimal risk.
Regulation (EU) 2026/1744 recast Art. 4. The duty to ensure AI literacy has become a duty to support its development. It is now expressly clarified that no one has to guarantee a particular level of competence for any individual. The obligation as such remains and has applied since 2 February 2025. The wording attaches to AI systems; a provider of a general-purpose AI model alone is covered in so far as they also provide or deploy systems.
This reference is a review prompt. A threat match alone does not establish applicability.
All 62 obligations by role, risk class and deadline in the obligations compass
Terms on this page
Glossary terms that occur in this entry. Every link leads to the full explanation.
- Slopsquatting (hallucinated package names) Attackers register package names that AI assistants invent.
- Coding agent AI agent that reads, writes and runs code in the development environment and build pipeline.
Matching use cases
This list shows where to review this threat, rather than how high the risk is.
Particularly important for:
- Coding assistantThe assistant suggests a nonexistent library, and attackers have published a malicious package under that exact name. Accepting the suggestion introduces malicious code into the organisation's software.
Typical for:
For 3 further use cases, relevance depends on the system design, for example whether it generates code or queries. Show these use cases
Frequently asked questions
- What is Insecure AI-Generated Code and Hallucinated Software Dependencies?
- Code produced by AI assistants or coding agents contains vulnerabilities, hard-coded credentials or risky changes and is adopted without adequate review. Attackers can register invented package names and fill them with malicious code.
- Which mitigations help against Insecure AI-Generated Code and Hallucinated Software Dependencies?
- The catalogue lists 7 mitigations, each with control type, effect and implementation level. First among them are “Mandatory review plus static code analysis (SAST) and secret scanning before every merge, including AI-generated changes”; “New dependencies only from an internal package mirror or allowlist; checked for existence, age and publisher”; and “Coding agents without access to production environments and production data by default”.
- Which EU AI Act obligations does Insecure AI-Generated Code and Hallucinated Software Dependencies touch?
- The catalogue maps this threat to Art. 4(1) of the EU AI Act. In the obligations compass this leads to: Support the AI literacy of your staff. Whether an obligation applies depends on role, risk class and deadline.
Assess this threat in your own system
The live demo contains all 79 threats of this catalogue, including the EU AI Act and GDPR assessment. The free single modules cover AI risk, the EU AI Act and GDPR. No sign-up; the assessment runs locally in your browser.
Cite this entry
For reports, policies or internal documents; the link leads directly to this entry.
“Insecure AI-Generated Code and Hallucinated Software Dependencies”. Versatile AI Risk Assessment, AI threat catalogue, as of November 2026. https://www.versatile-ai-risk-assessment.com/en/wissensbasis/threats/insecure-ai-generated-code/