arXivDaily arXiv每日学术速递 周一至周五更新
arXiv周末暂无论文更新,休息一下吧,周末愉快~~
arXiv 2510.26103cs.CR
收藏

AI生成代码中的安全漏洞:对公开GitHub仓库的大规模分析

Security Vulnerabilities in AI-Generated Code: A Large-Scale Analysis of Public GitHub Repositories

FernUniversität in Hagen(哈根 Fern 大学)

Maximilian Schreiber, Pascal Tippe

AI总结:

该研究通过分析GitHub上7703份四大AI工具生成的代码文件,揭示了不同编程语言、不同AI工具生成代码的安全漏洞差异,还发现AI文档生成这一未被充分研究的应用场景,为负责任地集成AI生成代码提供参考。

摘要:

本文对公开GitHub仓库中AI生成代码的安全漏洞开展了全面的实证分析。我们收集并分析了7703个明确归属于四大主流AI工具的文件:ChatGPT(占比91.52%)、GitHub Copilot(7.50%)、Amazon CodeWhisperer(0.52%)以及Tabnine(0.46%)。通过CodeQL静态分析,我们识别出4241个通用缺陷枚举(Common Weakness Enumeration,CWE)实例,涵盖77种不同的漏洞类型。研究结果显示,尽管87.9%的AI生成代码不存在可识别的、映射到CWE的漏洞,但在语言特定漏洞和工具表现方面呈现出显著规律。在所有工具中,Python的漏洞率(16.18%-18.50%)始终高于JavaScript(8.66%-8.99%)和TypeScript(2.50%-7.14%)。我们观察到工具间安全表现存在明显差异:GitHub Copilot在Python(每出现1个CWE对应1739行代码)和TypeScript上的安全密度更优,而ChatGPT在JavaScript上表现更好。此外,我们发现AI工具被广泛用于生成文档(占收集文件的39%),这一应用场景尚未得到充分研究,且对软件可维护性存在影响。这些发现以规模显著更大的数据集拓展了已有研究,为开发面向特定语言、具备上下文感知能力的安全实践提供了宝贵见解,以助力将AI生成代码负责任地融入软件开发工作流。

英文摘要:

This paper presents a comprehensive empirical analysis of security vulnerabilities in AI-generated code across public GitHub repositories. We collected and analyzed 7,703 files explicitly attributed to four major AI tools: ChatGPT (91.52\%), GitHub Copilot (7.50\%), Amazon CodeWhisperer (0.52\%), and Tabnine (0.46\%). Using CodeQL static analysis, we identified 4,241 Common Weakness Enumeration (CWE) instances across 77 distinct vulnerability types. Our findings reveal that while 87.9\% of AI-generated code does not contain identifiable CWE-mapped vulnerabilities, significant patterns emerge regarding language-specific vulnerabilities and tool performance. Python consistently exhibited higher vulnerability rates (16.18\%-18.50\%) compared to JavaScript (8.66\%-8.99\%) and TypeScript (2.50\%-7.14\%) across all tools. We observed notable differences in security performance, with GitHub Copilot achieving better security density for Python (1,739 LOC per CWE) and TypeScript, while ChatGPT performed better for JavaScript. Additionally, we discovered widespread use of AI tools for documentation generation (39\% of collected files), an understudied application with implications for software maintainability. These findings extend previous work with a significantly larger dataset and provide valuable insights for developing language-specific and context-aware security practices for the responsible integration of AI-generated code into software development workflows.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑