TL;DR
Vulnerability detection models are only as good as the data they are trained on, yet current datasets are plagued by "noise"—non-security code changes mistakenly labeled as vulnerability fixes. This paper introduces VulSifter, a tool that combines Large Language Models (LLMs) with regex-based heuristics to clean this data, resulting in CleanVul, a high-quality dataset of over 8,000 functions that significantly improves the performance and generalization of vulnerability detection models.
What Problem Does This Paper Address?
Machine learning models for vulnerability detection rely on datasets derived from "vulnerability-fixing commits" (VFCs). However, these datasets are notoriously noisy, with estimates suggesting that 40% to 75% of the labeled data is incorrect.
The culprit is a phenomenon known as tangled commits. When a developer fixes a security flaw, they often perform routine maintenance in the same commit—updating documentation, refactoring code, or adding new tests. Traditional automated labeling indiscriminately flags all changes in a VFC as security-related. When models train on this "noisy" data, they learn to associate benign coding patterns (like adding a test case) with security threats, leading to poor real-world performance.
Methods
The authors propose a two-stage methodology called VulSifter to discern genuine vulnerability fixes from noise:
- Heuristic Filtering: Based on an empirical study of VFCs, the authors found that nearly 80% of non-vulnerability changes are either test-related or general bug fixes. VulSifter uses a suite of regular expressions to automatically identify and filter out test functions and files before they reach the LLM.
- LLM Semantic Analysis: The remaining code changes are passed to an LLM (specifically GPT-4). Unlike simple keyword matching, the LLM is prompted to act as a cybersecurity expert, analyzing the "Original" and "Revised" code snippets alongside the commit message and surrounding context.
- Fine-Grained Scoring: Instead of a binary "yes/no," the LLM provides a score from 0 to 4 representing its confidence that a change is a vulnerability fix. This allows researchers to tune the "cleanliness" of their dataset by adjusting the threshold.
Datasets
The authors crawled over 127,000 GitHub repositories to collect over 5 million commits. Using VulSifter, they curated:
- CleanVul: A new high-quality dataset containing 8,198 functions (at threshold 3) across six programming languages (Java, Python, C, C++, C#, and JavaScript).
For evaluation and comparison, they used several established datasets:
- SVEN: A manually curated, high-correctness but small dataset (803 functions).
- PrimeVul: A high-quality dataset that relies on linking commits to National Vulnerability Database (NVD) entries.
- Noisy Baselines: Large-scale but uncleaned datasets like BigVul and DiverseVul.
Key Insights and Ideas
- The "Tangled" Reality: The paper quantifies why VFCs are noisy. As shown in their analysis, test-related changes (41.2%) and general bug fixes (38.2%) are the primary sources of false positives in vulnerability datasets.
- Semantics Over Keywords: Traditional tools often fail because they rely on keywords like "attack" or "fix." The authors highlight a case where a commit was flagged as a VFC because it mentioned "attack," but it actually referred to a gameplay mechanic in a computer game. The LLM's ability to understand context is what makes noise reduction effective.
- Generalization is the Gold Standard: The most striking finding is that models trained on CleanVul generalize better to other datasets than models trained on those datasets themselves. This suggests that by removing noise, the models are learning the fundamental "features" of a vulnerability rather than dataset-specific quirks.
Key Results
- High Correctness: CleanVul achieved a 90.6% correctness rate (at threshold 3), making it comparable to the gold-standard manually curated SVEN dataset (94%) but at a much larger scale.
- Superior Performance: In cross-dataset testing, a CodeBERT model fine-tuned on CleanVul and tested on PrimeVul achieved 58.09% accuracy, outperforming a model trained and tested exclusively on PrimeVul (56.61%).
- LLM Efficacy: GPT-4 emerged as the strongest engine for VulSifter, achieving an F1-score of 0.82 in identifying genuine fixes, significantly higher than other models like Claude or Gemini.
Limitations and Future Work
While VulSifter is a major step forward, the authors acknowledge a few hurdles:
- Token Limits: The current approach is limited by the LLM's input window (512 tokens in this study), which can be problematic for very large functions or complex commits.
- Scalability Costs: Using commercial LLMs for millions of commits can be expensive. The authors suggest that smaller, specialized models might be optimized for this task in the future.
- Context Integration: Future work aims to explore "hierarchical analysis" to maintain model attention across even larger codebases and integrate more project-level metadata.
Summary updated