AI 生成代码中的安全漏洞:来自公开 GitHub 代码库的大规模分析
摘要
本文对 AI 生成代码在公开 GitHub 代码库中的安全漏洞进行全面经验性分析。我们收集并分析了 7,703 个明确归属四大 AI 工具的文件:ChatGPT (91.52%)、GitHub Copilot (7.50%)、Amazon CodeWhisperer (0.52%) 和 Tabnine (0.46%)。使用 CodeQL 静态分析工具,我们识别出 4,241 个通用弱点枚举 (CWE) 实例,涉及 77 种不同的漏洞类型。我们的发现表明,尽管 87.9% 的 AI 生成代码不包含可识别的 CWE 映射漏洞,但仍存在显著的语言特定漏洞模式和工具性能差异。Python 持续表现出更高的漏洞率 (16.18%-18.50%),高于 JavaScript (8.66%-8.99%) 和 TypeScript (2.50%-7.14%)。我们观察到在安全性能方面存在显著差异,GitHub Copilot 在 Python (每个 CWE 1,739 LOC) 和 TypeScript 上实现更好的安全密度,而 ChatGPT 在 JavaScript 上表现更佳。此外,我们发现 AI 工具被广泛用于文档生成 (收集文件的 39%),这一正在被研究不足的应用对软件可维护性具有潜在影响。这些发现基于更大规模的数据集,扩展了前期工作,为为 AI 生成代码在软件开发工作流程中负责任地集成提供了宝贵的见解,尤其是针对特定语言和情境的安全实践。
引用
@article{arxiv.2510.26103,
title = {Security Vulnerabilities in AI-Generated Code: A Large-Scale Analysis of Public GitHub Repositories},
author = {Maximilian Schreiber and Pascal Tippe},
journal= {arXiv preprint arXiv:2510.26103},
year = {2025}
}
备注
This preprint has not undergone peer review or any post-submission improvements or corrections. The Version of Record of this contribution is published in Volume 16219 of the Lecture Notes in Computer Science series, and is available online at https://doi.org/10.1007/978-981-95-3537-8_9