arXiv:2502.06898cs.SEcs.AI2025-02中稿 · publication at the…被引 17

大模型检测代码漏洞时,越靠近文件末尾越容易漏检。

Large Language Models for In-File Vulnerability Localization Can Be "Lost in the End"

  • 发现大模型在处理长文件时对末尾漏洞检测能力显著下降。
  • 末尾漏洞漏检率高,平均召回率提升超37%可通过调整输入长度实现。
  • 提出简单策略可优化模型输入大小,适用于多种漏洞和模型。

近年来,人工智能发展使大语言模型(LLM)能处理更大输入,软件开发者开始用 GPT-3.5、GPT-4 等模型检测整个文件中的漏洞。本文评估了主流聊天式 LLM 在检测三类常见且危险漏洞(XSS、SQL 注入、路径遍历)时的表现。研究发现,模型性能受漏洞位置与输入大小双重影响:无论漏洞类型如何,当漏洞位于较大文件末尾时,检测效果显著下降(p < .05),这一现象称为“丢失在末尾”效应。通过探索最优输入尺寸,我们提出一种简单策略,可显著提升检测效果——所有模型平均召回率提升超过37%。

原文摘要 · Abstract (English)

Recent advancements in artificial intelligence have enabled processing of larger inputs, leading everyday software developers to increasingly rely on chat-based large language models (LLMs) like GPT-3.5 and GPT-4 to detect vulnerabilities across entire files, not just within functions. This new development practice requires researchers to urgently investigate whether commonly used LLMs can effectively analyze large file-sized inputs, in order to provide timely insights for software developers and engineers about the pros and cons of this emerging technological trend. Hence, the goal of this paper is to evaluate the effectiveness of several state-of-the-art chat-based LLMs, including the GPT models, in detecting in-file vulnerabilities. We conducted a costly investigation into how the performance of LLMs varies based on vulnerability type, input size, and vulnerability location within the file. To give enough statistical power to our study, we could only focus on the three most common (as well as dangerous) vulnerabilities: XSS, SQL injection, and path traversal. Our findings indicate that the effectiveness of LLMs in detecting these vulnerabilities is strongly influenced by both the location of the vulnerability and the overall size of the input. Specifically, regardless of the vulnerability type, LLMs tend to significantly (p < .05) underperform when detecting vulnerabilities located toward the end of larger files, a pattern we call the 'lost-in-the-end' effect. Finally, to further support software developers and practitioners, we also explored the optimal input size for these LLMs and presented a simple strategy for identifying it, which can be applied to other models and vulnerability types. Eventually, we show how adjusting the input size can lead to significant improvements in LLM-based vulnerability detection, with an average recall increase of over 37% across all models.

代码安全大模型漏洞检测

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