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

LLM是否考虑了安全性?关于编程问题回答的实证研究

Do LLMs Consider Security? An Empirical Study on Responses to Programming Questions

College of Computing and Informatics, Drexel University(德雷塞尔大学计算与信息学院);College of Engineering, Virginia Commonwealth University(弗吉尼亚联邦大学工程学院)

Amirali Sajadi, Binh Le, Anh Nguyen, Kostadin Damevski, Preetha Chatterjee

AI总结:

本研究评估了Claude 3、GPT-4和Llama 3在回答含漏洞代码的编程问题时表现出的安全意识,发现其漏洞检测率仅为12.6%至40%,并提出了一种基于CLI的提示工具以生成更安全的回答。

摘要:

对话式LLM在软件开发中的广泛采用引发了关于LLM生成内容安全性的新担忧。我们的动机研究概述了ChatGPT在主动向开发者提供上下文相关信息以促进安全编码实践方面的潜力。受此发现启发,我们开展了一项研究,评估三种知名LLM(Claude 3、GPT-4和Llama 3)所表现出的安全意识程度。我们使用包含漏洞代码的Stack Overflow问题来提示这些LLM,以评估它们是仅仅提供问题的答案,还是也会警告用户代码的不安全性,从而展现出一定程度的安全意识。此外,我们评估LLM的回答是否提供了关于漏洞原因、利用方式和潜在修复方法的信息,以帮助提高用户的意识。我们的研究结果表明,所有三个模型都难以准确检测漏洞并向用户发出警告,在我们的数据集中检测率仅为12.6%到40%。我们还观察到,与涉及文件名或路径外部控制的漏洞相比,LLM更倾向于识别与敏感信息暴露和输入不当中和相关的某些类型的漏洞。此外,当LLM确实发出安全警告时,与Stack Overflow的回答相比,它们通常会提供更多关于漏洞原因、利用方式和修复方法的信息。最后,我们对研究结果的启示进行了深入讨论,并提出了一种基于CLI的提示工具,可用于生成显著更安全的LLM回答。

英文摘要:

The widespread adoption of conversational LLMs for software development has raised new security concerns regarding the safety of LLM-generated content. Our motivational study outlines ChatGPT's potential in volunteering context-specific information to the developers, promoting safe coding practices. Motivated by this finding, we conduct a study to evaluate the degree of security awareness exhibited by three prominent LLMs: Claude 3, GPT-4, and Llama 3. We prompt these LLMs with Stack Overflow questions that contain vulnerable code to evaluate whether they merely provide answers to the questions or if they also warn users about the insecure code, thereby demonstrating a degree of security awareness. Further, we assess whether LLM responses provide information about the causes, exploits, and the potential fixes of the vulnerability, to help raise users' awareness. Our findings show that all three models struggle to accurately detect and warn users about vulnerabilities, achieving a detection rate of only 12.6% to 40% across our datasets. We also observe that the LLMs tend to identify certain types of vulnerabilities related to sensitive information exposure and improper input neutralization much more frequently than other types, such as those involving external control of file names or paths. Furthermore, when LLMs do issue security warnings, they often provide more information on the causes, exploits, and fixes of vulnerabilities compared to Stack Overflow responses. Finally, we provide an in-depth discussion on the implications of our findings and present a CLI-based prompting tool that can be used to generate significantly more secure LLM responses.

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

↑