TL;DR
LLMxCPG is a novel framework that merges Code Property Graphs (CPGs) with Large Language Models (LLMs) to drastically improve software vulnerability detection. By using a fine-tuned LLM to generate precise graph queries, it strips away 68% to 91% of irrelevant code while preserving critical multi-function execution context, leading to a 15–40% boost in F1-score over state-of-the-art baselines.
What Problem Does This Paper Address?
Deep learning and LLM-based vulnerability detectors show immense promise, but they suffer from a major flaw: brittleness. When evaluated on rigorously verified datasets, the accuracy of state-of-the-art models often plummets by up to 45%. This happens because models frequently overfit to superficial patterns—like variable names or comments—rather than understanding actual control and data flows.
Furthermore, most existing approaches are restricted to function-level analysis. They miss vulnerabilities that span multiple functions or files because entire codebases quickly overwhelm the limited context windows of standard embedding models.
Methods
The authors introduce LLMxCPG, a two-phase framework that combines the structural precision of graph-based program analysis with the advanced reasoning of LLMs.
- Slice Construction (
LLMxCPG-Q): Instead of feeding raw, noisy code directly to a classifier, the framework uses a fine-tuned LLM (Qwen2.5-Coder-32B-Instruct) to generate graph queries in CPGQL (the query language for the Joern static analysis tool). These queries traverse a Code Property Graph (CPG)—which merges Abstract Syntax Trees, Control Flow Graphs, and Program Dependence Graphs—to map out potential vulnerability execution paths. It then applies backward slicing to isolate only the essential code elements and interacting variables. - Vulnerability Detection (
LLMxCPG-D): The highly condensed code slice is fed into a second fine-tuned LLM (QwQ-32B-Preview), which performs a binary classification to label the slice as either "Vulnerable" or "Safe".
Datasets
The framework was trained and evaluated using several distinct datasets:
- Training:
- FormAI-v2: 331,000 AI-generated C programs formally verified using the ESBMC bounded model checker.
- PrimeVul: A high-quality, rigorously reviewed real-world dataset designed to eliminate data duplication and labeling errors.
- Evaluation & Generalizability:
- SVEN: A manually curated dataset of real-world GitHub security fixes used to test performance on unseen code.
- ReposVul: A repository-level dataset containing complex, multi-file, and multi-function codebases.
- PKCO-25 (Post-Knowledge-Cutoff): A custom dataset compiled from 60 CVEs published in early 2025 to evaluate how well the model generalizes to entirely novel, emerging vulnerabilities.
Key Insights and Ideas
- Slicing Cuts the Noise: Feeding raw code to an LLM introduces massive token overhead and distracting noise. Graph-guided slicing acts as an intelligent filter, reducing code size by up to 91% while keeping the semantic "ground truth" of the execution path intact.
- Overcoming Low-Resource Language Barriers: CPGQL is a niche query language based on Scala, making it difficult for standard LLMs to write accurately. The authors overcame this by training
LLMxCPG-Qusing an iterative feedback loop with a Joern server, allowing the model to learn from syntax errors and refine its queries. - True Semantic Robustness: Because the slicing process strips away comments and focuses purely on data and control dependencies, the model is highly resistant to adversarial code modifications (like variable renaming or statement reordering) that typically trick standard deep learning models.
Key Results
- Massive Code Reduction: The framework achieved an average code size reduction of 78.70% on FormAI, 67.84% on PrimeVul, 70.22% on SVEN, and a substantial 90.93% on project-level ReposVul codebases.
- Performance Leap: On the unseen SVEN dataset, LLMxCPG outperformed top baselines (such as VulSim, VulBERTa, and ReGVD), delivering a 15–40% improvement in F1-score and a 9–27% increase in Accuracy.
- Zero-Shot Project-Level Generalization: Despite being trained primarily on function-level data, it maintained a solid 0.634 accuracy on complex, multi-function project code from ReposVul and a 0.600 accuracy on the 2025 post-cutoff dataset.
Limitations and Future Work
Despite its success, the authors note a few key limitations:
- Extreme Complexity Degradation: Performance drops significantly (down to 0.33 accuracy) on code samples featuring very high nesting depths (>7 levels) or highly intricate inter-function relationships.
- Vulnerability Type Coverage: Static CPG analysis cannot easily model runtime-dependent flaws, such as race conditions or complex architectural design flaws.
- Hardware Constraints: Due to computing limitations, the query-generation model was fine-tuned with a 32K token limit, though the base model theoretically supports up to 128K.
For future work, the authors plan to compile a larger, high-quality, syntactically augmented multi-file dataset verified via bounded model checking to further enhance the model's complex reasoning capabilities.
Summary updated