Research Papers 论文研究 4h ago Updated 30m ago 更新于 30分钟前 47

Names Can Hurt: Spotting Slopsquatting Risks Caused by Package Name Hallucinations in Local Coding LLMs 名称之痛:识别本地编码LLM中包名幻觉引发的Slopsquatting风险

The paper introduces "slopsquatting," a supply chain attack where adversaries pre-register PyPI packages with names matching hallucinated package names from code-generating LLMs A two-layer detector combines deterministic PyPI existence checks with a Random Forest classifier trained on ten features from package names and metadata An import name reconciler resolves mismatches between import names and pip install names (e.g., `import cv2` vs `pip install opencv-python`) The pipeline, embedded in a 首次系统定义"slopsquatting"攻击:LLM幻觉生成的Python包名可被恶意预注册于PyPI,转化为供应链投毒向量 提出两层检测架构:确定性PyPI存在性检查 + 基于10个特征的Random Forest分类器,配合导入名协调器解决import/pip名称不一致问题 嵌入LangGraph状态机实现温度递增重试与跨模型备用路由,300提示下76%生成无幻觉代码 幻觉率随提示对抗性线性增长(常规编码0-10% → slopsquat诱饵40-73%),同家族模型失败重复率达84% 用户研究(n=24)满意度4.4/5,87.5%表示采用意向

62
Hot 热度
72
Quality 质量
68
Impact 影响力

Analysis 深度分析

TL;DR

  • The paper introduces "slopsquatting," a supply chain attack where adversaries pre-register PyPI packages with names matching hallucinated package names from code-generating LLMs
  • A two-layer detector combines deterministic PyPI existence checks with a Random Forest classifier trained on ten features from package names and metadata
  • An import name reconciler resolves mismatches between import names and pip install names (e.g., import cv2 vs pip install opencv-python)
  • The pipeline, embedded in a LangGraph state machine with escalating retry temperatures and cross-model fallback, achieves hallucination-free code on 76% of runs across 300 curated prompts
  • Hallucination rates scale linearly with adversarial prompt intensity (0–10% routine to 40–73% on slopsquat baits), and cross-family model pairing significantly improves fallback recovery

Why It Matters

This research addresses a critical and emerging supply chain security threat as local coding LLMs become more widely deployed in development workflows. Slopsquatting exploits a gap where LLM hallucinations can be weaponized by malicious PyPI actors, making this directly relevant to anyone building or relying on AI-assisted code generation in production environments.

Technical Details

  • Two-layer detection architecture: Layer 1 performs a deterministic PyPI existence check; Layer 2 uses a Random Forest classifier trained on 10 features derived from package names and PyPI metadata to catch lookalike packages (e.g., pil, faiss, tabula, haystack)
  • Import name reconciler: Bridges the semantic gap between Python import names and PyPI distribution names, preventing security bypasses in cases like import cv2 / pip install opencv-python
  • LangGraph state machine: The detector is embedded in a retry loop with escalating temperatures; upon repeated failure, it routes to a stronger fallback model
  • Evaluation: Tested across 300 curated prompts; 76% hallucination-free rate, with 28.7% of primary model failures exhausting retry budget, ~25% recovered via intra-model retries, and 16.5% via cross-model fallback
  • Key empirical findings: ~50% of flagged hallucinations are real PyPI-registered lookalike packages; same-family model fallbacks repeat ~84% of primary failures, supporting cross-family pairing strategies

Industry Insight

  • Organizations deploying local coding LLMs should integrate package name validation pipelines into their development tooling before hallucination-driven supply chain attacks become commonplace
  • Cross-family model fallback strategies are essential—relying on the same model family for primary and fallback yields minimal recovery gains due to correlated failure modes
  • The near-linear relationship between adversarial prompt intensity and hallucination rate suggests that red-teaming coding LLMs with slopsquat-style prompts should become a standard security evaluation benchmark

TL;DR

  • 首次系统定义"slopsquatting"攻击:LLM幻觉生成的Python包名可被恶意预注册于PyPI,转化为供应链投毒向量
  • 提出两层检测架构:确定性PyPI存在性检查 + 基于10个特征的Random Forest分类器,配合导入名协调器解决import/pip名称不一致问题
  • 嵌入LangGraph状态机实现温度递增重试与跨模型备用路由,300提示下76%生成无幻觉代码
  • 幻觉率随提示对抗性线性增长(常规编码0-10% → slopsquat诱饵40-73%),同家族模型失败重复率达84%
  • 用户研究(n=24)满意度4.4/5,87.5%表示采用意向

为什么值得看

本文首次量化了本地编码LLM幻觉与PyPI供应链攻击的关联风险,填补了AI辅助编程安全领域的空白。提出的检测架构与重试机制为工业界落地提供了可直接集成的工程方案。

技术解析

  • 两层检测器设计:第一层执行确定性PyPI API查询验证包是否存在;第二层Random Forest分类器基于包名长度、字符分布、与知名包相似度等10个特征识别低质量模仿包(如pil、faiss、tabula、haystack)
  • 导入名协调器:桥接import cv2pip install opencv-python的命名差异,防止攻击者利用名称不匹配绕过检测
  • LangGraph状态机编排:检测器嵌入工作流,支持温度递增重试策略;主模型耗尽重试预算(28.7%)后,模型内重试恢复约25%,跨模型备用恢复剩余部分的16.5%
  • 跨家族配对建议:实验发现同家族模型(如不同尺寸的Llama系列)失败模式高度相关(84%重复率),强烈建议主备模型采用不同架构家族以提升检测覆盖率

行业启示

  • 供应链安全防线前移:slopsquatting揭示AI编程幻觉可被直接转化为攻击向量,建议将PyPI包名验证纳入CI/CD管道与IDE插件的安全扫描层
  • 多模型编排策略调整:同家族模型幻觉模式高度相似,企业部署多模型fallback架构时应优先选择跨架构组合(如Llama + Mistral + Qwen)而非同家族不同尺寸
  • 指令微调的防御边界:主模型能无辅助拒绝60%直接诱饵,表明当前SFT已提供基线防御,但对抗性提示仍需外部检测层补充,安全设计应采用"模型内生防御+外部验证"的双层架构

Disclaimer: The above content is generated by AI and is for reference only. 免责声明:以上内容由 AI 生成,仅供参考。

LLM 大模型 Code Generation 代码生成 Security 安全 Research 科学研究 Programming 编程