arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2403.15600cs.SEcs.AIcs.CR
收藏

只是又一次复制粘贴吗?比较 ChatGPT 生成代码与 StackOverflow 回答的安全漏洞

Just another copy and paste? Comparing the security vulnerabilities of ChatGPT generated code and StackOverflow answers

Department of Computer Science, North Carolina State University, Raleigh, North Carolina(计算机科学系,北卡罗来纳州立大学,拉法叶,北卡罗来纳州)

Sivana Hamer, Marcelo d'Amorim, Laurie Williams

AI总结:

本研究使用 CodeQL 对 ChatGPT 与 StackOverflow 各 108 个 Java 代码片段进行 CWE 漏洞实证比较,发现 ChatGPT 漏洞显著更少,但两类来源均不应被盲目信任。

摘要:

Sonatype 2023 年报告发现,97% 的开发者和安全负责人将生成式人工智能(AI),尤其是大语言模型(LLM),集成到其开发流程中。人们已对这一趋势的安全影响提出担忧。开发者如今正在权衡 LLM 相对于 StackOverflow(SO)等其他受依赖信息来源的收益与风险,因此需要经验数据来为其选择提供依据。在本研究中,我们的目标是通过实证比较 ChatGPT 与 StackOverflow 的漏洞,提高软件开发者在选择代码片段时对安全影响的认识。为此,我们使用了一个来自 SO、包含安全相关问答的现有 Java 数据集。随后,我们向 ChatGPT 提出相同的 SO 问题,并收集生成的代码用于比较。整理数据集后,我们使用 CodeQL 分析了来自每个平台的 108 个代码片段中 Common Weakness Enumeration(CWE,通用弱点枚举)漏洞的数量和类型。ChatGPT 生成的代码包含 248 个漏洞,而 SO 片段中发现 302 个漏洞;前者漏洞少 20%,且差异具有统计显著性。此外,ChatGPT 生成了 19 种 CWE 类型,少于 SO 中发现的 22 种。我们的发现表明,开发者对两个平台上不安全代码传播的认识不足,因为我们共发现 274 个唯一漏洞和 25 种 CWE 类型。任何被复制粘贴的代码,无论由 AI 还是人类创建,都不能被盲目信任,需要采用良好的软件工程实践来降低风险。未来工作可帮助最大限度减少来自任何平台的不安全代码传播。

英文摘要:

Sonatype's 2023 report found that 97% of developers and security leads integrate generative Artificial Intelligence (AI), particularly Large Language Models (LLMs), into their development process. Concerns about the security implications of this trend have been raised. Developers are now weighing the benefits and risks of LLMs against other relied-upon information sources, such as StackOverflow (SO), requiring empirical data to inform their choice. In this work, our goal is to raise software developers awareness of the security implications when selecting code snippets by empirically comparing the vulnerabilities of ChatGPT and StackOverflow. To achieve this, we used an existing Java dataset from SO with security-related questions and answers. Then, we asked ChatGPT the same SO questions, gathering the generated code for comparison. After curating the dataset, we analyzed the number and types of Common Weakness Enumeration (CWE) vulnerabilities of 108 snippets from each platform using CodeQL. ChatGPT-generated code contained 248 vulnerabilities compared to the 302 vulnerabilities found in SO snippets, producing 20% fewer vulnerabilities with a statistically significant difference. Additionally, ChatGPT generated 19 types of CWE, fewer than the 22 found in SO. Our findings suggest developers are under-educated on insecure code propagation from both platforms, as we found 274 unique vulnerabilities and 25 types of CWE. Any code copied and pasted, created by AI or humans, cannot be trusted blindly, requiring good software engineering practices to reduce risk. Future work can help minimize insecure code propagation from any platform.

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

↑