Taint-Based Code Slicing for LLMs-based Malicious NPM Package Detection
By: Dang-Khoa Nguyen , Gia-Thang Ho , Quang-Minh Pham and more
Potential Business Impact:
Finds bad code in computer programs faster.
The increasing sophistication of malware attacks in the npm ecosystem, characterized by obfuscation and complex logic, necessitates advanced detection methods. Recently, researchers have turned their attention from traditional detection approaches to Large Language Models (LLMs) due to their strong capabilities in semantic code understanding. However, while LLMs offer superior semantic reasoning for code analysis, their practical application is constrained by limited context windows and high computational cost. This paper addresses this challenge by introducing a novel framework that leverages code slicing techniques for an LLM-based malicious package detection task. We propose a specialized taintbased slicing technique for npm packages, augmented by a heuristic backtracking mechanism to accurately capture malicious data flows across asynchronous, event-driven patterns (e.g., callbacks and Promises) that elude traditional analysis. An evaluation on a dataset of more than 5000 malicious and benign npm packages demonstrates that our approach isolates security-relevant code, reducing input volume by over 99% while preserving critical behavioral semantics. Using the DeepSeek-Coder-6.7B model as the classification engine, our approach achieves a detection accuracy of 87.04%, substantially outperforming a naive token-splitting baseline (75.41%) and a traditional static-analysis-based approach. These results indicate that semantically optimized input representation via code slicing not only mitigates the LLM context-window bottleneck but also significantly enhances reasoning precision for security tasks, providing an efficient and effective defense against evolving malicious open-source packages.
Similar Papers
Learning to Triage Taint Flows Reported by Dynamic Program Analysis in Node.js Packages
Cryptography and Security
Helps find computer bugs faster and easier.
Towards Classifying Benign And Malicious Packages Using Machine Learning
Cryptography and Security
Finds bad computer code before it causes harm.
Large Language Model (LLM) for Software Security: Code Analysis, Malware Analysis, Reverse Engineering
Cryptography and Security
Helps computers find computer viruses faster.