VulCoCo: A Simple Yet Effective Method for Detecting Vulnerable Code Clones

Tan Bui, Yan Naing Tun, Thanh Phuc Nguyen, Yindu Su, Ferdian Thung, Yikun Li, Han Wei Ang, Yide Yin, Frank Liauw, Lwin Khin Shar, Eng Lieh Ouh, Ting Zhang, David LoarXiv 2025 · DOI

Introduction

Code reuse is a fundamental practice in modern software development, yet it carries a significant security risk: the propagation of Vulnerable Code Clones (VCCs). When developers copy and paste code snippets containing hidden vulnerabilities, they inadvertently spread security flaws across disparate projects. Even if the original source is eventually patched, the cloned versions often remain unpatched and silent in downstream repositories.

Detecting these clones is a significant technical challenge. Traditional tools typically rely on syntactic matching, such as comparing Abstract Syntax Trees (ASTs) or code hashes. While effective for exact copies (Type-1 clones), these methods fail when developers modify the code through variable renaming, statement reordering, or logic refactoring (Type-3 and Type-4 clones). Furthermore, existing tools often lack transparency, providing binary labels without justification, and the field has historically lacked a standardized, reproducible benchmark for evaluation. VulCoCo (Vulnerable Code Clone detector) addresses these gaps by combining semantic embedding-based retrieval with Large Language Model (LLM) validation.

Methodology

VulCoCo moves away from rigid syntax matching, employing a flexible three-phase pipeline designed for both recall and precision:

  1. Target Repository Processing: The system utilizes tree-sitter to parse target C, C++, and Java repositories into discrete, function-level blocks.
  2. Embedding-Based Retrieval: To identify candidates, VulCoCo converts both known vulnerable functions and target functions into semantic vector embeddings using jina-embeddings-v4. Similarity search is performed via the FAISS library.
  3. Heuristic Filtering: To improve efficiency, VulCoCo calculates a candidate's similarity to both the vulnerable and the fixed version of the original code. If a candidate is semantically closer to the fixed version, it is discarded as a likely safe implementation.
  4. LLM-Based Validation: Surviving candidates are analyzed by Claude Sonnet 4. The LLM is provided with the original vulnerable function, the patched version, and the candidate clone. Acting as an expert reviewer, the LLM determines if the vulnerability persists and provides a natural language justification for its decision in a structured JSON format.

The SyVC Benchmark

To address the lack of reproducible evaluation data, the authors introduced the SyVC (Synthetic Vulnerable Clones) Benchmark. This dataset consists of 100 real-world vulnerable/fixed function pairs. For each pair, an LLM was used to generate five realistic clones ranging from Type-1 (exact) to Type-4 (semantic rewrites), resulting in a balanced 1,000-sample ground-truth benchmark for the research community.

Key Results and Impact

VulCoCo demonstrates substantial improvements over state-of-the-art baselines in both synthetic and real-world environments:

  • Benchmark Performance: On the SyVC benchmark, VulCoCo achieved a Mean Average Precision (MAP) of 67.69%, representing a 119% improvement over the best-performing baseline, MOVERY (30.94%).
  • Real-World Effectiveness: In scans of 10 popular open-source repositories (e.g., Apache Flink, Radare2), VulCoCo achieved an F1 score of 72.16%, significantly outperforming the baseline tool FIRE (23.61%).
  • Security Contributions: The practical utility of the tool is evidenced by its real-world impact. The authors submitted 400 pull requests to 284 open-source projects. To date, 75 PRs have been merged, and the tool has led to the discovery and publication of 15 new CVEs.

Discussion and Insights

The success of VulCoCo highlights that a two-stage pipeline is ideal for code security: embeddings provide the necessary recall to find semantic similarities despite heavy refactoring, while LLMs provide the logical reasoning required to confirm security vulnerabilities.

However, the study also identified a phenomenon termed LLM "Confabulation." When a vulnerability fix is extremely subtle (e.g., a minor change in variable type), the LLM may struggle to identify the fix. In these instances, rather than reporting uncertainty, the model occasionally "hallucinates" an unrelated vulnerability—such as an array bounds issue—to justify flagging the code as vulnerable. This suggests that while LLMs are powerful, their reasoning in edge cases requires careful calibration.

Limitations and Future Work

Currently, VulCoCo is limited to function-level analysis, meaning it may miss vulnerabilities that depend on broader system context or cross-function data flows. Additionally, the cost of querying commercial LLMs like Claude Sonnet 4 at scale remains a hurdle; during real-world testing, the authors had to increase similarity thresholds to manage API costs.

Future research will focus on expanding the vulnerability corpus to more programming languages and exploring the use of smaller, fine-tuned local models to reduce operational costs. Additionally, the authors aim to extend the pipeline to automatically generate patches for the clones it detects, creating an end-to-end solution for vulnerability remediation.

Summary updated

BibTeX
@misc{bui2025vulcoco,
  author = {Tan Bui and Yan Naing Tun and Thanh Phuc Nguyen and Yindu Su and Ferdian Thung and Yikun Li and Han Wei Ang and Yide Yin and Frank Liauw and Lwin Khin Shar and Eng Lieh Ouh and Ting Zhang and David Lo},
  title = {{VulCoCo: A Simple Yet Effective Method for Detecting Vulnerable Code Clones}},
  year = {2025},
  eprint = {2507.16661},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2507.16661},
}
Figure