NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Prompt-Enhanced Software Vulnerability Detection Using ChatGPT

Chenyuan Zhang, Hao Liu, Jiutian Zeng, Kejing Yang, Yuhong Li, Hui Li

TL;DR

Researchers from Xiamen University and Alibaba have developed a "prompt-enhanced" framework to turn ChatGPT into a more effective software vulnerability detector. By moving beyond simple questions and providing the model with structural code information (like data flows and API sequences) and specialized "roles," they significantly improved detection accuracy compared to both basic prompts and traditional deep learning baselines.

What Problem Does This Paper Address?

Software vulnerabilities are a multi-billion dollar headache, but finding them automatically is notoriously difficult. Traditional methods usually fall into two camps: rule-based systems (which are rigid and labor-intensive) and deep learning models (which are powerful but often language-specific and require massive labeled datasets).

While Large Language Models (LLMs) like ChatGPT have shown "stunning intelligence" in coding, early attempts to use them for security were underwhelming. The gap wasn't necessarily in the model's intelligence, but in the prompts. Simple questions like "Is this code buggy?" don't provide enough context for an LLM to navigate complex program logic. This paper explores how to bridge that gap using sophisticated prompt engineering.

Methods

The authors designed a series of increasingly complex prompt strategies to see what "clicks" for the model:

  1. Role-Based Prompting: Instead of a generic query, they told the model: "I want you to act as a vulnerability detection system."
  2. Auxiliary Information: Since LLMs process text linearly, they struggle to "see" the non-linear structure of code. The researchers extracted API call sequences and Data Flow Graphs (DFG) and converted them into natural language descriptions (e.g., "The data value of variable X at token 5 comes from variable Y...") to include in the prompt.
  3. Chain-of-Thought (CoT): They used a multi-round dialogue approach. First, they asked ChatGPT to describe the intent of the code. Only after the model "understood" what the code was supposed to do did they ask it to find vulnerabilities.
  4. Reverse-Questioning: To check for bias, they asked if code was "correct" instead of "buggy" to ensure the model wasn't just reacting to the word "bug."

Datasets

The study evaluated ChatGPT on two primary datasets:

  • Java Dataset: 2,088 functions sourced from the Software Assurance Reference Dataset (SARD).
  • C/C++ Dataset: 1,937 functions sourced from the National Vulnerability Database (NVD).
  • Baselines: They compared results against CFGNN (a graph neural network) and Bugram (an n-gram based detector).

Key Insights and Ideas

  • Context is King: ChatGPT often misses vulnerabilities because it doesn't "understand" the data flow. Explicitly telling the model where variables come from (the DFG) helps it "see" the logic it otherwise overlooks.
  • The "Buggy" Bias: The researchers found that ChatGPT is surprisingly susceptible to suggestion. If the prompt includes the word "buggy," the model is more likely to label code as vulnerable. Using a "reverse prompt" (asking if code is "correct") revealed this hidden bias.
  • Intent Matters: Asking the model to summarize the code's purpose before looking for bugs (Chain-of-Thought) significantly improved performance in C/C++, suggesting that "thinking out loud" helps the model align its internal logic.
  • Language Sensitivity: Interestingly, different prompts worked better for different languages. API call sequences were highly effective for Java but less so for C/C++, highlighting that "one size fits all" prompting doesn't exist in software security.

Key Results

  • Superiority over Baselines: ChatGPT with even basic prompts outperformed traditional baselines like CFGNN and Bugram. In Java, ChatGPT's accuracy was 58% to 64% higher than the baselines.
  • The Power of Roles: Simply assigning ChatGPT a "task role" (vulnerability detection system) boosted accuracy by about 5% on the Java dataset.
  • Information Boost: Incorporating API call sequences into the prompt led to an accuracy of 0.747 on Java, an 8% improvement over the role-based basic prompt.
  • Understanding vs. Detection: While ChatGPT is great at identifying that a bug exists, it only provided a "comprehensive" explanation for about 52-64% of the cases it correctly identified.

Limitations and Future Work

  • Input Length: ChatGPT has a "context window" limit. The authors had to cap code snippets at 700 tokens, meaning very large functions or multi-file vulnerabilities remain out of reach for this method.
  • Deep Logic Gaps: The model still struggles with vulnerabilities that require deep domain knowledge or human-like intervention, such as "Use of a One-Way Hash without a Salt" (CWE-759). It can see the code, but it doesn't always know what's missing.
  • Version Sensitivity: The study was performed on GPT-4. As OpenAI updates its models, the effectiveness of specific prompts may change (the "brittleness" of prompt engineering).
  • Future Direction: The authors suggest exploring how to handle multi-file context and more complex vulnerability types that require understanding the entire project architecture.

Summary updated

BibTeX
@inproceedings{zhang2024prompt,
  author = {Chenyuan Zhang and Hao Liu and Jiutian Zeng and Kejing Yang and Yuhong Li and Hui Li},
  title = {{Prompt-Enhanced Software Vulnerability Detection Using ChatGPT}},
  booktitle = {ICSE Companion},
  year = {2024},
  doi = {10.1145/3639478.3643065},
}
Figure