Source-linked AI summary
ChatGPT for Vulnerability Detection, Classification, and Repair: How Far Are We?
Michael Fu, Chakkrit Tantithamthavorn, Van Nguyen, Trung Le
TL;DR
The paper asks how well ChatGPT performs across vulnerability detection, classification, severity estimation, and repair, areas where prior work had not comprehensively evaluated the full workflow. It compares prompted ChatGPT with vulnerability-focused models and finds that ChatGPT fares worse across the tasks.
Problem
Although ChatGPT showed competence in code-related tasks, comprehensive evidence on its performance across the vulnerability workflow was lacking.
Source: §I · p. 1Method
The authors evaluate prompted gpt-3.5-turbo and gpt-4 on four vulnerability tasks and compare them with fine-tuned vulnerability models using datasets of over 190,000 C/C++ functions.
Source: §I · p. 1Results
Takeaways & Limitations
The findings highlight the need for security expertise and fine-tuning for vulnerability prediction despite large model size.
Source: (RQ1) How accurate is ChatGPT for… · p. 4
Abstract
from arXiv · showhide
Large language models (LLMs) like ChatGPT (i.e., gpt-3.5-turbo and gpt-4) exhibited remarkable advancement in a range of software engineering tasks associated with source code such as code review and code generation. In this paper, we undertake a comprehensive study by instructing ChatGPT for four prevalent vulnerability tasks: function and line-level vulnerability prediction, vulnerability classification, severity estimation, and vulnerability repair. We compare ChatGPT with state-of-the-art language models designed for software vulnerability purposes. Through an empirical assessment employing extensive real-world datasets featuring over 190,000 C/C++ functions, we found that ChatGPT achieves limited performance, trailing behind other language models in vulnerability contexts by a significant margin. The experimental outcomes highlight the challenging nature of vulnerability prediction tasks, requiring domain-specific expertise. Despite ChatGPT's substantial model scale, exceeding that of source code-pre-trained language models (e.g., CodeBERT) by a factor of 14,000, the process of fine-tuning remains imperative for ChatGPT to generalize for vulnerability prediction tasks. We publish the studied dataset, experimental prompts for ChatGPT, and experimental results at https://github.com/awsm-research/ChatGPT4Vul.
I. INTRODUCTION
The paper evaluates prompted ChatGPT across four vulnerability tasks against models fine-tuned for software vulnerability work. Across the tasks, ChatGPT trails those baselines, despite its much larger model scale.
I. INTRODUCTION
- The study addresses the lack of comprehensive evaluation across the vulnerability workflow, from detecting vulnerabilities and explaining types to estimating severity and suggesting repairs.Source: §I · p. 1
- Because ChatGPT’s parameters are proprietary, the study prompts it rather than fine-tuning it, comparing two ChatGPT versions with vulnerability-focused baselines.Source: §I · p. 1
- Across the four vulnerability tasks, ChatGPT produced the least favorable outcomes compared with fine-tuned vulnerability models.The evaluation covered over 190,000 C/C++ functions.Source: §I · pp. 1–2
- ChatGPT’s function and line-level prediction results were lowest among the baselines: F1-measure of 10% and 29%, and top-10 accuracy of 25% and 65%.Source: §I · p. 1
- For vulnerability classification, ChatGPT achieved 13% and 20% accuracy, 45%-52% below the best baseline.Source: §I · p. 1
- Reported MSE values were 5.4 and 5.85, compared with 1.8 to 1.86 for other baselines; separately, ChatGPT generated no correct repair patches, while baselines repaired 7%-30% of vulnerable functions.Source: §I · p. 2
II. RELATED WORK
Prior work has examined ChatGPT on selected vulnerability and repair tasks, while this paper introduces four vulnerability task formulations and their prompt designs.
II. RELATED WORK
- Earlier studies examined ChatGPT vulnerability prediction and classification on 120 samples, prompt design for prediction, smart-contract vulnerability correction, and general bug repair.The cited program-repair evaluation did not include the two most advanced ChatGPT versions.Source: §II · p. 2
III. PROBLEM STATEMENT & PROMPT DESIGN
- The next section formulates vulnerability prediction, classification, severity estimation, and automated repair, then describes prompts for each task.Source: §III · p. 2
A. Prompt ChatGPT for Software Vulnerability Prediction
The prediction prompts frame function vulnerability detection as binary classification and line-level localization as ranking vulnerable statements.
A. Prompt ChatGPT for Software Vulnerability Prediction
- Function-level vulnerability prediction is a binary classification task; localization ranks vulnerable statements to reduce security analysts’ manual analysis workload.Source: A. Prompt ChatGPT for Software… · p. 2
- The initial prompt requests a function-level prediction, and a subsequent prompt asks ChatGPT to rank the top 10 vulnerable-prone statements in a function identified as vulnerable.Source: A. Prompt ChatGPT for Software… · p. 2, Figure 1 · p. 2
- The expected localization output pairs each predicted statement with its line number.Source: A. Prompt ChatGPT for Software… · p. 2
B. Prompt ChatGPT for Software Vulnerability Classification
The prompts frame vulnerability classification as identifying a CWE-ID for a vulnerable function and severity estimation as predicting its CVSS score.
B. Prompt ChatGPT for Software Vulnerability Classification
- Vulnerability classification is a multiclass task that identifies a CWE-ID for an input vulnerable function.Source: B. Prompt ChatGPT for Software… · p. 2
- The classification prompt supplies potential CWE-IDs, limiting the label choices for comparison with fine-tuned models.Source: B. Prompt ChatGPT for Software… · p. 2, Figure 2 · p. 2
- The classification prompt tells ChatGPT the function is vulnerable and asks it to identify the corresponding CWE-ID.Source: B. Prompt ChatGPT for Software… · p. 2
C. Prompt ChatGPT for Vulnerability Severity Estimation
- Severity estimation is formulated as regression, predicting a continuous value from an input vulnerable function.Source: C. Prompt ChatGPT for Vulnerability… · p. 2
- The study uses CVSS version 3.1, whose severity scores range from 0 to 10.Source: C. Prompt ChatGPT for Vulnerability… · p. 2
- The severity prompt identifies the function as vulnerable and specifies the CVSS version and output range for the estimate.Source: C. Prompt ChatGPT for Vulnerability… · p. 2, Figure 3 · p. 3
D. Prompt ChatGPT for Automated Vulnerability Repair
The repair task is framed as generating a patch for an input vulnerable function. Prompts include repair examples because the requested outputs are patches rather than complete repaired programs.
D. Prompt ChatGPT for Automated Vulnerability Repair
- Repair is formulated as sequence-to-sequence generation: the model receives a vulnerable function and generates a corresponding repair patch.The prompt requests patches rather than complete repaired programs.Source: D. Prompt ChatGPT for Automated… · p. 3
- Each prompt provides three repair examples to help ChatGPT understand the patch-generation task.The examples use templates for the requested repair patches.Source: D. Prompt ChatGPT for Automated… · p. 3
- The prompt then asks ChatGPT to create repair patches for vulnerable functions using the templates in those examples.Source: D. Prompt ChatGPT for Automated… · p. 3
- The repair prompt’s examples reflect the specified output format: repair patches, not full repaired programs.Source: D. Prompt ChatGPT for Automated… · p. 3
- Figure 4 presents an example prompt for automated vulnerability repair.Source: Figure 4 · p. 3
IV. EXPERIMENTAL DESIGN AND RESULTS
- The experimental section introduces datasets, baseline-model settings and hardware, then presents each research question’s approach and results.Source: §IV · p. 3
A. Experimental Datasets
Big-Vul supports vulnerability prediction, classification, and severity estimation, while repair uses preprocessed Big-Vul and CVEFixes data. Baselines were reproduced with their original settings, and ChatGPT was prompted through a paid API.
A. Experimental Datasets
- Big-Vul contains 188k C/C++ functions from 348 projects, including 3,754 vulnerabilities across 91 types, with a 1:20 vulnerable-to-benign ratio.Each vulnerable function has a CWE-ID and CVSS severity score; the data is split 80%/10%/10% for training, validation, and testing.Source: A. Experimental Datasets · p. 3
- Repair uses 5.5k vulnerable-function and repair-patch pairs from preprocessed Big-Vul and CVEFixes, split 70%/10%/20% for training, validation, and testing.Source: A. Experimental Datasets · p. 3
B. Parameter Settings and Execution Environment
- Baseline methods were reproduced with their authors’ parameter settings, and ChatGPT prompting used paid OpenAI API access.Experiments ran on Linux with an AMD Ryzen 9 5950X, 64 GB RAM, and an NVIDIA RTX 3090 GPU.Source: B. Parameter Settings and Execution… · p. 3
C. Experimental Results
On function- and line-level vulnerability prediction, ChatGPT trails fine-tuned baselines, including on the reported F1-measure and top-10 accuracy results. The findings point to a need for domain-specific knowledge and fine-tuning.
(RQ1) How accurate is ChatGPT for function and line-level vulnerability predictions?
- AIBugHunter achieves 94% F1-measure and 99% top-10 accuracy, versus gpt-4’s 29% and 65%; ChatGPT reports 10% F1-measure and 25% top-10 accuracy.Source: (RQ1) How accurate is ChatGPT for… · p. 3, Figure 5 · p. 4
- Function-level performance is evaluated with F1-measure, precision, and recall; line-level performance uses top-10 accuracy.Top-10 accuracy measures the share of vulnerable functions with at least one actual vulnerable line in the model’s top-10 ranking.Source: (RQ1) How accurate is ChatGPT for… · p. 3
- The results indicate that vulnerability prediction requires learning domain-specific knowledge, such as vulnerability patterns, and that fine-tuning remains necessary despite large model size.Source: (RQ1) How accurate is ChatGPT for… · p. 4
(RQ2) How accurate is ChatGPT for vulnerability types classification?
ChatGPT’s CWE-ID classification accuracy is limited compared with fine-tuned language-model baselines. The authors attribute the gap to the need to learn mappings from vulnerability patterns to CWE-IDs.
(RQ2) How accurate is ChatGPT for vulnerability types classification?
- Fine-tuned baselines achieve 62%–65% multiclass accuracy, compared with 13%–20% for gpt-3.5-turbo and gpt-4 on CWE-ID classification.Source: (RQ2) How accurate is ChatGPT for… · p. 4
- The classification task identifies CWE-IDs for vulnerable functions and is evaluated using multiclass accuracy.Source: (RQ2) How accurate is ChatGPT for… · p. 4
- The authors say accurate classification requires learning to map patterns such as buffer overflows to CWE-IDs, which ChatGPT had not adequately acquired during pretraining.They conclude that fine-tuning is still required to boost performance.Source: (RQ2) How accurate is ChatGPT for… · p. 4
(RQ3) How accurate is ChatGPT for vulnerability severity estimation?
ChatGPT performed poorly on severity estimation and automated vulnerability repair relative to fine-tuned baselines. Repair was especially difficult: ChatGPT generated no correct patches, while baselines repaired some vulnerable functions.
(RQ3) How accurate is ChatGPT for vulnerability severity estimation?
- ChatGPT’s CVSS estimation yielded MSE 5.4 and MAE 1.84; gpt-3.5-turbo and gpt-4 had MSE 5.4 and 5.85, versus 1.8–1.86 for fine-tuned baselines.The authors report that accurate severity estimation demands software security expertise that ChatGPT had not acquired during pretraining.Source: (RQ3) How accurate is ChatGPT for… · p. 4
(RQ4) How accurate is ChatGPT for automated vulnerability repair?
- Repair scoring uses %PP only for patches identical to ground truth, with BLEU and METEOR also measuring patch similarity.The evaluation returns one repair candidate for fine-tuned models using greedy decoding.Source: (RQ4) How accurate is ChatGPT for… · pp. 4–5
- ChatGPT generated no correct repair patches, whereas fine-tuned baselines correctly repaired 7%–30% of testing functions.BLEU and METEOR also indicated that baseline patches were closer to the true patches.Source: (RQ4) How accurate is ChatGPT for… · p. 5, Figure 8 · p. 5
V. CONCLUSION
The study evaluates prompted ChatGPT on four vulnerability tasks using over 190,000 real-world C/C++ functions. ChatGPT had the least favorable outcomes across tasks, and the authors conclude that additional fine-tuning is needed for effective generalization.
V. CONCLUSION
- Across four vulnerability tasks and over 190,000 real-world C/C++ functions, ChatGPT had the least favorable outcomes, particularly struggling to generate accurate repair patches.The evaluated tasks were locating vulnerabilities, identifying vulnerability types, estimating severity scores, and suggesting repair patches.Source: §V · p. 5
- The authors conclude that vulnerability prediction tasks require security expertise that ChatGPT did not acquire during extensive pretraining.Source: §V · p. 5
- The authors identify an additional fine-tuning round as pivotal for ChatGPT to generalize effectively to software vulnerability tasks.Source: §V · p. 5