arXiv:2504.13676cs.CRcs.AI2025-04被引 6

用精简代码路径提升漏洞检测准确率

Trace Gadgets: Minimizing Code Context for Machine Learning-Based Vulnerability Prediction

  • 只保留通向漏洞的必要代码,减少无关上下文干扰
  • 在未见数据上比CodeQL等工具高4%以上准确率
  • 适合需要高精度漏洞检测的开发与安全团队

随着网络应用和API端点数量持续增长,可利用漏洞也不断增多。人工识别漏洞效率低,而静态扫描器常产生大量误报。机器学习方法虽有潜力,但通常仅在训练与测试数据相近时表现良好。关键挑战在于提供合适且简洁的代码上下文,过长的上下文会削弱模型(尤其是小型模型)的代码理解能力。本文提出Trace Gadgets,一种新型代码表示方法,通过移除无关代码,精准捕捉通向漏洞的执行路径。作为机器学习模型输入,Trace Gadgets提供最小但完整的上下文,从而提升检测性能。此外,我们构建了一个大规模真实应用数据集,经人工标注标签,进一步优化检测效果。实验表明,使用Trace Gadgets时,先进机器学习模型的表现优于以往代码表示方式,在完全未见过的数据集上,检测能力较GitHub CodeQL等工业级静态扫描器至少提升4%。将该框架应用于真实软件,成功发现并报告了多个此前未知的漏洞。

原文摘要 · Abstract (English)

As the number of web applications and API endpoints exposed to the Internet continues to grow, so does the number of exploitable vulnerabilities. Manually identifying such vulnerabilities is tedious. Meanwhile, static security scanners tend to produce many false positives. While machine learning-based approaches are promising, they typically perform well only in scenarios where training and test data are closely related. A key challenge for ML-based vulnerability detection is providing suitable and concise code context, as excessively long contexts negatively affect the code comprehension capabilities of machine learning models, particularly smaller ones. This work introduces Trace Gadgets, a novel code representation that minimizes code context by removing non-related code. Trace Gadgets precisely capture the statements that cover the path to the vulnerability. As input for ML models, Trace Gadgets provide a minimal but complete context, thereby improving the detection performance. Moreover, we collect a large-scale dataset generated from real-world applications with manually curated labels to further improve the performance of ML-based vulnerability detectors. Our results show that state-of-the-art machine learning models perform best when using Trace Gadgets compared to previous code representations, surpassing the detection capabilities of industry-standard static scanners such as GitHub's CodeQL by at least 4% on a fully unseen dataset. By applying our framework to real-world applications, we identify and report previously unknown vulnerabilities in widely deployed software.

漏洞检测代码分析机器学习安全工程

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