TL;DR
Existing vulnerability detection models typically analyze code at the single-function level, missing critical bugs that span multiple functions. Simply dumping raw surrounding code into a model introduces noise that degrades performance; CPRVUL solves this by intelligently profiling and selecting security-relevant inter-procedural context, then training large language models (LLMs) to explicitly reason over it.
What Problem Does This Paper Address?
Most automated vulnerability detection tools operate under a flawed assumption: that a single function contains all the information necessary to determine if it is vulnerable. In reality, many security flaws depend heavily on inter-procedural context—such as how a function's arguments are validated by its callers, the behavior of its callees, or changes to a shared global state.
While recent high-quality datasets have cleaned up label noise, models trained strictly on function-level code still struggle. You might think the solution is simple: just append the code of the callers and callees to the input. However, the authors demonstrate that this naive approach actually degrades the performance of strong code models. Real-world codebases introduce too much long, redundant, and noisy context, which overwhelms the model's attention mechanism and fills up its context window with irrelevant tokens.
Methods
The authors introduce CPRVUL, a two-phase framework designed to filter out the noise and teach models how to reason about inter-procedural relationships.
Phase I: Context Profiling and Selection
- Context Extraction: For a target function, the framework builds a Code Property Graph (CPG) to map out its repository-level relationships, extracting all candidate callers, callees, and accessed global variables.
- Security Profiling: Instead of feeding raw code, CPRVUL uses an LLM (GPT-4) to compress these components into concise, security-focused text profiles (e.g., noting if a caller sanitizes input or if a callee lacks bounds checking).
- Relevance Ranking: The LLM scores and ranks these profiles based on their relevance to the target function's security, selecting only the highest-impact elements to fit within the model's context window.
Phase II: Context-Aware Reasoning and Detection
Rather than treating vulnerability detection as a simple binary classification task, CPRVUL frames it as a reasoning problem. The target function, its selected context profiles, and auxiliary metadata (like CVE/CWE descriptions and commit messages) are combined into a structured prompt. An LLM generates explicit, step-by-step reasoning traces explaining why the code is or isn't vulnerable. Finally, open-source LLMs (Qwen2.5-Coder 7B and 32B) are fine-tuned via LoRA on these reasoning traces to perform the final detection at inference time.
Datasets
The framework was evaluated on three high-quality vulnerability benchmarks:
- PRIMEVUL
- TITANVUL
- CLEANVUL
Additionally, the authors created and released context-enriched variants of these datasets—PrimeVulCTX, TitanVulCTX, and CleanVulCTX—providing a massive corpus of 19,858 callers, 187,170 callees, and 132,633 global variables mapped to 23,904 labeled functions across 883 repositories.
Key Insights and Ideas
- Naive Context is Toxic: Simply appending raw code context consistently hurts accuracy. As shown in the paper's preliminary experiments, adding unstructured context caused UniXcoder's accuracy on PRIMEVUL to drop from 56.65% to 54.22%.
- The Synergy of Context and Reasoning: A key takeaway from the ablation studies is that neither processed context nor reasoning capabilities work in isolation. Conventional encoder models still fail when given the processed context alone. The performance gains only emerge when the model is explicitly trained to reason over the structured context.
- Spatial vs. Temporal Strengths: CPRVUL shows massive improvements in vulnerabilities that rely on spatial code distribution, such as Access Control (CWE-264) and Resource Management (CWE-399). However, it struggles with temporal bugs like Double Free (CWE-415), indicating that tracking state changes over complex execution paths requires a different flavor of reasoning.
Key Results
CPRVUL achieved substantial performance leaps over function-only baselines and state-of-the-art (SOTA) methods across all three datasets:
- New State-of-the-Art: On the rigorous PRIMEVUL benchmark, CPRVUL (using the Qwen2.5-32B backbone) achieved 67.78% accuracy, outperforming the previous best SOTA approach (VulTrial, 55.17%) by an absolute 12.61 percentage points—a 22.9% relative improvement.
- Consistent Gains: It achieved accuracies of 73.76% on TITANVUL and 64.94% on CLEANVUL, comfortably beating strong baselines like UniXcoder.
- Precision Boost: Crucially for real-world deployment, CPRVUL significantly improved precision (e.g., jumping from 55.34% to 67.62% on PRIMEVUL), meaning it generates far fewer false positives that waste developers' time.
Limitations and Future Work
The primary limitation identified is the framework's handling of temporal vulnerabilities. For instance, on TITANVUL, accuracy for Double Free bugs (CWE-415) actually degraded by 6.90 points. The authors note that tracking memory lifecycles across multiple execution paths requires sophisticated temporal reasoning that simple spatial context profiling cannot fully capture.
To address this, future work will focus on incorporating path-sensitive and temporal-sensitive signals directly into the context generation phase to better capture complex lifetime weaknesses.
Summary updated