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

GitHub 项目中 Copilot 生成代码的安全弱点:一项实证研究

Security Weaknesses of Copilot-Generated Code in GitHub Projects: An Empirical Study

Yujia Fu, Peng Liang, Amjed Tahir, Zengyang Li, Mojtaba Shahin, Jiaxin Yu, Jinfu Chen

AI总结:

本文通过分析 GitHub 项目中 Copilot 等工具生成的 733 个代码片段,实证揭示了生成代码中安全弱点的高发生率及其 CWE 分布,并验证了 Copilot Chat 结合静态分析警告可修复最多 55.5% 的安全问题。

摘要:

现代代码生成工具利用大型语言模型(LLMs)等 AI 模型,因其能够生成功能性代码而日益受到欢迎。然而,它们的使用带来了安全挑战,常常导致不安全的代码被合并到代码库中。因此,评估生成代码的质量,尤其是其安全性,至关重要。尽管先前的研究探索了代码生成的各个方面,但对安全性的关注仍然有限,大多考察的是受控环境中生成的代码,而非开源开发场景。为弥补这一不足,我们开展了一项实证研究,分析了来自 GitHub 项目的 GitHub Copilot 和另外两种 AI 代码生成工具(即 CodeWhisperer 和 Codeium)生成的代码片段。我们的分析识别出 733 个片段,揭示了安全弱点的高发生率,其中 29.5% 的 Python 片段和 24.2% 的 JavaScript 片段受到影响。这些问题涉及 43 个通用弱点枚举(CWE)类别,包括一些重要类别,如 CWE-330:随机值不足的使用、CWE-94:代码生成的不当控制以及 CWE-79:跨站脚本。值得注意的是,其中 8 个 CWE 位列 2023 年 CWE Top-25,凸显了其严重性。我们进一步考察了使用 Copilot Chat 修复 Copilot 生成代码中的安全问题,方法是将静态分析工具的警告信息提供给 Copilot Chat,结果最多 55.5% 的安全问题可以得到修复。最后,我们为缓解生成代码中的安全问题提供了建议。

英文摘要:

Modern code generation tools utilizing AI models like Large Language Models (LLMs) have gained increased popularity due to their ability to produce functional code. However, their usage presents security challenges, often resulting in insecure code merging into the code base. Thus, evaluating the quality of generated code, especially its security, is crucial. While prior research explored various aspects of code generation, the focus on security has been limited, mostly examining code produced in controlled environments rather than open source development scenarios. To address this gap, we conducted an empirical study, analyzing code snippets generated by GitHub Copilot and two other AI code generation tools (i.e., CodeWhisperer and Codeium) from GitHub projects. Our analysis identified 733 snippets, revealing a high likelihood of security weaknesses, with 29.5% of Python and 24.2% of JavaScript snippets affected. These issues span 43 Common Weakness Enumeration (CWE) categories, including significant ones like CWE-330: Use of Insufficiently Random Values, CWE-94: Improper Control of Generation of Code, and CWE-79: Cross-site Scripting. Notably, eight of those CWEs are among the 2023 CWE Top-25, highlighting their severity. We further examined using Copilot Chat to fix security issues in Copilot-generated code by providing Copilot Chat with warning messages from the static analysis tools, and up to 55.5% of the security issues can be fixed. We finally provide the suggestions for mitigating security issues in generated code.

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

↑