
The code of VulTriage: Triple-Path Context Augmentation for LLM-Based Vulnerability Detection

An intelligent vulnerability detection framework based on Large Language Models and static code analysis, supporting multi-dataset evaluation and ablation studies.

This project is an intelligent vulnerability detection framework based on GPT-4o and BGE-M3 models, combining:
pip install -r requirements.txt
The model will be downloaded automatically, or you can download it manually:
git clone https://huggingface.co/BAAI/bge-m3
# Note: BGE-M3 related dependencies can be installed via FlagEmbedding. For details, refer to: pip install -U FlagEmbedding
Ensure that cwec_latest.xml/cwec_v4.19.1.xml and 1435.csv/1435_filtered_columns.csv (CWE index data) files exist in the project root directory.
Note: This project uses CWE Top 25 Most Dangerous Software Weaknesses. Related files are already included in the project root directory.
Place the following files in the project root directory:
primevul_test_paired.jsonl (PrimeVul dataset)LLM4Vul-main/LLM4Vul-main/data/kotlin_data.csv (Kotlin dataset)Modify the OpenAI API configuration in main.py or hyperparam_exp.py:
client = OpenAI(
api_key="YOUR_API_KEY",
base_url="https://api.poixe.com/v1"
)
Note: The current URL
https://api.poixe.com/v1failed to parse. It may be an unsupported webpage type or a broken link. Please verify the link validity or switch to another API provider.
python main.py --wotask all --jsonl_file primevul_test_paired.jsonl
# Without control flow information
python main.py --wotask wo_ctrl_info_pth --jsonl_file primevul_test_paired.jsonl
# Without RAG knowledge
python main.py --wotask wo_rag_pth --jsonl_file primevul_test_paired.jsonl
# Without code understanding
python main.py --wotask wo_exp_pth --jsonl_file primevul_test_paired.jsonl
# Without any auxiliary information
python main.py --wotask nan --jsonl_file primevul_test_paired.jsonl
# Pairwise evaluation mode
python hyperparam_exp.py --mode pairwise --input_file primevul_test_paired.jsonl --detail_level C --info_comb all --desc_level concise --max_vuln 2
# Single-sample evaluation mode
python hyperparam_exp.py --mode single --input_file LLM4Vul-main/LLM4Vul-main/data/kotlin_data.csv
Detection results are saved in real-time to metrics_log.txt and final evaluation summaries are output to the terminal:
| Script | Purpose |
|---|---|
main.py | Main vulnerability detection script with ablation study support |
hyperparam_exp.py | Hyperparameter experiments and multi-mode evaluation |
retrieval.py | CWE knowledge base retrieval module (hybrid retrieval based on BGE-M3 model) |
metrics_tracker.py | Real-time metrics tracker with log saving and visualization support |
| Parameter | Default | Description |
|---|---|---|
--wotask | all | Ablation mode: all (full functionality), wo_ctrl_info_pth (no static structure info), wo_rag_pth (no RAG knowledge), wo_exp_pth (no code understanding), nan (no auxiliary information) |
--jsonl_file | primevul_test_paired.jsonl | JSONL dataset path |
--metrics_file | metrics_log.txt | Metrics output file |
| Parameter | Default | Description |
|---|---|---|
--mode | pairwise | Evaluation mode: pairwise or single |
--input_file | Required | Input file path (JSONL or CSV format) |
--detail_level | C | Code analysis detail level: C (complete), B (standard), A (brief) |
--info_comb | all | Information combination: all, no_ast, no_cfg, no_dfg |
--desc_level | concise | Description level: concise, normal, detailed |
--max_vuln | 2 | Maximum number of vulnerabilities: 2 or 4 |
func and target fields)code and label columns)| Library | Version | License |
|---|---|---|
| FlagEmbedding | 1.4.0 | MIT |
| openai | 2.26.0 | Apache 2.0 |
Modify the base_url and api_key in main.py or hyperparam_exp.py.
1435.csv/1435_filtered_columns.csv is loaded correctly and ensure the CWE index data format is correct;git clone https://huggingface.co/BAAI/bge-m3;Modify the update_pair_metrics method in metrics_tracker.py to add or adjust metric calculation logic.
Download the model files directly from the HuggingFace website, extract them to the project root directory, or check your network connection and re-execute the git clone https://huggingface.co/BAAI/bge-m3 command.