Table of Contents
Fetching ...

CleanVul: Automatic Function-Level Vulnerability Detection in Code Commits Using LLM Heuristics

Yikun Li, Ting Zhang, Ratnadira Widyasari, Yan Naing Tun, Huu Hung Nguyen, Tan Bui, Ivana Clairine Irsan, Yiran Cheng, Xiang Lan, Han Wei Ang, Frank Liauw, Martin Weyssow, Hong Jin Kang, Eng Lieh Ouh, Lwin Khin Shar, David Lo

TL;DR

The paper tackles the problem of noisy vulnerability datasets by showing that many changes within vulnerability-fixing commits are not actual vulnerability fixes. It introduces VulSifter, an LLM-guided approach augmented with heuristics to automatically identify function-level vulnerability-fixing changes, and builds CleanVul from 5.3 million commits across GitHub, achieving a Correctness of 90.6% at a threshold of 3. The work demonstrates that models fine-tuned on CleanVul generalize better to established datasets like SVEN and PrimeVul, and even outperform models trained on those datasets in some cross-dataset evaluations. By providing a scalable, NVD-independent method to clean data and improve cross-language vulnerability detection, the paper offers a practical path to higher-quality vulnerability datasets and more robust detection models.

Abstract

Accurate identification of software vulnerabilities is crucial for system integrity. Vulnerability datasets, often derived from the National Vulnerability Database (NVD) or directly from GitHub, are essential for training machine learning models to detect these security flaws. However, these datasets frequently suffer from significant noise, typically 40% to 75%, due primarily to the automatic and indiscriminate labeling of all changes in vulnerability-fixing commits (VFCs) as vulnerability-related. This misclassification occurs because not all changes in a commit aimed at fixing vulnerabilities pertain to security threats; many are routine updates like bug fixes or test improvements. This paper introduces the first methodology that uses the Large Language Model (LLM) with a heuristic enhancement to automatically identify vulnerability-fixing changes from VFCs, achieving an F1-score of 0.82. VulSifter was applied to a large-scale study, where we conducted a crawl of 127,063 repositories on GitHub, resulting in the acquisition of 5,352,105 commits. VulSifter involves utilizing an LLM to comprehend code semantics and contextual information, while applying heuristics to filter out unrelated changes. We then developed CleanVul, a high-quality dataset comprising 8,198 functions using our LLM heuristic enhancement approach, demonstrating Correctness (90.6%) comparable to established datasets such as SVEN and PrimeVul. To evaluate the CleanVul dataset, we conducted experiments focusing on fine-tuning various LLMs on CleanVul and other high-quality datasets. Evaluation results reveal that LLMs fine-tuned on CleanVul not only exhibit enhanced accuracy but also superior generalization capabilities compared to those trained on uncleaned datasets. Specifically, models trained on CleanVul and tested on PrimeVul achieve accuracy higher than those trained and tested exclusively on PrimeVul.

CleanVul: Automatic Function-Level Vulnerability Detection in Code Commits Using LLM Heuristics

TL;DR

The paper tackles the problem of noisy vulnerability datasets by showing that many changes within vulnerability-fixing commits are not actual vulnerability fixes. It introduces VulSifter, an LLM-guided approach augmented with heuristics to automatically identify function-level vulnerability-fixing changes, and builds CleanVul from 5.3 million commits across GitHub, achieving a Correctness of 90.6% at a threshold of 3. The work demonstrates that models fine-tuned on CleanVul generalize better to established datasets like SVEN and PrimeVul, and even outperform models trained on those datasets in some cross-dataset evaluations. By providing a scalable, NVD-independent method to clean data and improve cross-language vulnerability detection, the paper offers a practical path to higher-quality vulnerability datasets and more robust detection models.

Abstract

Accurate identification of software vulnerabilities is crucial for system integrity. Vulnerability datasets, often derived from the National Vulnerability Database (NVD) or directly from GitHub, are essential for training machine learning models to detect these security flaws. However, these datasets frequently suffer from significant noise, typically 40% to 75%, due primarily to the automatic and indiscriminate labeling of all changes in vulnerability-fixing commits (VFCs) as vulnerability-related. This misclassification occurs because not all changes in a commit aimed at fixing vulnerabilities pertain to security threats; many are routine updates like bug fixes or test improvements. This paper introduces the first methodology that uses the Large Language Model (LLM) with a heuristic enhancement to automatically identify vulnerability-fixing changes from VFCs, achieving an F1-score of 0.82. VulSifter was applied to a large-scale study, where we conducted a crawl of 127,063 repositories on GitHub, resulting in the acquisition of 5,352,105 commits. VulSifter involves utilizing an LLM to comprehend code semantics and contextual information, while applying heuristics to filter out unrelated changes. We then developed CleanVul, a high-quality dataset comprising 8,198 functions using our LLM heuristic enhancement approach, demonstrating Correctness (90.6%) comparable to established datasets such as SVEN and PrimeVul. To evaluate the CleanVul dataset, we conducted experiments focusing on fine-tuning various LLMs on CleanVul and other high-quality datasets. Evaluation results reveal that LLMs fine-tuned on CleanVul not only exhibit enhanced accuracy but also superior generalization capabilities compared to those trained on uncleaned datasets. Specifically, models trained on CleanVul and tested on PrimeVul achieve accuracy higher than those trained and tested exclusively on PrimeVul.

Paper Structure

This paper contains 53 sections, 4 figures, 10 tables.

Figures (4)

  • Figure 1: Overview of the Methods and Experiments Conducted in This Paper
  • Figure 2: The Prompt Produces a Score from 0 to 4, Representing the Confidence in Predicting Vulnerability-Fixing Changes.
  • Figure 3: Regular expression patterns for identifying test functions and test files across multiple programming languages (Java, C++, C#, JavaScript, and Python). The patterns capture both function declarations and test file naming conventions commonly used in various testing frameworks.
  • Figure 4: The Prompt Produces a Binary Output, Indicating Whether Changes are Vulnerability-Fixing or Not.