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:
- Binary Classification: Determining if a function contains a vulnerability (Yes/No).
- 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.
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.
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