Skip to main content
QUICK REVIEW

[Paper Review] ChatGPT for Vulnerability Detection, Classification, and Repair: How Far Are We?

Michael C. Fu, Chakkrit Tantithamthavorn|arXiv (Cornell University)|Oct 15, 2023
Software Engineering ResearchComputer Science6 citations
TL;DR

This study evaluates ChatGPT (gpt-3.5-turbo and gpt-4) for four software vulnerability tasks—detection, classification, severity estimation, and repair—using over 190,000 C/C++ functions. Despite its massive scale, ChatGPT underperforms significantly compared to fine-tuned code-specific models, highlighting the necessity of domain-specific fine-tuning for effective vulnerability prediction and repair.

ABSTRACT

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.

Motivation & Objective

  • To evaluate the effectiveness of prompting large language models like ChatGPT for end-to-end software vulnerability tasks.
  • To compare ChatGPT’s performance against state-of-the-art, fine-tuned language models specifically designed for software vulnerability detection and repair.
  • To investigate whether the massive parameter count of ChatGPT (up to 1.7 trillion) enables superior generalization for vulnerability tasks without fine-tuning.
  • To assess the feasibility of using off-the-shelf LLMs like ChatGPT for automated vulnerability detection, classification, severity estimation, and patch generation in real-world software systems.
  • To determine whether domain-specific fine-tuning is essential for LLMs to achieve practical performance in cybersecurity-related software engineering tasks.

Proposed method

  • Employed two versions of ChatGPT—gpt-3.5-turbo and gpt-4—using prompt engineering without parameter fine-tuning.
  • Used two real-world datasets: Big-Vul (190,000 C/C++ functions) and CVEFixes for evaluation across four vulnerability tasks.
  • Designed task-specific prompts for function/line-level vulnerability prediction, vulnerability type classification (CWE-ID), severity estimation (CVSS scores), and automated patch repair.
  • Compared ChatGPT’s performance against four fine-tuned baselines: AIBugHunter, CodeBERT, GraphCodeBERT, and VulExplainer.
  • Evaluated results using standard metrics: F1-score, top-10 accuracy, multiclass accuracy, Mean Squared Error (MSE), Mean Absolute Error (MAE), and %Perfect Prediction (%PP) for repair.
  • Used greedy decoding to ensure fair comparison and included BLEU and METEOR scores to assess patch similarity to ground truth.

Experimental results

Research questions

  • RQ1How accurate is ChatGPT for function and line-level vulnerability prediction?
  • RQ2How accurate is ChatGPT for vulnerability type classification (CWE-ID)?
  • RQ3How accurate is ChatGPT for vulnerability severity estimation (CVSS score)?
  • RQ4How accurate is ChatGPT for automated vulnerability repair (patch generation)?

Key findings

  • ChatGPT achieved an F1-measure of 10% and 29% for function-level and line-level vulnerability prediction, respectively, with top-10 accuracy of 25% and 65%, significantly lower than baseline models.
  • For vulnerability classification, ChatGPT achieved only 13% and 20% multiclass accuracy, which is 45%-52% lower than the best-performing baseline models.
  • ChatGPT’s severity estimation had the highest Mean Squared Error (MSE) of 5.4 and 5.85 for gpt-3.5-turbo and gpt-4, respectively, compared to 1.8–1.86 for fine-tuned baselines.
  • ChatGPT failed to generate any correct repair patches, achieving 0% %Perfect Prediction (PP), while baseline models repaired 7% to 30% of vulnerable functions.
  • BLEU and METEOR scores confirmed that repair patches generated by fine-tuned models were significantly closer to ground truth than those from ChatGPT.
  • The results indicate that despite its 14,000x larger parameter count than CodeBERT, ChatGPT lacks the domain-specific security expertise needed for vulnerability tasks without fine-tuning.

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.