Versatile AI Risk Assessment

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.

As of: November 2026 Catalogue version 2026.11.15.2 7 mitigations 13 verified references

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
    1. Enable branch protection with mandatory review.
    2. Add SAST and secret scanning as blocking pipeline checks.
    3. 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
    1. Route package retrieval through an internal mirror or allowlist.
    2. Define criteria for existence, age, publisher and adoption.
    3. 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
    1. Remove production credentials from agent environments.
    2. Block network access from agent environments to production systems.
    3. 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
    1. Create training content with realistic examples of insecure AI code.
    2. Make the training mandatory for all developers.
    3. 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
    1. Define a consistent label for AI-generated changes.
    2. Apply the label automatically in agent workflows.
    3. 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
    1. Define scope, frequency and triggers for dynamic testing.
    2. Plan and conduct penetration tests for critical applications.
    3. 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
    1. Identify code and data assets that agents can modify.
    2. Set up backups and rollback procedures for these assets.
    3. 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.

How the catalogue relates this threat to others, with the reason.

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.

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/

← Back to the full catalogue