Skip to content

Package Hallucinations as Phantoms in Open-source Software Supply Chains: An Empirical Security Analysis

Jul 2026 · ACM Transactions on Software Engineering and Methodology · 0 citations · 53 references

TL;DR

An autonomous defense agent is designed: NymGuard, which provides a proactive defense by automating the real-time detection of hallucinated packages, their preemptive registration to block malicious use and the maintenance of a public warning registry.

Abstract

In code generation tasks, large language models (LLMs) frequently recommend nonexistent software packages, referred to as package hallucinations. This may pose a security risk, as attackers could register these fake packages and exploit them in supply chain attacks. To investigate the real-world feasibility, this paper conducts a systematic empirical study of this potential threat. We extracted 107 hallucinated packages from eight prominent LLMs and uploaded them to the npm registry over six months. The results demonstrate a tangible risk: 35.2% of package installations are attributed to developers, with most initial interactions occurring within a two-week window post-registration. A name similarity analysis further reveals that 25.2% of hallucinated names fall within an absolute edit distance of \(\leq\) 1 from existing npm packages, posing a direct typosquatting risk. In our evaluated setting, tool-augmented generation, specifically using web search, fails to mitigate this threat. Instead, it significantly amplifies hallucination persistence from 11.2% to 17.3% through context contamination. In the npm registry, the entire attack campaign costs only an estimated $496, making it far more accessible than traditional supply chain attacks yet capable of enabling poisoning effects. To mitigate this emergent threat, we design an autonomous defense agent: NymGuard. It provides a proactive defense by automating the real-time detection of hallucinated packages, their preemptive registration to block malicious use and the maintenance of a public warning registry. The full implementation has been open-sourced and is available on GitHub (https://github.com/xiaoye798/Package-Hallucination-Research).

View source

Similar papers

#software testing Book Open access Aug 2026

Evaluating Inference-Time Defenses against Package Hallucination in LLM-Generated Code

The results recast package hallucination as both a measurement problem and a decoding-time control problem, and they demonstrate that the choice of defense must be matched to the threat model and recommendation utility.

Albérick Euraste Djiré, I. E. Olatunji, Melissa Tessa et al. · 1 citation
Preprint Aug 2026

Names Can Hurt: Spotting Slopsquatting Risks Caused by Package Name Hallucinations in Local Coding LLMs

A two layer detector to counter'slopsquatting of Python package names, with findings that hallucination rate scales almost linearly with prompt adversariality, and when primary and fallback share a model family, approximately 84% of primary failures recur on the fallback, motivating cross family pairing.

Akash Raj, Sargam Sahu · 0 citations
Open access Jul 2026

Hallucination Mitigation in Large Language Model-Based Tool Recommendation: A Cross-Provider Architectural Ablation Study Across Two Model Generations

This work evaluates a three-mechanism mitigation stack consisting of database-grounded context injection, fixed vocabulary constraints, and enforced JavaScript Object Notation output across three commercial LLM providers, two model generations, and two output modes (standard and reasoning), totaling 6912 Application Pr...

Lavdim Menxhiqi, Galia Marinova · 0 citations
Book Open access Aug 2026

Evidencing LLM Misuse: A Hands-on Forensic Tutorial on Copyright Infringement and Plagiarism Detection

This tutorial presents a unified forensic perspective on LLM content misuse, combining hands-on copyright-risk auditing with a flexible plagiarism module, and equips attendees with practical and conceptual tools for auditing black-box models, interpreting similarity evidence, and understanding content misuse beyond sim...

Deng-Hui Zhang, Guangwei Zhang, Dongwon Lee · 0 citations
Conference Jul 2026

Is AI-Generated Web Code Vulnerability-Free?

With the increasing usage of AI-generated code in software development workflows, new security challenges and concerns arise. This paper analyzes five LLMs: ChatGPT, Claude, Gemini, DeepSeek, and Grok in three phases of security assessments against web vulnerabilities listed by the OWASP Top 10. Phase 1 (December 2025)...

Malak Mansour, Anas AlMajali · 0 citations

We use cookies to run the site and, with your consent, for analytics and to show ads. See our Cookie Policy.