English

Taint-Based Code Slicing for LLMs-based Malicious NPM Package Detection

Cryptography and Security 2026-01-13 v2

Abstract

Software supply chain attacks targeting the npm ecosystem have become increasingly sophisticated, leveraging obfuscation and complex logic to evade traditional detection mechanisms. Recently, large language models (LLMs) have attracted significant attention for malicious code detection due to their strong capabilities in semantic code understanding. However, the practical deployment of LLMs in this domain is severely constrained by limited context windows and high computational costs. Naive approaches, such as token-based code splitting, often fragment semantic context, leading to degraded detection performance. To overcome these challenges, this paper introduces a novel LLM-based framework for malicious npm package detection that leverages code slicing techniques. A specialized taint-based slicing method tailored to the JavaScript ecosystem is proposed to recover malicious data flows. By isolating security-relevant logic from benign boilerplate code, the approach reduces the input code volume by over 99\% while preserving critical malicious behaviors. The framework is evaluated on a curated dataset comprising over \num{7000} malicious and benign npm packages. Experimental results using the DeepSeek-Coder-6.7B model demonstrate that the proposed approach achieves a detection accuracy of \num{87.04}\%, significantly outperforming a full-package baseline based on naive token splitting (\num{75.41}\%). These results indicate that semantically optimized input representations via code slicing not only mitigate the LLM context window bottleneck but also enhance reasoning precision for security analysis, providing an effective defense against evolving open-source software supply chain threats.

Keywords

Cite

@article{arxiv.2512.12313,
  title  = {Taint-Based Code Slicing for LLMs-based Malicious NPM Package Detection},
  author = {Dang-Khoa Nguyen and Gia-Thang Ho and Quang-Minh Pham and Tuyet A. Dang-Thi and Minh-Khanh Vu and Thanh-Cong Nguyen and Phat T. Tran-Truong and Duc-Ly Vu},
  journal= {arXiv preprint arXiv:2512.12313},
  year   = {2026}
}

Comments

21 pages, 1 figure, 5 tables, 2 algorithms

R2 v1 2026-07-01T08:23:26.510Z