An Insight into Security Code Review with LLMs: Capabilities, Obstacles, and Influential Factors

📄 arXiv: 2401.16310v6 📥 PDF

作者: Jiaxin Yu, Peng Liang, Yujia Fu, Amjed Tahir, Mojtaba Shahin, Chong Wang, Yangxiao Cai

分类: cs.SE, cs.AI

发布日期: 2024-01-29 (更新: 2026-05-09)

备注: 30 pages, 13 images, 10 tables, Manuscript revision submitted to a journal (2026)


💡 一句话要点

利用大型语言模型提升安全代码审查效率

🎯 匹配领域: 支柱九:具身大模型 (Embodied Foundation Models)

关键词: 安全代码审查 大型语言模型 静态分析工具 安全缺陷检测 深度学习 性能评估 提示设计

📋 核心要点

  1. 现有安全分析工具在泛化能力、假阳性率和检测粒度方面存在显著不足,影响了安全代码审查的效率和准确性。
  2. 本文提出利用大型语言模型(LLMs)进行安全代码审查,探索其在检测安全缺陷中的潜力,并通过实证研究进行评估。
  3. 实验结果显示,LLMs在安全代码审查中表现优于传统工具,DeepSeek-R1和GPT-4的性能差异显著,提示设计对模型表现影响较大。

📝 摘要(中文)

安全代码审查是一个耗时且劳动密集的过程,通常需要与自动化安全缺陷检测工具结合。然而,现有的安全分析工具在泛化能力差、高假阳性率和检测粒度粗等方面存在不足。本文通过实证研究探讨了大型语言模型(LLMs)在代码审查中检测安全缺陷的潜力,评估了七种LLMs在五种不同提示下的表现,并与最先进的静态分析工具进行了比较。研究结果表明,LLMs在安全代码审查中显著优于传统静态分析工具,DeepSeek-R1的表现最佳,其次是GPT-4。最优提示设计对不同模型的性能影响显著。

🔬 方法详解

问题定义:本文旨在解决现有安全代码审查工具在泛化能力差、高假阳性率和粗粒度检测等方面的痛点,探索LLMs在此领域的应用潜力。

核心思路:通过实证研究评估七种LLMs在安全缺陷检测中的表现,比较其与传统静态分析工具的效果,分析影响性能的因素。

技术框架:研究采用了七种LLMs,设计了五种不同的提示,进行性能评估,并对表现最好的两个模型进行了语言学和回归分析,以识别其输出中的质量问题及影响因素。

关键创新:本文的创新在于系统性地评估LLMs在安全代码审查中的应用,发现其在特定条件下优于传统工具,尤其是针对特定类型的安全缺陷。

关键设计:在提示设计上,DeepSeek-R1的最佳提示结合了提交信息和思维链指导,而GPT-4则使用了常见弱点枚举(CWE)列表。

🖼️ 关键图片

fig_0
fig_1
fig_2

📊 实验亮点

实验结果表明,LLMs在安全代码审查中显著优于最先进的静态分析工具,DeepSeek-R1的性能最高,GPT-4表现紧随其后。DeepSeek-R1在特定安全缺陷类型的检测能力上与代码复杂性呈正相关,提示设计对模型性能影响显著。

🎯 应用场景

该研究的潜在应用领域包括软件开发中的安全审查、代码质量提升和自动化安全检测工具的优化。通过引入LLMs,开发者可以更高效地识别和修复安全缺陷,从而提升软件的安全性和可靠性,未来可能对软件工程实践产生深远影响。

📄 摘要(原文)

Security code review is a time-consuming and labor-intensive process typically requiring integration with automated security defect detection tools. However, existing security analysis tools struggle with poor generalization, high false positive rates, and coarse detection granularity. Large Language Models (LLMs) have been considered promising candidates for addressing those challenges. In this study, we conducted an empirical study to explore the potential of LLMs in detecting security defects during code review. Specifically, we evaluated the performance of seven LLMs under five different prompts and compared them with state-of-the-art static analysis tools. We also performed linguistic and regression analyses for the two top-performing LLMs to identify quality problems in their responses and factors influencing their performance. Our findings show that: (1) In security code review, LLMs significantly outperform state-of-the-art static analysis tools, and the reasoning-optimized LLM performs better than general-purpose LLMs. (2) DeepSeek-R1 achieves the highest performance, followed by GPT-4 provided in the ChatGPT platform. The optimal prompt for DeepSeek-R1 incorporates both the commit message and chain-of-thought (CoT) guidance, while for GPT-4 via ChatGPT, the prompt with a Common Weakness Enumeration (CWE) list works best. (3) GPT-4 via ChatGPT frequently produces vague expressions and exhibits difficulties in accurately following instructions in the prompts, while DeepSeek-R1 more commonly generates inaccurate code details in its outputs. (4) LLMs are more adept at identifying security defects in code files that have fewer tokens and security-relevant annotations. (5) Higher code complexity correlates with enhanced detection capabilities of DeepSeek-R1 for specific security defect types.