NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Multi-Granularity Detector for Vulnerability Fixes

Truong Giang Nguyen, Thanh Le-Cong, Hong Jin Kang, Ratnadira Widyasari, Chengran Yang, Zhipeng Zhao, Bowen Xu, Jiayuan Zhou, Xin Xia, Ahmed E. Hassan, Xuan-Bach Dinh Le, David LoIEEE Trans. Software Eng 2023 · DOI

Abstract

With the increasing reliance on Open Source Software, users are exposed to third-party library vulnerabilities. Software Composition Analysis (SCA) tools have been created to alert users of such vulnerabilities. SCA requires the identification of vulnerability-fixing commits. Prior works have proposed methods that can automatically identify such vulnerability-fixing commits. However, identifying such commits is highly challenging, as only a very small minority of commits are vulnerability fixing. Moreover, code changes can be noisy and difficult to analyze. We observe that noise can occur at different levels of detail, making it challenging to detect vulnerability fixes accurately. To address these challenges and boost the effectiveness of prior works, we propose MiDas (Multi-Granularity Detector for Vulnerability Fixes). Unique from prior works, Midas constructs different neural networks for each level of code change granularity, corresponding to commit-level, file-level, hunk-level, and line-level, following their natural organization. It then utilizes an ensemble model that combines all base models to generate the final prediction. This design allows MiDas to better handle the noisy and highly imbalanced nature of vulnerability-fixing commit data. Additionally, to reduce the human effort required to inspect code changes, we have designed an effort-aware adjustment for Midas's outputs based on commit length. The evaluation results demonstrate that MiDas outperforms the current state-of-the-art baseline in terms of AUC by 4.9% and 13.7% on Java and Python-based datasets, respectively. Furthermore, in terms of two effort-aware metrics, EffortCost@L and Popt@L, MiDas also outperforms the state-of-the-art baseline, achieving improvements of up to 28.2% and 15.9% on Java, and 60% and 51.4% on Python, respectively.

Introduction

Software Composition Analysis (SCA) tools are critical for modern development, alerting teams to vulnerabilities in third-party libraries. However, these tools often rely on public databases like the National Vulnerability Database (NVD), which can lag behind the actual fix in a repository. This delay creates a "window of opportunity" for attackers. To mitigate this, researchers aim to automatically identify vulnerability-fixing commits (VFCs) directly from version control systems.

Identifying VFCs is notoriously difficult due to two primary factors: extreme data imbalance and "tangled" changes. VFCs typically represent less than 1% of all commits. Furthermore, commits are often noisy; a single commit might bundle a security fix with unrelated refactoring, feature additions, or documentation updates. Existing single-granularity detectors often fail because the security signal is drowned out by this surrounding noise.

MiDas identifies vulnerability-fixing lines (VF) while filtering out unrelated "noise" such as logging updates.

The MiDas Framework

To address these challenges, we propose MiDas (Multi-Granularity Detector for Vulnerability Fixes). Unlike previous approaches that analyze code at a single level, MiDas decomposes every commit into its natural hierarchical components: commit-level, file-level, hunk-level, and line-level.

Multi-level Decomposition and Feature Extraction

MiDas utilizes CodeBERT to generate initial embeddings for code fragments. It then employs specialized neural architectures tailored to each level of granularity:

  • Line-level: Uses BiLSTM to capture sequential logic within individual lines.
  • Hunk-level: Uses Convolutional Neural Networks (CNN) to capture local dependencies within continuous blocks of code.
  • File and Commit-levels: Uses Fully Connected Networks (FCN) to analyze broader structural changes.

An ensemble model then combines the features from all four levels to generate a final prediction. This multi-granularity approach allows the model to "disentangle" security fixes from unrelated changes, focusing on the specific lines or hunks that actually address a vulnerability.

The MiDas architecture: from multi-level code decomposition to ensemble classification and effort-aware adjustment.

Effort-Aware Adjustment

In industrial settings, security researchers have limited time to manually verify potential VFCs. MiDas incorporates an effort-aware adjustment that modifies the predicted probability based on the commit length (Lines of Code). By prioritizing shorter commits, which are easier to inspect, MiDas maximizes the practical utility of its findings for human experts.

Evaluation

We evaluated MiDas using the VulFixMiner dataset, covering 150 Java projects and 106 Python projects, including a manually curated SAP dataset. We also conducted real-world validation on the TensorFlow framework.

MiDas significantly outperformed the current state-of-the-art baseline (VulFixMiner):

  • Accuracy: Improved AUC by 4.9% for Java and 13.7% for Python.
  • Efficiency: Achieved improvements of up to 60% in effort-aware metrics (EffortCost@L and Popt@L) on Python datasets.
  • Real-world Impact: On the TensorFlow dataset, MiDas achieved an AUC of 0.88, successfully detecting 81% of vulnerabilities by requiring the inspection of only 5% of the total lines of code.

Conclusion

MiDas demonstrates that analyzing code changes at multiple levels of granularity is essential for overcoming the noise and imbalance inherent in vulnerability detection. By combining hierarchical deep learning with effort-aware prioritization, MiDas provides a robust and practical solution for identifying "silent" security fixes, helping to secure the software supply chain more effectively.

Summary updated

BibTeX
@article{nguyen2023multi,
  author = {Truong Giang Nguyen and Thanh Le-Cong and Hong Jin Kang and Ratnadira Widyasari and Chengran Yang and Zhipeng Zhao and Bowen Xu and Jiayuan Zhou and Xin Xia and Ahmed E. Hassan and Xuan-Bach Dinh Le and David Lo},
  title = {{Multi-Granularity Detector for Vulnerability Fixes}},
  journal = {IEEE Trans. Software Eng.},
  year = {2023},
  doi = {10.1109/tse.2023.3281275},
}
Figure