Evaluation of ChatGPT Model for Vulnerability Detection

Anton Cheshkov, Pavel Zadorozhny, Rodion LevichevarXiv 2023 · DOI

Abstract

As Large Language Models (LLMs) like ChatGPT become integral to software development, their potential as automated security auditors is under scrutiny. This technical report evaluates the performance of text-davinci-003 (GPT-3) and gpt-3.5-turbo (ChatGPT) in identifying Java vulnerabilities. Through zero-shot prompting on real-world datasets, the study reveals that while these models possess strong linguistic capabilities, they struggle significantly with the logical nuances of security, often performing only marginally better than random chance.

Introduction

The rapid adoption of LLMs has prompted questions regarding their ability to serve as automated security auditors. While models like GPT-4 can solve complex coding challenges, their ability to identify subtle security flaws remains unproven. This research investigates whether ChatGPT and GPT-3 can effectively perform vulnerability detection, specifically identifying Common Weakness Enumeration (CWE) patterns and distinguishing between vulnerable functions and their patched counterparts.

Methodology

The researchers employed a zero-shot prompting approach using the OpenAI API, testing models without additional fine-tuning.

Models and Tasks

The study compared text-davinci-003 and gpt-3.5-turbo across two primary tasks:

  1. Binary Classification: Determining if a function contains a vulnerability (Yes/No).
  2. Multi-label Classification: Identifying specific CWE types from the top five most frequent patterns in the dataset.

Experimental Setup

Prompt variations were tested to ensure results were not dependent on specific wording. For multi-label tasks, JSON-formatted responses were requested for reliable parsing. The "temperature" parameter was set to 0 to ensure deterministic outputs. Results were compared against a "dummy classifier" baseline that guessed based on dataset distribution.

Dataset

A custom dataset of Java files was curated from open GitHub repositories, focusing on real-world commit histories where vulnerabilities were explicitly patched. The dataset included a binary set of 308 samples (pairs of vulnerable and patched functions) and a multi-label set of 120 samples focusing on five specific CWE types (CWE-20, CWE-200, CWE-502, CWE-611, and CWE-79).

Key Results

Binary Classification

Both models demonstrated a significant "Yes-Man" bias, characterized by high recall but very low precision. The models were overly eager to flag code as vulnerable, leading to numerous false positives.

Binary Classification Performance

As shown in the table above, both models achieved an Area Under the Curve (AUC) of 0.51. Given that a random guess yields an AUC of 0.50, the models provided virtually no statistical advantage over a baseline classifier.

Multi-label Classification

In multi-label tasks, the models achieved approximately 38% accuracy. However, this performance dropped significantly when "Negative" (non-vulnerable) samples were excluded, suggesting the models struggle to categorize specific flaw types even when a vulnerability is detected.

Multi-label Classification Results

Discussion and Insights

  • The Patch Anomaly: ChatGPT was nearly twice as accurate at identifying fixed functions than vulnerable ones, suggesting it recognizes "clean" code patterns more effectively than "dirty" vulnerability patterns.
  • Logic vs. Syntax: While LLMs understand code syntax, they struggle with the high-dimensional logic required for security. They can explain a loop's function but may fail to see how it creates a buffer overflow in context.
  • Prompt Invariance: Performance did not improve significantly with different prompt wordings, indicating that the limitation lies in the model's underlying reasoning rather than the instructions provided.

Limitations and Future Work

The study's findings are tempered by a relatively small sample size and the lack of exploration into Chain-of-Thought (CoT) prompting, which has been shown to boost reasoning performance. Future research should evaluate more advanced models like GPT-4 and incorporate more diverse datasets to mitigate human bias in ground truth selection.

Conclusion

While ChatGPT is a powerful tool for code generation and explanation, it is currently an unreliable sentry for security auditing. Its tendency toward false positives and near-random performance in binary detection suggests that human security auditors remain indispensable.

Summary updated

Abstract

In this technical report, we evaluated the performance of the ChatGPT and GPT-3 models for the task of vulnerability detection in code. Our evaluation was conducted on our real-world dataset, using binary and multi-label classification tasks on CWE vulnerabilities. We decided to evaluate the model because it has shown good performance on other code-based tasks, such as solving programming challenges and understanding code at a high level. However, we found that the ChatGPT model performed no better than a dummy classifier for both binary and multi-label classification tasks for code vulnerability detection.

Empirical ResultsBrowse all benchmarks →

BenchmarkMethodMetricScoreProtocol / Evidence
Multi-label classification (five CWE types)Dummy ClassifierAccuracy0.218samples=60 · cwe_types=CWE-20, CWE-200, CWE-502, CWE-611, CWE-79
Source quote
L232: accuracy │ 0.218 │ 60
Multi-label classification (five CWE types)Dummy ClassifierMacro-average F1-score0.196samples=60 · cwe_types=CWE-20, CWE-200, CWE-502, CWE-611, CWE-79
Source quote
L233: macro avg │ 0.199 │ 0.199 │ 0.196 │ 60
Multi-label classification (five CWE types)Dummy ClassifierWeighted-average F1-score0.214samples=60 · cwe_types=CWE-20, CWE-200, CWE-502, CWE-611, CWE-79
Source quote
L234: weighted avg │ 0.218 │ 0.218 │ 0.214 │ 60
BibTeX
@misc{cheshkov2023evaluation,
  author = {Anton Cheshkov and Pavel Zadorozhny and Rodion Levichev},
  title = {{Evaluation of ChatGPT Model for Vulnerability Detection}},
  year = {2023},
  eprint = {2304.07232},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2304.07232},
}
Figure