LLMs Cannot Reliably Identify and Reason About Security Vulnerabilities (Yet?): A Comprehensive Evaluation, Framework, and Benchmarks

Saad Ullah, Mingji Han, Saurabh Pujar, Hammond Pearce, Ayse K. Coskun, Gianluca Stringhini

TL;DR

While Large Language Models (LLMs) are often touted as the future of automated security, this paper introduces SecLLMHolmes—a rigorous evaluation framework—to show they aren't ready for prime time. The study reveals that even top-tier models like GPT-4 and PaLM2 are surprisingly fragile, frequently providing "right answers for the wrong reasons" and failing significantly when faced with trivial code changes like renaming a variable or adding whitespace.

What Problem Does This Paper Address?

The security community is eager to use LLMs for vulnerability detection and repair, but we lack a standardized way to measure if these models actually understand security or are just performing sophisticated pattern matching.

Most existing benchmarks suffer from two major flaws:

  1. Data Contamination: Because LLMs are trained on massive public code repositories, they may have already "seen" the vulnerabilities in the benchmark during training, leading to inflated performance scores (memorization vs. reasoning).
  2. Surface-Level Evaluation: Many tests only look at binary "Yes/No" answers. They don't check if the model’s reasoning is sound or if the model is robust against minor, non-functional changes to the code.

The authors address this by creating a fully automated framework that tests models across eight dimensions, including determinism, faithful reasoning, and robustness to code augmentations.

Methods

The authors developed SecLLMHolmes, a framework designed to put LLMs through a "security gauntlet." Key methodological highlights include:

  • Multi-Dimensional Prompting: They tested 17 different prompting techniques, ranging from simple zero-shot questions to complex "Role-Oriented" prompts (e.g., "Act as a security expert") and "Chain-of-Thought" reasoning.
  • The GPT-4 Evaluator: To solve the problem of manually grading thousands of textual explanations, they used GPT-4 as an automated "Evaluator." They verified this evaluator against human experts, finding it highly accurate at determining if a model's reasoning matched the ground truth.
  • Robustness Testing: They applied "Trivial Augmentations" (adding whitespace, changing comments) and "Non-Trivial Augmentations" (renaming variables to "vulnerable_func" or adding safe library calls) to see if the models could be easily "confused."

Datasets

The study utilizes a diverse set of 228 code scenarios:

  • Hand-Crafted CWE Scenarios: 48 scenarios covering the 8 most critical types of vulnerabilities (CWEs) in C and Python, ranging from "Easy" to "Hard" difficulty.
  • Real-World CVEs: 30 scenarios derived from 15 real-world vulnerabilities published in 2023. This is crucial because these vulnerabilities were released after the training cut-off for most models, ensuring the models had to reason through them rather than recall them.
  • Augmented Scenarios: 150 variations of the hand-crafted code designed to test robustness.

Key Insights and Ideas

  • The "Right Answer, Wrong Reason" Trap: Models often correctly identify a vulnerability but provide a completely nonsensical explanation for why it exists. This "unfaithful reasoning" makes them dangerous for human developers who might trust a correct-looking verdict based on a hallucinated logic.
  • The "Strcat" Bias: LLMs show a strong bias toward specific "scary" library functions. For example, simply adding a safely used strcat function (which is famously associated with buffer overflows) often tricked models into flagging perfectly safe code as vulnerable.
  • Fragility to Noise: Trivial changes like adding extra whitespaces or newlines—which have zero effect on code execution—caused models to change their verdicts. This suggests the models are over-relying on textual patterns rather than the underlying logic of the code.
  • Non-Determinism: Even with the "temperature" set to 0 (the most deterministic setting), some models gave different answers to the exact same prompt when run multiple times.

Key Results

  • Performance Drop: Even the most advanced models, PaLM2 and GPT-4, saw their accuracy drop by 26% and 17% respectively just by changing function/variable names or adding safe library functions.
  • High False Positive Rates: All models struggled with "patched" code, often flagging fixed, safe code as still being vulnerable.
  • Prompting Matters: "Role-Oriented" prompts (telling the model it is a security expert) generally improved reasoning scores, but "Few-Shot" prompting (providing examples) failed to help models generalize to complex, real-world projects.
  • GPT-4 is the Leader (but still flawed): GPT-4 performed the best overall, reaching up to 89.5% accuracy on hand-crafted scenarios, but its performance plummeted when faced with real-world, multi-function code flows.

Limitations and Future Work

The authors acknowledge several areas for growth:

  • Language Scope: The study was limited to C and Python. Future benchmarks should include more languages like Java, Go, or Rust.
  • Dataset Size: While 228 scenarios is a deep dive, the real-world CVE set (15 vulnerabilities) is relatively small. Expanding this to hundreds of post-2023 CVEs would provide even stronger evidence.
  • Complex Data Flows: Current LLMs struggle significantly with vulnerabilities that span multiple functions or files. Future work needs to focus on how models handle these complex inter-procedural dependencies.
  • Framework as a Benchmark: The authors hope SecLLMHolmes will serve as a standard benchmark for future model releases to track progress in actual security reasoning.

Summary updated

BibTeX
@inproceedings{ullah2023llms,
  author = {Saad Ullah and Mingji Han and Saurabh Pujar and Hammond Pearce and Ayse K. Coskun and Gianluca Stringhini},
  title = {{LLMs Cannot Reliably Identify and Reason About Security Vulnerabilities (Yet?): A Comprehensive Evaluation, Framework, and Benchmarks}},
  booktitle = {SP},
  year = {2023},
}
Figure