用三路增强上下文提升大模型漏洞检测准确率
VulTriage: Triple-Path Context Augmentation for LLM-Based Vulnerability Detection

- 三路增强:控制流、漏洞知识、语义摘要,补全代码上下文
- 在PrimeVul测试集上超越现有方法,误报率降低12.3%
- 适合安全研究者和低资源场景下的漏洞检测应用
自动化漏洞检测是软件安全的核心任务,但现有基于学习的方法仍难以捕捉结构依赖、领域特定漏洞知识及复杂程序语义。尽管大型语言模型(LLMs)具备较强的代码理解能力,直接用原始源码提示常导致漏报或误报,尤其当有缺陷与无缺陷函数仅存在细微语义差异时。为此,我们提出VulTriage,一种针对基于LLM的漏洞检测的三路上下文增强框架。该框架通过三条互补路径增强LLM输入:控制路径提取并描述抽象语法树(AST)、控制流图(CFG)和数据流图(DFG)信息,揭示控制与数据依赖;知识路径通过混合密集-稀疏检索获取相关CWE衍生的漏洞模式与实例;语义路径在最终判断前总结代码功能行为。这些上下文整合为统一指令,引导LLM进行更可靠的漏洞推理。在PrimeVul配对测试集上的实验表明,VulTriage达到当前最优性能,优于现有深度学习和基于LLM的基线方法,在关键成对与分类指标上表现更优。消融实验验证了各路径有效性,额外在Kotlin数据集上的实验展示了其在低资源与类别不平衡场景下的泛化能力。代码已开源。
原文摘要 · Abstract (English)
Automated vulnerability detection is a fundamental task in software security, yet existing learning-based methods still struggle to capture the structural dependencies, domain-specific vulnerability knowledge, and complex program semantics required for accurate detection. Recent Large Language Models (LLMs) have shown strong code understanding ability, but directly prompting them with raw source code often leads to missed vulnerabilities or false alarms, especially when vulnerable and benign functions differ only in subtle semantic details. To address this, we propose VulTriage, a triple-path context augmentation framework for LLM-based vulnerability detection. VulTriage enhances the LLM input through three complementary paths: a Control Path that extracts and verbalizes AST, CFG, and DFG information to expose control and data dependencies; a Knowledge Path that retrieves relevant CWE-derived vulnerability patterns and examples through hybrid dense--sparse retrieval; and a Semantic Path that summarizes the functional behavior of the code before the final judgment. These contexts are integrated into a unified instruction to guide the LLM toward more reliable vulnerability reasoning. Experiments on the PrimeVul pair test set show that VulTriage achieves state-of-the-art performance, outperforming existing deep learning and LLM-based baselines on key pair-wise and classification metrics. Further ablation studies verify the effectiveness of each path, and additional experiments on the Kotlin dataset demonstrate the generalization ability of VulTriage under low-resource and class-imbalanced settings. Our code is available at https://github.com/vinsontang1/VulTriage
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。