AI-generated code inherits the patterns in its training data, including insecure ones, and it is produced faster than humans can carefully read it.
What the evidence shows
- Insecure choices are common. Veracode's 2025 GenAI Code Security Report tested 80 curated coding tasks across more than 100 LLMs. When a task could be done securely or insecurely, models chose the insecure option 45% of the time. Java had a security failure rate over 70%, and models failed to defend against cross-site scripting in 86% of relevant cases. Larger models did not do significantly better.
- Hallucinated packages. Researchers analysing 576,000 code samples (USENIX Security 2025) found that the average share of hallucinated package names was at least 5.2% for commercial models and 21.7% for open-source models, with 205,474 unique made-up names. Attackers can register those names and wait for someone to install them ("slopsquatting").
- Secrets and data. Assistants can echo secrets from context into code or logs if not controlled.
Controls that work
- Same gates for all code: SAST, dependency (SCA) and secret scanning as required checks on every PR — human or agent.
- Package controls: an internal proxy or registry with allow-lists; block unknown or brand-new packages by default; alert on first-time dependencies.
- Secure prompting defaults: organization-level instructions that require parameterized queries, output encoding, approved crypto and auth libraries.
- Risk-based review: security-sensitive paths (auth, payments, crypto, input handling, infrastructure-as-code) require review by a qualified engineer, whatever wrote the code.
- Secure SDLC alignment: NIST's SP 800-218A adds AI-specific practices to the Secure Software Development Framework.
- Measure: vulnerabilities found per 1,000 changed lines, split by AI-authored vs human where your tools allow.