Comparison of Static Application Security Testing Tools and Large Language Models for Repo-level Vulnerability Detection

Xin Zhou, Duc-Manh Tran, Thanh Le-Cong, Ting Zhang, Ivana Clairine Irsan, Joshua Sumarlin, Bach Le, David LoarXiv 2024 · DOI

Introduction

In automated security auditing, a significant gap exists between industrial practice and academic research. While industry relies on Static Application Security Testing (SAST) tools to scan entire repositories, the research community has largely focused on Large Language Models (LLMs) for "function-level" detection. Function-level detection assumes the vulnerable function is already known, which is unrealistic for real-world applications. This study presents the first comprehensive head-to-head comparison between 15 traditional SAST tools and 12 LLMs for detecting vulnerabilities at the repository level.

The Repo-Level Challenge

The primary difficulty in repository-level detection is the "needle-in-a-haystack" problem. Unlike function-level benchmarks that provide a model with a specific snippet, repo-level detection requires scanning millions of lines of code across thousands of files without prior knowledge of where a vulnerability might reside.

Comparison of Function-level vs. Repo-level Vulnerability Detection workflows.

As illustrated in the figure above, traditional function-level detection often relies on "future" information—specifically, the files changed by a fix—to narrow the search space. In contrast, the repo-level approach evaluated here scans all files in a repository, mirroring the actual workflow of a security auditor.

Methodology and Datasets

The researchers evaluated 15 SAST tools (e.g., CodeQL, SonarQube, Semgrep) against 12 open-source LLMs (e.g., CodeBERT, Llama3, StarCoder2). The evaluation spanned three languages: Java, C, and a newly curated Python dataset containing 98 CVEs from 2002–2023. The combined datasets included over 5.4 million functions.

To adapt LLMs for this task, the authors utilized four strategies: zero-shot prompting, few-shot prompting, Chain-of-Thought (CoT) reasoning, and fine-tuning (including Parameter-Efficient Fine-Tuning like LoRA).

Results: The Precision-Recall Frontier

The study revealed a stark trade-off between detection rates and false positives, quantified by the Marked Function Ratio (MFR)—the percentage of a codebase flagged as suspicious.

Performance trade-off between detection rate (S2) and the percentage of functions marked as suspicious.

Key findings include:

  • SAST Conservatism: SAST tools are generally conservative, marking less than 5% of functions. However, their detection rates are often low, peaking at approximately 44.4% (CodeQL on C).
  • LLM Aggression: Fine-tuned LLMs like DeepSeekCoder and Llama3 achieved near 100% detection rates in several scenarios. However, they often suffered from high MFR, sometimes flagging over 20-50% of the codebase, which creates a significant triage burden for developers.
  • Language-Specific Performance: The optimal tool varied by language. Fine-tuned LLMs dominated in Java, while ensembles of SAST tools performed better for C and Python.

Conclusion

The future of automated security auditing likely lies in ensembling. By requiring multiple LLMs to reach a consensus, researchers reduced false positives by up to 74%. Rather than replacing traditional tools, LLMs can be used to "verify" the potential vulnerabilities flagged by SAST tools, combining the precision of logic-based analysis with the broad knowledge of deep learning models. Future work will need to address computational costs and potential data leakage in LLM training sets.

Summary updated

BibTeX
@misc{zhou2024comparison,
  author = {Xin Zhou and Duc-Manh Tran and Thanh Le-Cong and Ting Zhang and Ivana Clairine Irsan and Joshua Sumarlin and Bach Le and David Lo},
  title = {{Comparison of Static Application Security Testing Tools and Large Language Models for Repo-level Vulnerability Detection}},
  year = {2024},
  eprint = {2407.16235},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2407.16235},
}
Figure