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

Vulnerability Detection with Code Language Models: How Far are We?

Yangruibo Ding, Yanjun Fu, Omniyyah Ibrahim, Chawin Sitawarin, Xinyun Chen, Basel Alomair, David A. Wagner, Baishakhi Ray, Yizheng Chen

TL;DR

Code language models (code LMs) appear highly capable of detecting software vulnerabilities on paper, but this performance is largely an illusion caused by flawed benchmarks. By introducing a rigorously cleaned, realistically distributed dataset called PRIMEVUL, this paper demonstrates that current state-of-the-art models—including GPT-4—struggle significantly, often performing no better than random guessing in realistic settings.

What Problem Does This Paper Address?

Automating vulnerability detection (VD) using code LMs is a highly active area of research. However, the authors identify three critical flaws in how these models are currently trained and evaluated:

  1. Noisy Labels: Most large-scale datasets rely on automated labeling heuristics (e.g., marking every function modified in a security patch as "vulnerable"). In reality, patches often alter surrounding, non-vulnerable code for consistency or formatting, leading to massive label noise.
  2. Data Leakage: Code duplication is rampant. Exact copies or near-duplicates of vulnerable functions frequently span both the training and testing splits, artificially inflating model performance.
  3. Misleading Metrics: Standard metrics like Accuracy and F1-score fail to reflect real-world utility. In practice, vulnerabilities are rare (the base-rate problem), and developers face severe alert fatigue if a tool introduces excessive false positives.
The statistics of data duplication in existing vulnerability detection benchmarks.

Methods

To counter these limitations, the authors propose a new framework consisting of:

  • Rigorous De-duplication: Normalizing formatting characters and using MD5 hashing to ensure zero data leakage between splits.
  • Advanced Labeling Techniques: They introduce two high-accuracy automated labeling heuristics: PRIMEVUL-ONEFUNC (isolating commits that only modify a single function) and PRIMEVUL-NVDCHECK (cross-referencing code changes with official NVD CVE descriptions).
  • Temporal Splitting: Splitting data chronologically rather than randomly, forcing models to train on past code and test on future code, mimicking real-world deployment.
  • Realistic Evaluation Metrics: They introduce the Vulnerability Detection Score (VD-S), which measures the false negative rate when the false positive rate is capped at a strict, practical threshold (≤ 0.5%). They also introduce pair-wise evaluation, testing a model's ability to distinguish a vulnerable function directly from its patched counterpart.

The authors evaluated a diverse suite of seven models using these methods, ranging from smaller encoder models like CodeBERT to massive proprietary LLMs like GPT-4.

The code LMs studied in this paper.

Datasets

The paper introduces PRIMEVUL, a large-scale, high-quality dataset compiled by merging and filtering existing repositories (BigVul, CrossVul, CVEFixes, and DiverseVul).

Statistics of the PRIMEVUL dataset, including all functions and paired functions.

PRIMEVUL achieves a human-verified label accuracy of up to 92% (on par with small, manually curated datasets like SVEN) while scaling to 6,968 vulnerable and 228,800 benign functions across 140 Common Weakness Enumerations (CWEs).

Label accuracy across existing benchmarks compared to PRIMEVUL's automated techniques.

Key Insights and Ideas

  • The Performance Collapse: Models that achieve stellar results on older benchmarks fail catastrophically on PRIMEVUL. For example, StarCoder2 drops from a 68.26% F1-score on BigVul to a meager 3.09% on PRIMEVUL.
  • Textual Shortcuts vs. Semantic Understanding: Pair-wise evaluations reveal that code LMs rely heavily on superficial text patterns rather than understanding security logic. When presented with a vulnerable function and its patch, models frequently classify both as either benign or vulnerable.
  • Scale and Advanced Training are Not Enough: Standard mitigation strategies like adjusting class weights or employing contrastive learning yield only marginal improvements. Even massive models like GPT-4, when equipped with Chain-of-Thought (CoT) reasoning, fail to beat a random baseline on pair-wise discrimination tasks.

Key Results

The main evaluation highlights a stark reality check for LLM-based vulnerability detection:

Performance of code-LM-based vulnerability detection models across different settings.
  • High False Negatives: Under the realistic VD-S metric (FPR ≤ 0.5%), the false negative rates for all open-source models hover around 90%, meaning they miss 9 out of 10 real vulnerabilities.
  • Class Weights Failure: Attempting to fix the dataset's class imbalance by up-weighting the vulnerable class slightly improves the F1 score but fails to lower the practical false negative rate significantly.
The impact of class weights during training.
  • LLM Evaluation: On the challenging pair-wise task, a random guess yields a Pair-wise Correct (P-C) score of 22.70%. GPT-4 with Chain-of-Thought prompting only achieves 12.94%, demonstrating that it frequently misidentifies the subtle semantic differences introduced by security patches.

Limitations and Future Work

The authors note that evaluating vulnerabilities at the single-function level is inherently limited. Many security flaws (like race conditions or interprocedural data leaks) require broader system context to detect accurately.

Future work should focus on:

  1. Providing models with broader repository-level context.
  2. Developing pre-training objectives specifically tailored to security concepts rather than generic code completion.
  3. Decomposing the binary classification task into multi-step, explainable program analysis steps that models can reason through sequentially.

Summary updated

BibTeX
@inproceedings{ding2025vulnerability,
  author = {Yangruibo Ding and Yanjun Fu and Omniyyah Ibrahim and Chawin Sitawarin and Xinyun Chen and Basel Alomair and David A. Wagner and Baishakhi Ray and Yizheng Chen},
  title = {{Vulnerability Detection with Code Language Models: How Far are We?}},
  booktitle = {ICSE},
  year = {2025},
  doi = {10.1109/icse55347.2025.00038},
}
Figure