How far are code language models for vulnerability detection from practical use?Vulnerability Detection with Code Language Models: How Far Are We?
The authors build the vulnerability detection benchmark PrimeVul and evaluate 7 code LMs; the authors state that existing benchmarks overestimate model capability, and that GPT-4 CoT pairwise judgment is worse than random guessing.
- Existing vulnerability detection datasets have noisy labels and high duplication rates, and evaluation metrics are divorced from real deployment scenarios; the authors argue this leads to overestimation of code LMs' vulnerability detection capabilities.
- The authors merge four existing datasets and, through strict deduplication and two automatic labeling techniques, construct PrimeVul (6,968 vulnerable functions, 228,800 benign functions, 140 CWEs), and propose a time-based split, the VD-S metric, and paired evaluation.
- On PrimeVul, 5 open-source code LMs are fine-tuned and evaluated with BigVul as a comparison; F1 does not exceed 21.43%; class weighting and contrastive learning yield limited improvement; GPT-4 CoT pairwise judgment achieves P-C of 12.94%, below the 22.70% of random guessing.
- The authors note that PrimeVul label accuracy does not reach 100%, that the choice of the VD-S threshold r affects the specific values, and that the OpenAI experiments use only default settings; the experiments cover only function-level C/C++ detection, and GPT-3.5 fine-tuning is limited by budget to a single epoch.
- Evaluated models
- CodeT5CodeBERTUnixCoderStarCoder2CodeGen2.5GPT-3.5GPT-4
- Benchmarks
- PrimeVulBigVul
- Metrics
- AccF1VD-SP-CP-VP-BP-R
Researchers construct the PrimeVul vulnerability detection dataset and propose a companion evaluation method, finding that existing benchmarks significantly overestimate the performance of code language models: StarCoder2 (7B) has an F1 of 68.26% on BigVul and only 3.09% on PrimeVul. PrimeVul contains 6,968 vulnerable functions and 228,800 benign functions, covering 140 CWEs; the authors state that the accuracy of its automatic labeling is comparable to that of manually labeled SVEN (SVEN is 94%), and they performed deduplication and splitting by commit time, whereas some old benchmarks have up to 18.9% of test samples duplicated with the training set. The authors also propose the VD-S metric, which measures the model's false negative rate when the false positive rate does not exceed 0.5%, and design paired function evaluation to compare vulnerable functions with their fixed versions. In paired evaluation, the accuracy of GPT-3.5 and GPT-4 using chain-of-thought remains below random guessing, and the authors conclude on this basis that existing methods are not yet sufficient to support practical deployment.
Why it was selectedPrimeVul redoes the test set with stricter labeling, deduplication, and temporal splitting; for the same model, F1 drops from 68.26% to 3.09%, and it can serve as a reference for evaluating code vulnerability detection tools.
Paper analysis
What problem does this paper attempt to solve?
The authors argue that existing vulnerability detection datasets and evaluation methods are unreliable, causing the vulnerability detection capability of code LMs to be overestimated.
Core problem: existing vulnerability detection (VD) datasets are of poor quality and evaluation methods are detached from practice, causing the vulnerability detection capability of code LMs to be systematically overestimated.
- Problem setting: code LMs are already used in real development (e.g., GitHub Copilot), and researchers hope to use them to automatically detect security vulnerabilities in code; the authors argue this requires first rigorously validating their training and evaluation frameworks.
- Shortcomings of existing datasets (the authors' analysis): automatically labeled datasets (BigVul, CrossVul, CVEFixes, DiverseVul) have label accuracy of only 25.0%–60.0% (Table I, 50 vulnerability functions manually reviewed per benchmark); the manually labeled and accurate SVEN has only about 1.6k samples covering 9 CWEs, insufficient in scale and diversity.
- Data leakage: the authors find that exact duplicates and temporal leakage are widespread in benchmarks, with up to 18.9% of test samples leaked from the training set (Table II, CVEFixes).
- Distorted evaluation metrics: the authors argue that accuracy is affected by the base rate problem and that F1 cannot reflect the asymmetric costs of false positives and false negatives; neither can predict real deployment performance.
- Contributions of the paper: propose a new benchmark PrimeVul (strict deduplication, two automatic labeling techniques, temporal split) and new evaluation criteria (VD-S metric, pairwise evaluation), and use it to re-evaluate 7 code LMs.
What related research exists?
The paper is organized around three lines of work: VD datasets, code-LM vulnerability detection methods, and empirical analyses of deep learning vulnerability detection.
Vulnerability detection datasets
- Automatic labeling category: BigVul, ReVeal, CrossVul, CVEfixes, DiverseVul—collect vulnerability-fixing commits from sources such as NVD and label the modified functions as vulnerable. The paper notes that such methods have high label noise (Table I accuracy 25.0%–60.0%).
- Manual labeling category: SVEN (He and Vechev, 2023)—manually labels 1,606 functions with 94.0% accuracy but covers only 9 CWEs; CodeXGLUE/Devign (Zhou et al., 2019), although its commits are manually labeled, the paper's review finds its vulnerability function label accuracy to be only 24.0%.
- Synthetic datasets: SATE IV Juliet, SARD—the paper cites that synthetic data cannot capture the complexity of real vulnerabilities.
code-LM vulnerability detection methods
- Fine-tuning category: CodeBERT, UniXcoder, CodeT5, StarCoder2, CodeGen2.5, etc., fine-tuned with a binary classification head.
- Prompting category: Khare et al. (2023) find that LLMs perform well on synthetic data but poorly on real data; Ullah et al. (2023) try various CoT prompts; other work embeds LLMs in larger frameworks to detect specific vulnerabilities (Use Before Initialization, smart contract vulnerabilities).
Empirical analyses of deep learning vulnerability detection
- Chakraborty et al. (2021), Risse and Böhme (2023), Steenhoek et al. (2023), etc., point out that DLVP models often rely on spurious features rather than vulnerability root causes.
- Chen et al. (2023, DiverseVul)—after large-scale evaluation, conclude that DLVP lacks generalization to unseen projects; this paper adopts its label error taxonomy and the split method of some benchmarks.
- Croft et al. (2023)—report that 80% of labels in a CodeXGLUE sample are correct; the paper states that the discrepancy stems from this paper's stricter labeling criteria (Appendix A).
Baseline and benchmark: RQ1 uses BigVul as the comparison benchmark, directly comparing the performance of the same set of code LMs trained and tested on the two datasets (Table V).
The authors position this paper as a complement to existing empirical analysis work: prior work focuses on why models err, whereas this paper focuses on benchmark construction and evaluation techniques themselves.
How does the paper address this problem?
Build the strictly deduplicated and accurately labeled PrimeVul dataset, and propose three evaluation criteria: temporal split, the VD-S metric, and pairwise evaluation.
Overall approach: first diagnose three types of problems in existing datasets (label noise, data leakage, distorted metrics), then build a new benchmark PrimeVul and design new evaluation criteria accordingly, and finally use them to re-evaluate code LMs.
Data merging and deduplication
- Merge the commits and their modified functions from the four datasets BigVul, CrossVul, CVEfixes, and DiverseVul; exclude Devign/CodeXGLUE because the authors found during labeling that many of its commits are unrelated to security.
- Deduplication process: compute MD5 after stripping formatting characters such as spaces, tabs, and newlines; functions whose hashes are identical before and after the commit are treated as unmodified and discarded; then deduplicate all functions by hash.
- The authors state that this process ensures that vulnerable functions in the training set do not leak into the test set (PrimeVul's duplication rate in Table II is 0.0%).
Two automatic labeling techniques
- PrimeVul-OneFunc: a function is labeled vulnerable when it is the only function modified by a security-related commit.
- PrimeVul-NVDCheck: link the commit to a CVE ID and NVD description, and label it vulnerable if one of two criteria is met: the NVD description explicitly mentions the function name; or the description mentions its file name and it is the only modified function in that file.
- The two sets of vulnerable functions are merged and deduplicated again; their post-commit versions and other unmodified functions in the same commit are labeled benign; commits not meeting the criteria are excluded.
- Labeling accuracy is manually reviewed (50 vulnerability functions sampled per technique, majority vote of three annotators): OneFunc is 86.0%, NVDCheck is 92.0% (Table I).
Dataset scale and split
- A total of 6,968 vulnerable functions and 228,800 benign functions, covering 755 projects, 6,827 commits, and 140 CWEs; the authors state that its number of vulnerable C/C++ functions is 16.7 times that of SVEN.
- Temporal split: sort by commit date, with the oldest 80% as the training set, the middle 10% as the validation set, and the newest 10% as the test set; samples from the same commit do not cross sets (Table III).
New evaluation criteria
- VD-S (Vulnerability Detection Score): FNR@(FPR ≤ r), i.e., measuring the false negative rate after suppressing the false positive rate below threshold r; this paper takes r = 0.5%. The authors argue that it directly reflects the trade-off between false negatives and false positives in real deployment.
- Pairwise evaluation: collect 5,480 pairs of vulnerable functions and their fixed versions (keeping only pairs with at least 80% string overlap), judge the model's predictions for the entire pair as a single entity, and define four outcomes: P-C (both judged correctly), P-V (both misjudged as vulnerable), P-B (both misjudged as benign), P-R (the two labels reversed). The authors argue that this can test whether the model relies only on surface text patterns.
Attempts to improve performance (RQ2, RQ3 methods)
- Class weighting: weight the vulnerable class in the cross-entropy, trying 1, 5, 20, 30, 40 times (the PrimeVul vulnerable-to-benign ratio is about 1:32).
- Contrastive learning: implement the CLR objective (dropout-perturbed representations) following Gao et al. (SimCSE), and its variant CA-CLR (only pulling apart the similarity of samples with different labels), fine-tuned jointly with the classification objective.
- GPT models: GPT-3.5 with two-shot, CoT prompting, and fine-tuning (all vulnerable samples plus three times as many random benign samples, trained for one epoch); GPT-4 with two-shot and CoT prompting (its fine-tuning API was not released at the time).
What experiments did the paper conduct?
On PrimeVul, 5 open-source code LMs are fine-tuned and evaluated and compared with BigVul, then class weighting, contrastive learning, and GPT-3.5/GPT-4 are tested; the authors state that all methods perform poorly.
Experimental Setup
- Models evaluated (Table IV): five open-source models fine-tuned: CodeT5 (60M), CodeBERT (125M), UnixCoder (125M), StarCoder2 (7B), CodeGen2.5 (7B); GPT-3.5 and GPT-4 with two-shot and CoT prompting, with GPT-3.5 additionally fine-tuned.
- Datasets: PrimeVul (Table III: 5,574 vulnerable / 178,853 benign for training, 695 vulnerable / 25,216 benign for testing, paired test set of 564 pairs); RQ1 additionally uses BigVul as a comparison.
- Metrics: Acc, F1, VD-S (FNR @ FPR ≤ 0.5%), paired metrics P-C/P-V/P-B/P-R.
- Training setup: learning rate 2×10⁻⁵ for open-source models; models smaller than 7B trained for 10 epochs, 7B models for 4 epochs; GPT-3.5 fine-tuned for 1 epoch (budget constraint); greedy decoding for OpenAI models.
- Label accuracy evaluation: 50 vulnerable functions randomly sampled per benchmark, manually reviewed by majority vote of three annotators (including one senior security expert).
- The paper does not report the number of experimental repetitions or confidence intervals.
Main Results
According to Table V, results for each model under different training/test combinations (BV=BigVul, PV=PrimeVul):
Swipe horizontally to read the table
Model Train/Test Acc F1 VD-S P-C CodeT5 BV/BV 95.67 64.93 77.30 24.98 CodeT5 BV/PV 97.00 5.82 95.97 0.18 CodeT5 PV/PV 96.67 19.7 89.93 1.06 CodeBERT BV/BV 95.57 62.88 81.77 22.60 CodeBERT PV/PV 96.87 20.86 88.78 1.77 UnixCoder BV/BV 96.46 65.46 62.30 39.60 UnixCoder PV/PV 96.86 21.43 89.21 1.60 StarCoder2 BV/BV 96.20 68.26 69.14 35.23 StarCoder2 BV/PV 97.09 3.09 96.83 0.89 StarCoder2 PV/PV 97.02 18.05 89.64 2.30 CodeGen2.5 BV/BV 96.57 67.30 61.73 40.84 CodeGen2.5 PV/PV 96.65 19.61 91.51 3.01 (Table V also contains the BV/PV combinations for each model and the P-V, P-B, P-R columns, omitted here.)
- The authors state that the F1 of the same model drops substantially from BigVul to PrimeVul, and argue that existing benchmarks overestimate model capability.
- The authors point out that VD-S is uncorrelated with Acc and F1: CodeBERT achieves Acc 95.57% and F1 62.88% on BigVul, yet its VD-S reaches 81.77%; the authors consider such models practically unusable.
- On paired metrics, StarCoder2 (PV/PV) has P-C of only 2.30% and P-B of 88.30%; the authors argue that models rely on textual patterns rather than understanding security semantics.
RQ2: Advanced Training Techniques
- Class weights (Table VI, UnixCoder, PV/PV): F1 is 21.43% at weight 1 and 26.28% at weight 40, but VD-S fluctuates between 88.49% and 90.65% across weights; the authors consider the improvement far from practically usable and rule out class imbalance as the main cause.
- Contrastive learning (Table VII, UnixCoder, PV/PV): with CLR, F1 goes from 21.43% to 21.73%; CA-CLR raises F1 to 24.46% and P-C from 1.60% to 2.30%, with VD-S still around 90%; the authors state that contrastive learning does not yield substantial improvement.
RQ3: Paired Evaluation of GPT Models
- According to Table VIII, on PrimeVul paired functions: GPT-3.5 two-shot has P-C of 5.67%, CoT 6.21%, fine-tuning 1.24%; GPT-4 two-shot 5.14%, CoT 12.94%; random guessing has P-C of 22.70%.
- The authors state that GPT-4 CoT also falls short of random guessing, and most pairs cannot be distinguished; GPT-3.5 fine-tuning is biased by the 1:3 training ratio and performs below the prompting methods.
- The authors argue this points to a fundamental weakness of code LMs in distinguishing subtle vulnerable from benign versions, possibly requiring entirely new methods.
Other Ablations and Analyses
- Label accuracy (Table I, n=50 each): SVEN 94.0%, CodeXGLUE 24.0%, VulnPatchPairs 36.0%, BigVul 25.0%, CrossVul 47.8%, CVEFixes 51.7%, DiverseVul 60.0%.
- Data duplication (Table II): exact overlap between test and training sets: BigVul 12.7%, CVEFixes 18.9%, CodeXGLUE 0.6%, DiverseVul 3.3%, PrimeVul 0.0%.
- Label error breakdown (Appendix Table IX): 58% of CodeXGLUE's erroneous samples are unrelated to security; SVEN's errors are only 6% and all of the unrelated class.
- Negative result: GPT-3.5 fine-tuning (1.24% P-C) is lower than its two-shot prompting (5.67%), which the authors explain as bias from the 1:3 training data ratio.
What are some points that can be further explored?
The authors list three directions for improvement and three validity threats; the experiments cover 7 models and function-level C/C++ detection.
Limitations noted by the authors and future directions
- Introduce broader context (Section VI Discussion-a): the authors argue that function-level judgment may itself be infeasible and suggest reframing the problem to give models access to broader context; PrimeVul retains commit metadata to support extracting relevant context.
- Enhance security awareness (Section VI Discussion-b): suggest exploring letting code LMs learn security concepts, or building hybrid systems combining LMs with traditional security analysis/program analysis tools.
- Teach models to reason (Section VI Discussion-c): the authors argue that binary classification is too simple and suggest decomposing VD into sub-problems for step-by-step reasoning; they state that the slight progress of CoT in Table VIII offers some promise in this direction.
- Label accuracy does not reach 100% (Section VI Threats to validity): PrimeVul still has a small number of mislabels; the authors argue that given the small proportion, the conclusions still hold.
- VD-S parameter r (Section VI Threats to validity): the acceptable r varies by scenario and changes the specific VD-S values; the authors expect the overall conclusions to be unchanged.
- OpenAI experimental settings (Section VI Threats to validity): only results under default settings are reported; the authors do not expect tuning to change the conclusions.
Scope of experiments
- 7 models are tested in total: 5 open-source models (60M–7B) fine-tuned, GPT-3.5 and GPT-4 via prompting, with GPT-3.5 additionally fine-tuned for one epoch (Section V-A).
- The evaluation language is C/C++ function-level vulnerability detection; PrimeVul covers 140 CWEs and 755 projects (Section III-B).
- GPT models are evaluated only on the pairwise function subset, not on the full test set; GPT-4 is not fine-tuned (its fine-tuning API was not released at the time) (Section V-D).
- Label accuracy is manually reviewed on 50 vulnerability functions per benchmark; the paper does not report the number of repetitions for the open-source model experiments.
- Improvement attempts are limited to class weighting, CLR/CA-CLR contrastive learning, and GPT prompting/fine-tuning (Section V-C, V-D).
Summarize the main content of the paper
The authors build the PrimeVul benchmark and re-evaluate code LMs; the authors state that existing models are far from usable levels under realistic settings.
A vulnerability detection evaluation/benchmark paper: the authors first diagnose problems in existing VD datasets and evaluation methods, then propose a new benchmark PrimeVul and new evaluation criteria, and use them to re-measure the true capability of code LMs.
- Problem: the authors' analysis finds that existing benchmarks have low label accuracy (automatic labeling category 25.0%–60.0%, Table I), data duplication causing leakage (up to 18.9%, Table II), and that accuracy and F1 cannot reflect the false-positive/false-negative trade-off in real deployment.
- Method: merge four datasets, strictly deduplicate, and build PrimeVul using two automatic labeling techniques, OneFunc and NVDCheck (6,968 vulnerable/228,800 benign functions, 140 CWEs, labeling accuracy 86.0%/92.0%), split training/test sets by commit time, and propose the VD-S metric (FNR @ FPR ≤ 0.5%) and a pairwise evaluation of 5,480 pairs.
- Main results: StarCoder2 has an F1 of 68.26% on BigVul and only 3.09% on PrimeVul (Table V); after fine-tuning on PrimeVul, the five open-source models reach a maximum F1 of 21.43%, with VD-S all above 88%.
- Improvement attempts all perform poorly: class weighting raises UnixCoder's F1 from 21.43% to a maximum of 26.28% but VD-S remains around 90%; CLR/CA-CLR contrastive learning yields limited improvement (Table VI, VII).
- GPT models: GPT-4 CoT achieves P-C of 12.94% on pairwise evaluation, below the 22.70% of random guessing; GPT-3.5 after fine-tuning achieves P-C of only 1.24% (Table VIII).
- Authors' conclusion: existing code LMs are still far from practical deployment for vulnerability detection and may require fundamentally new methods; the authors suggest introducing broader context, enhancing model security awareness, and decomposing VD into reason-able sub-problems.