Leveraging Large Language Models to Detect npm Malicious Packages
Open accessAbstract
Existing malicious code detection techniques demand the integration of multiple tools to detect different malware patterns, often suffering from high misclassification rates. Therefore, malicious code detection techniques could be enhanced by adopting advanced, more automated approaches to achieve high accuracy and a low misclassification rate. The goal of this study is to aid security analysts in detecting malicious packages by empirically studying the effectiveness of Large Language Models (LLMs) in detecting malicious code. We present SocketAI, a malicious code review workflow to detect malicious code. To evaluate the effectiveness of SocketAI, we leverage a benchmark dataset of 5,115 npm packages, of which 2,180 packages have malicious code. We conducted a baseline comparison of GPT-3 and GPT-4 models with the state-of-the-art CodeQL static analysis tool, using 39 custom CodeQL rules developed in prior research to detect malicious Javascript code. We also compare the effectiveness of static analysis as a pre-screener with SocketAI workflow, measuring the number of files that need to be analyzed. and the associated costs. Additionally, we performed a qualitative study to understand the types of malicious activities detected or missed by our workflow. Our baseline comparison demonstrates a 16% and 9% improvement over static analysis in precision and F1 scores, respectively. GPT-4 achieves higher accuracy with 99% precision and 97% F1 scores, while GPT-3 offers a more cost-effective balance at 91% precision and 94% F1 scores. Pre-screening files with a static analyzer reduces the number of files requiring LLM analysis by 77.9% and decreases costs by 60.9% for GPT-3 and 76.1% for GPT-4. Our qualitative analysis identified data theft, execution of arbitrary code, and suspicious domain categories as the top detected malicious packages.
The claims and statistics of this paper haven’t been checked yet.
Run the check — free, no account needed. It reads the open-access text and checks the sources it cites.
Integrity signals
Registry
Cites
Statistics
Claims the paper makes
The claims and statistics of this paper haven’t been checked yet.
Run the check — free, no account needed. It reads the open-access text and checks the sources it cites.
Claims other papers make about this one
Each is checked against this paper’s own text: does it say what the citing paper says it does?
Zahan et al. (2024) employs GPT-3 and GPT-4 to detect potential malware in the npm ecosystem by analyzing JavaScript packages.
“Zahan et al. (2024) employs GPT-3 and GPT-4 to detect potential malware in the npm ecosystem by analyzing JavaScript packages.”
From When LLMs meet cybersecurity: a systematic literature review (2025) · cites this paper as Zahan et al. (2024)
Zahan et al. (2024) demonstrates that LLMs can effectively pinpoint malware with higher precision and lower false positive rates compared to static analysis tools.
“By comparing LLMs' performance with static analysis tools, the paper demonstrates that LLMs can effectively pinpoint malware with higher precision and lower false positive rates.”
From When LLMs meet cybersecurity: a systematic literature review (2025) · cites this paper as Zahan et al. (2024)
Self-check
Percentages, sums and reported differences re-computed from the paper’s own numbers.
The self-check needs the paper’s full text.
Cites
The publisher hasn’t deposited this paper’s reference list.
Research works printed but not linked: 5
- BROWN, T., MANN, B., RYDER, N., SUBBIAH, M., KAPLAN, J. D., DHARIWAL, P., NEELAKANTAN, A., SHYAM, P., SASTRY, G., ASKELL, A., ET AL. Language models are few-shot learners. Advances in neural information processing systems 33 (2020), 1877-1901.
- ČARNOGURSK Ỳ, M. Attacks on package managers. Bachelor Thesis, Masaryk University, Brünn, Tschechien (2019).
- JI, Z., LEE, N., FRIESKE, R., YU, T., SU, D., XU, Y., ISHII, E., BANG, Y. J., MADOTTO, A., AND FUNG, P. Survey of hallucination in natural language generation. ACM Computing Surveys.
- MILJE, A. A. Detecting malicious python packages in the python package index (pypi). Master's thesis, NTNU, 2022.
- ZAHAN, N., BURCKHARDT, P., LYSENKO, M., ABOUKHADIJEH, F., AND WILLIAMS, L. Malwarebench: Malware samples are not enough. In 2024 IEEE/ACM 21st International Conference on Mining Software Repositories (MSR) (2024), IEEE, pp. 728-732.
Cited by
Sorted by citations
When LLMs meet cybersecurity: a systematic literature review
Zhang, J., Bu, H., Wen, H., Liu, Y., Fei, H., Xi, R., Li, L., Yang, Y., Zhu, H., & Meng, D. (2025) · Cybersecurity · doi:10.1186/s42400-025-00361-w · Cited by 220 · see citing works
Friha, O., Ferrag, M. A., Kantarcı, B., Çakmak, B., Ozgun, A., & Ghoualmi‐Zine, N. (2024) · IEEE Open Journal of the Communications Society · doi:10.1109/ojcoms.2024.3456549 · Cited by 209 · see citing works
Research Directions in Software Supply Chain Security
Williams, L. A., Benedetti, G., Hamer, S., Paramitha, R., Rahman, I., Tamanna, M., Tystahl, G., Zahan, N., Morrison, P. J., Acar, Y., et al. (2025) · ACM Transactions on Software Engineering and Methodology · doi:10.1145/3714464 · Cited by 74 · see citing works
Self-citationMaltracker: A Fine-Grained NPM Malware Tracker Copiloted by LLM-Enhanced Dataset
Yu, Z., Wen, M., Guo, X., & Jin, H. (2024) · ACM SIGSOFT International Symposium on Software Testing and Analysis (ISSTA) · doi:10.1145/3650212.3680397 · Cited by 33 · see citing works
A Contemporary Survey of Large Language Model Assisted Program Analysis
Wang, J., Tao, N., Lee, W.-B., & Zhao, Q. (2025) · Transactions on Artificial Intelligence · doi:10.53941/tai.2025.100006 · Cited by 28 · see citing works
Large Language Models for Cybersecurity Intelligence, Threat Hunting, and Decision Support
Ren, S., & Chen, S. (2025) · Jisuanji shenghuojia. · doi:10.54097/7ysr5k17 · Cited by 16 · see citing works
Huang, Y., Wang, R., Zheng, W. H., Zhou, Z., Wu, S., Ke, S., Chen, B., Gao, S., & Peng, X. (2024) · IEEE/ACM International Conference on Automated Software Engineering (ASE) · doi:10.1145/3691620.3695492 · Cited by 13 · see citing works
MalPacDetector: An LLM-Based Malicious NPM Package Detector
Wang, J., Li, Z., Qu, J., Zou, D., Xu, S., Xu, Z., Wang, Z., & Jin, H. (2025) · IEEE Transactions on Information Forensics and Security · doi:10.1109/tifs.2025.3580336 · Cited by 11 · see citing works
He, H., Vasilescu, B., & Kästner, C. (2025) · Proceedings of the ACM on software engineering. · doi:10.1145/3715728 · Cited by 10 · see citing works
Closing the Chain: How to reduce your risk of being SolarWinds, Log4j, or XZ Utils
Hamer, S., Bowen, J., Haque, M. N., Hines, R., Madden, C., & Williams, L. A. (2026) · ACM/IEEE International Conference on Software Engineering: Companion Proceedings (ICSE-Companion) · doi:10.1145/3744916.3773194 · Cited by 6 · see citing works
Self-citationIntelliRadar: A Comprehensive Platform to Pinpoint Malicious Packages from Cyber Intelligence
Guo, W., Liu, C., Wang, L., Zhang, Y., Wu, J., Xu, Z., & Liu, Y. (2026) · ACM/IEEE International Conference on Software Engineering: Companion Proceedings (ICSE-Companion) · doi:10.1145/3744916.3773113 · Cited by 5 · see citing works
Detecting Malicious Source Code in PyPI Packages with LLMs: Does RAG Come in Handy
Ibiyo, M. O., Louangdy, T., Nguyen, P. T. L., Sipio, C. D., & Ruscio, D. D. (2025) · International Conference on Evaluation and Assessment in Software Engineering (EASE) · doi:10.1145/3756681.3757042 · Cited by 2 · see citing works
Metaverse Security: LLM-Based Malicious Code Detection Through Token Optimization
Park, S., Min, D., Nguyen, T. A., & Choi, E. (2025) · IEEE International Conference on Metaverse Computing, Networking and Applications (MetaCom) · doi:10.1109/metacom65502.2025.00057 · Cited by 1 · see citing works
ProfMal: Detecting Malicious NPM Packages by the Synergy between Static and Dynamic Analysis
Huang, Y., Zheng, W., Wu, S., Chen, B., Lu, Y. J., Zhou, Z., Cao, Y., Li, X., & Peng, X. (2025) · IEEE/ACM International Conference on Automated Software Engineering (ASE) · doi:10.1109/ase63991.2025.00042 · Cited by 1 · see citing works
CHASE: LLM Agents for Dissecting Malicious PyPI Packages
Toda, T., & Mori, T. (2025) · ACM International Conference on AI-Powered Software (AIware) · doi:10.1109/aiware69974.2025.00008 · Cited by 2 · see citing works
One Detector Fits All: Robust and Adaptive Detection of Malicious Packages from PyPI to Enterprises
Montaruli, B., Compagna, L., Ponta, S. E., & Balzarotti, D. (2025) · Annual Computer Security Applications Conference · doi:10.1109/acsac67867.2025.00053 · Cited by 1 · see citing works
Large language models for cyberattack defense: a critical survey
Fourati, L. C., Awad, M., Ali, M. B., & Jaafar, W. (2026) · Knowledge and Information Systems · doi:10.1007/s10115-026-02736-y · Cited by 1 · see citing works
Designing Abandabot: When Does Open Source Dependency Abandonment Matter?
Miller, C., He, H., Chen, W., Lin, E., Yang, C., Vasilescu, B., & Kästner, C. (2026) · ACM/IEEE International Conference on Software Engineering: Companion Proceedings (ICSE-Companion) · doi:10.1145/3744916.3764519 · Cited by 1 · see citing works
Cybersecurity with LLMs and RAGs: Challenges and Innovations
Simoni, M., & Saracino, A. (2025) · Lecture notes of the Institute for Computer Sciences, Social Informatics and Telecommunications Engineering · doi:10.1007/978-3-031-94458-1_8
Cai, Z., Cai, Y., Leng, T., Zhou, H., Xie, X., Sun, Y., Chai, Y., & Qiu, J. (2025) · IEEE International Conference on Data Science in Cyberspace · doi:10.1109/dsc67331.2025.00044
MalSkills: Detecting Malicious Skills in the Agentic Supply Chain via Neuro-symbolic Reasoning
Wang, S., He, J., Zhao, Y., Wang, Y., Yu, K., & Wang, H. (2026) · IEEE/ACM International Conference on Automated Software Engineering (ASE) · doi:10.1145/3832783.3834375
Rytilahti, J., Puhtila, P., Weerakoon, O., Kaila, E., & Mäkilä, T. (2026) · International Workshop on Agentic Engineering · doi:10.1145/3786167.3788413
Guardnpm: Automated Identification of Malicious NPM Dependencies
Sharan, M., Sathiyapriya, V., & Keerthana, S. (2026) · IEEE International Conference on Intelligent Technologies for a Sustainable and Inclusive Future (ICITSIF) · doi:10.1109/icitsif69060.2026.11609160
Leveraging Code Slicing for LLMs-Based Malicious NPM Package Detection
Nguyen, D.-K., Ho, G., Pham, Q. N., Anh, T. D.-T., Vu, M.-K., Nguyen, T. C., Tran-Truong, P. T., & Vu, D. (2026) · Lecture notes in computer science · doi:10.1007/978-3-032-35576-8_2
Bai, H., Zhang, J., Li, H., Fu, X., siya, A., & Hao, Y. (2026) · Journal of King Saud University - Computer and Information Sciences · doi:10.1007/s44443-026-01121-7
Park, S., & Yang, J. (2026) · International Conference on Advanced Algorithms and Neural Networks (AANN) · doi:10.1109/aann71145.2026.11709227
Seeing the Forest: A Taxonomy-Guided Analysis and Improvement of Malicious PyPI Package Detectors
Liu, Z., Wang, J., & Chen, S. (2026) · doi:10.1145/3844178.3844648
Defensive Capability Analysis for JavaScript Libraries
Xu, W., & Møller, A. (2026) · IEEE/ACM International Conference on Automated Software Engineering (ASE) · doi:10.1145/3832783.3837491
An Explainable Multi-Feature Learning Approach for Malware Detection Using API Call Sequences
Thakur, K., Sharma, A., Chankrola, V., Rana, T., Gandotra, E., & Gupta, D. (2026) · International Conference on Integrated Circuits, Communication, and Computing Systems (ICIC3S) · doi:10.1109/icic3s72305.2026.11737183
- Authors
- Zahan, N., Burckhardt, P., Lysenko, M., Aboukhadijeh, F., & Williams, L.
- Affiliations
- North Carolina State University (US)
- Venue
- arXiv
- Publisher
- arXiv
- Published
- 2024
- ISSN
- 2331-8422 (ISSN-L)
- arXiv
- 2403.12196
- OpenAlex
- W4393055583
- Cited by
- 3
- References
- 0
- Citations by year
- 2025: 1 · 2024: 2
- Type
- posted content
- Language
- en
- Open access
- green
- arxiv.org
- Locations
- arXiv (Cornell University) (submittedVersion)
- arXiv (Cornell University)
- Funders
- National Science Foundation (2207008)
- North Carolina State University
- Topics
- Physical Sciences › Computer Science › Signal Processing › Advanced Malware Detection Techniques
- Physical Sciences › Computer Science › Information Systems › Software Engineering Research
- Physical Sciences › Computer Science › Artificial Intelligence › Security and Verification in Computing
- Keywords
- malicious package detection, npm packages, large language models, GPT-3, GPT-4, data theft, arbitrary code execution, security cost reduction
About these checks
Registry, retraction, Cites and statistics results are computed, not judged, with one exception: a printed reference that no index lists is read once by a model before it counts as a citation error. Claims are extracted by a model and kept only when their quote appears verbatim in the text; each cited source is then checked, with a model’s help, for whether it says what the claim relies on. Those verdicts can be wrong — read the claim’s quote and the cited source before relying on one.
Statistics and arithmetic are recomputed, not judged.
Confidence bands are shown only for fields calibrated on our annotated test set. None is calibrated yet, so no band is shown.
What counts as a claim ›How we measure confidence ›How we check this ›
Are you an author, or do you see a problem with this page? Request a review