SecureReviewer: Enhancing Large Language Models for Secure Code Review through Secure-aware Fine-tuning

Fang Liu, Simiao Liu, Yinghao Zhu, Xiaoli Lian, Li ZhangarXiv 2025 · DOI

Introduction

Modern software development increasingly adopts "shift-left" practices, aiming to identify vulnerabilities as early as possible in the lifecycle. Code review serves as a critical line of defense; however, manual review is notoriously slow and prone to human error. While Large Language Models (LLMs) have shown promise in automated code review, they often prioritize general code quality—such as style and logic—over critical security concerns.

Existing LLM-based approaches face three primary hurdles: noisy datasets filled with non-actionable comments, a mismatch between standard evaluation metrics (like BLEU) and security accuracy, and the tendency for models to hallucinate advice without grounded domain knowledge. To address these, the SecureReviewer framework introduces a specialized pipeline designed to transform general-purpose LLMs into security-aware experts.

The SecureReviewer Framework

SecureReviewer employs a multi-stage approach to refine LLM performance for security-centric tasks. The framework is built on three core innovations:

  1. Secure-aware Fine-tuning (SA-Loss): Traditional fine-tuning treats all tokens with equal importance. SecureReviewer introduces a novel loss function that "upweights" security-critical tokens, such as variable names involved in vulnerabilities and specific security category identifiers. This forces the model to prioritize technical precision over linguistic fluency.
  2. Retrieval-Augmented Generation (RAG): To mitigate hallucinations and provide grounded advice, the framework utilizes a "Template Datastore" of high-quality security reviews. During inference, the model first identifies the security issue type and then retrieves a relevant template to guide the generation of a detailed, actionable review comment.
  3. SecureBLEU Metric: Recognizing that a high BLEU score does not equate to a secure code review, the authors proposed SecureBLEU. This metric incorporates a security-type accuracy multiplier and a keyword overlap check based on a specialized security dictionary, ensuring models are rewarded for identifying the correct vulnerability and using appropriate technical terminology.
The SecureReviewer framework overview, illustrating the pipeline from data collection to retrieval-augmented generation.

Data Curation and Refinement

High-quality training data is essential for specialized fine-tuning. The researchers curated a dataset derived from the CodeReviewer dataset (originally 138k entries). Using keyword matching and semantic embeddings based on the Common Weakness Enumeration (CWE-699), they filtered for security-specific interactions. The final dataset consists of 4,674 entries spanning seven major security categories, including Input Validation, Concurrency, and Access Control. To minimize false positives, a "Non-Issue" category was also included. The quality of this dataset was manually validated by domain experts, ensuring a 95% confidence level.

Experimental Results and Evaluation

SecureReviewer was benchmarked against both specialized models (e.g., LlamaReviewer) and state-of-the-art general LLMs (e.g., GPT-4o). The results demonstrate significant improvements across all key metrics:

  • Detection Accuracy: SecureReviewer achieved a 17% higher F1-score and 18% better accuracy than the leading baselines.
  • Comment Quality: The framework showed a 19% relative improvement in SecureBLEU scores compared to existing state-of-the-art models.
  • Human Evaluation: In blind tests, human experts rated SecureReviewer highly for Clarity (3.93/5), Relevance (4.06/5), and Actionability (3.90/5).
A comparison between a reference comment and a generated comment, highlighting how SecureBLEU provides a more rigorous assessment of security identification than standard BLEU.

Discussion and Future Work

A key insight from this research is the "BLEU Paradox": a model can generate a comment that looks linguistically similar to a human review (high BLEU) while failing to identify the actual security threat. SecureReviewer’s SA-Loss and SecureBLEU metric directly address this by prioritizing security semantics. Furthermore, the RAG component proved particularly effective for general-purpose models, bridging the domain-knowledge gap for off-the-shelf LLMs.

Despite its success, SecureReviewer currently focuses on code diffs and may struggle with vulnerabilities requiring global codebase context. Future work will explore integrating broader execution flows and utilizing more cost-effective backbone models to facilitate large-scale deployment in industrial environments.

Summary updated

BibTeX
@misc{liu2025securereviewer,
  author = {Fang Liu and Simiao Liu and Yinghao Zhu and Xiaoli Lian and Li Zhang},
  title = {{SecureReviewer: Enhancing Large Language Models for Secure Code Review through Secure-aware Fine-tuning}},
  year = {2025},
  eprint = {2510.26457},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2510.26457},
}
Figure