Just another copy and paste? Comparing the security vulnerabilities of ChatGPT generated code and StackOverflow answers
作者: Sivana Hamer, Marcelo d'Amorim, Laurie Williams
分类: cs.SE, cs.AI, cs.CR
发布日期: 2024-03-22
备注: 8 pages, 2 figures, accepted at Deep Learning Security and Privacy Workshop (DLSP) part of IEEE Symposium on Security and Privacy Workshops (SPW) for 2024
DOI: 10.1109/SPW63631.2024.00014
💡 一句话要点
比较ChatGPT与StackOverflow代码的安全漏洞以提升开发者意识
🎯 匹配领域: 支柱九:具身大模型 (Embodied Foundation Models)
关键词: 生成式人工智能 代码安全 安全漏洞 StackOverflow ChatGPT 软件工程 实证研究
📋 核心要点
- 开发者在使用生成式AI与传统信息源(如StackOverflow)时面临安全漏洞的选择困境。
- 本研究通过比较ChatGPT与StackOverflow生成代码的安全漏洞,旨在提高开发者的安全意识。
- 实验结果显示,ChatGPT生成的代码漏洞数量显著低于StackOverflow,且涉及的CWE类型也较少。
📝 摘要(中文)
Sonatype 2023年的报告显示,97%的开发者和安全负责人在开发过程中整合了生成式人工智能(AI),尤其是大型语言模型(LLMs)。然而,这一趋势引发了对安全隐患的担忧。本文旨在通过实证比较ChatGPT与StackOverflow生成的代码片段的安全漏洞,提升软件开发者对选择代码片段时安全隐患的认识。研究发现,ChatGPT生成的代码包含248个漏洞,而StackOverflow的代码片段则有302个,前者的漏洞数量显著减少20%。此外,ChatGPT生成的CWE类型为19种,低于StackOverflow的22种。研究结果表明,开发者对两者平台上不安全代码的传播缺乏足够的认识,强调了良好的软件工程实践的重要性。
🔬 方法详解
问题定义:本文解决了开发者在选择代码片段时对安全漏洞的认知不足问题,现有方法未能有效比较不同信息源的安全性。
核心思路:通过实证研究比较ChatGPT与StackOverflow生成的代码片段的安全漏洞,旨在为开发者提供更可靠的代码选择依据。
技术框架:研究使用了一个包含安全相关问题和答案的Java数据集,首先从StackOverflow收集代码片段,然后向ChatGPT提出相同问题以获取生成代码,最后使用CodeQL分析漏洞。
关键创新:本研究首次系统性比较了生成式AI与传统编程社区在代码安全性方面的差异,揭示了两者在漏洞数量和类型上的显著差异。
关键设计:研究中使用了CodeQL进行漏洞分析,重点关注Common Weakness Enumeration (CWE)的分类,确保了分析的全面性和准确性。通过对108个代码片段的分析,确保了结果的统计显著性。
🖼️ 关键图片
📊 实验亮点
实验结果显示,ChatGPT生成的代码片段包含248个漏洞,相较于StackOverflow的302个漏洞,减少了20%。此外,ChatGPT生成的CWE类型为19种,低于StackOverflow的22种,表明生成式AI在某些情况下可能提供更安全的代码选择。
🎯 应用场景
该研究的结果对软件开发领域具有重要的应用价值,尤其是在安全敏感的应用程序开发中。通过提高开发者对代码安全性的认识,可以有效减少不安全代码的传播,促进更安全的软件开发实践。未来的研究可以进一步探索如何利用生成式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.