arXiv:2502.14202cs.SEcs.AI2025-02中稿 · EMSE被引 33

测试三大模型对代码漏洞的识别能力,发现普遍不靠谱。

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

  • 用漏洞代码提问,看模型能否主动预警安全风险。
  • 检测率仅12.6%到40%,对特定漏洞更敏感。
  • 虽预警少,但一旦提醒,解释比社区回答更详细。

对话式大模型在软件开发中的广泛应用引发了对其生成内容安全性的新担忧。本文研究发现,ChatGPT有主动提供上下文安全信息、促进安全编码的潜力。基于此,我们评估了Claude 3、GPT-4和Llama 3三款主流大模型的安全意识水平。通过向它们提出包含漏洞代码的Stack Overflow问题,考察其是否仅给出答案,还是能主动警示不安全代码。进一步分析其是否提供漏洞成因、利用方式及修复方案,以提升用户认知。结果显示,三模型对漏洞的准确检测率仅为12.6%至40%,且对敏感信息暴露和输入未净化类漏洞识别率更高,而对外部控制文件名或路径等类型识别不足。当模型发出安全警告时,其提供的成因、利用与修复信息通常优于原始Stack Overflow回答。最后,我们讨论了研究启示,并开源了一个命令行提示工具,可显著提升模型响应的安全性。

原文摘要 · Abstract (English)

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.

安全大模型代码漏洞检测

Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。