arXiv:2508.18933cs.AIcs.CR2025-08AAAI被引 7

用反事实数据增强提升代码漏洞检测的鲁棒性与可解释性

VISION: Robust and Interpretable Code Vulnerability Detection Leveraging Counterfactual Augmentation

  • 通过大模型生成语义微变但标签相反的反事实代码对
  • 在对抗样本对上训练图神经网络,准确率从51.8%提至97.8%
  • 支持可视化分析,适合安全研究者与可信AI开发者

自动化检测源代码漏洞是保障数字系统可信性的关键挑战。图神经网络(GNN)虽能学习代码结构关系,但受限于训练数据不平衡和标签噪声,常捕捉表面相似性等虚假关联,导致泛化能力差。本文提出统一框架VISION,通过系统性构建反事实训练数据缓解虚假关联:(i) 利用大语言模型生成语义微变但标签相反的反事实样本;(ii) 在成对代码上进行针对性GNN训练;(iii) 基于图的可解释性识别关键代码段,排除虚假关联。实验表明,VISION将CWE-20漏洞检测的整体准确率从51.8%提升至97.8%,成对对比准确率从4.5%升至95.8%,最差组准确率从0.7%提高到85.5%。我们还引入新评估指标:类内归因方差、类间归因距离与节点得分依赖性。同时发布CWE-20-CFA基准数据集,包含27,556个真实与反事实函数。最后,通过交互式可视化实现人机协同分析,推动可信的AI安全系统发展。

原文摘要 · Abstract (English)

Automated detection of vulnerabilities in source code is an essential cybersecurity challenge, underpinning trust in digital systems and services. Graph Neural Networks (GNNs) have emerged as a promising approach as they can learn structural and logical code relationships in a data-driven manner. However, their performance is severely constrained by training data imbalances and label noise. GNNs often learn 'spurious' correlations from superficial code similarities, producing detectors that fail to generalize well to unseen real-world data. In this work, we propose a unified framework for robust and interpretable vulnerability detection, called VISION, to mitigate spurious correlations by systematically augmenting a counterfactual training dataset. Counterfactuals are samples with minimal semantic modifications but opposite labels. Our framework includes: (i) generating counterfactuals by prompting a Large Language Model (LLM); (ii) targeted GNN training on paired code examples with opposite labels; and (iii) graph-based interpretability to identify the crucial code statements relevant for vulnerability predictions while ignoring spurious ones. We find that VISION reduces spurious learning and enables more robust, generalizable detection, improving overall accuracy (from 51.8% to 97.8%), pairwise contrast accuracy (from 4.5% to 95.8%), and worst-group accuracy (from 0.7% to 85.5%) on the Common Weakness Enumeration (CWE)-20 vulnerability. We further demonstrate gains using proposed metrics: intra-class attribution variance, inter-class attribution distance, and node score dependency. We also release CWE-20-CFA, a benchmark of 27,556 functions (real and counterfactual) from the high-impact CWE-20 category. Finally, VISION advances transparent and trustworthy AI-based cybersecurity systems through interactive visualization for human-in-the-loop analysis.

代码安全图神经网络可解释性反事实

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