Security Vulnerability Patterns in AI-Generated Code: A Cross-Model Comparative Study
Summary
A cross-model comparative study revealed that LLM-generated automation code for non-expert users consistently contains exploitable security vulnerabilities. Researchers used ChatGPT, Microsoft Copilot, and Google Gemini to generate nine Python automation scripts across three domains: web scraping, email automation, and file/workflow automation. Claude Code performed a standardized vulnerability review, identifying 45 findings, which deduplicated to 17 distinct vulnerability classes. Every script contained exploitable weaknesses. Nine of these 17 vulnerability classes appeared in code from all three models, and 14 appeared in at least two. Weighted CVSS v3.1 scores across platforms differed by less than 10%, indicating the risk is tied to the task category rather than a specific LLM. The study mapped vulnerabilities to OWASP Top 10:2021 and MITRE ATT&CK, highlighting critical risks like SSRF, path traversal, and template injection, which account for 80% of the total weighted exposure.
Key takeaway
For IT Professionals or Directors of AI/ML deploying LLM-generated automation scripts, recognize that these tools consistently introduce exploitable vulnerabilities, regardless of the specific model. Your organization should implement mandatory security reviews for all LLM-generated code entering enterprise workflows. Do not trust functional correctness as an indicator of security. Focus remediation efforts on high-impact vulnerabilities like SSRF and path traversal, and consider security-aware prompting as an initial mitigation.
Key insights
LLM-generated automation code inherently contains exploitable vulnerabilities, consistently across models and tasks.
Principles
- LLM-generated code risk is task-category dependent, not model-dependent.
- Functional correctness does not imply secure code execution.
- Vulnerability classes converge across different LLM code generations.
Method
The study generated Python automation scripts from three LLMs using identical prompts, then reviewed them with Claude Code. Identified vulnerabilities were scored using CVSS v3.1 and mapped to OWASP Top 10:2021 and MITRE ATT&CK.
In practice
- Prioritize remediation for high-risk vulnerabilities like SSRF and path traversal.
- Implement security-aware prompt templates for LLM code generation.
- Use LLM-based tools for initial vulnerability analysis, but not as a sole review.
Topics
- LLM Security
- AI-Generated Code
- Vulnerability Analysis
- OWASP Top 10
- MITRE ATT&CK
- CVSS Scoring
- Automation Scripts
Best for: CTO, VP of Engineering/Data, Executive, AI Security Engineer, Director of AI/ML, IT Professional
Related on AIssential
See Counsel's argued verdicts on the open AI decisions leaders are weighing →
Editorial summary, takeaway, and curation by AIssential. Original article published by cs.SE updates on arXiv.org.