arXiv:2603.17174cs.CRcs.AI2026-03

通过结构分析检测代码生成大模型的投毒攻击

Detecting Data Poisoning in Code Generation LLMs via Black-Box, Vulnerability-Oriented Scanning

  • 基于多生成结果的结构相似性,抽象语法树去冗余
  • 97%以上准确率,误报率显著低于已有方法
  • 适合关注代码安全的开发与评测人员

代码生成大语言模型正广泛应用于现代软件开发流程。近期研究发现,这些模型易受后门和投毒攻击,导致生成不安全代码,但有效防御手段仍有限。现有扫描方法依赖标记级生成一致性来反推攻击目标,但在源码中因相同语义可呈现多样语法形式而失效。我们提出CodeScan,据知是首个专为代码生成模型设计的投毒检测框架。该方法通过分析不同干净提示下多次生成结果间的结构相似性,结合迭代分歧分析与抽象语法树(AST)归一化,消除表面差异,统一语义等价代码,从而识别出在多轮生成中持续出现的结构。随后利用大模型进行漏洞分析,若提取结构含安全漏洞,则判定模型被污染。我们在三种真实漏洞类别下,针对四种代表性攻击,在背门与投毒设置下评估了CodeScan。对108个跨三种架构及多种规模的模型进行实验,检测准确率达97%以上,且误报率显著低于先前方法。

原文摘要 · Abstract (English)

Code generation large language models (LLMs) are increasingly integrated into modern software development workflows. Recent work has shown that these models are vulnerable to backdoor and poisoning attacks that induce the generation of insecure code, yet effective defenses remain limited. Existing scanning approaches rely on token-level generation consistency to invert attack targets, which is ineffective for source code where identical semantics can appear in diverse syntactic forms. We present CodeScan, which, to the best of our knowledge, is the first poisoning-scanning framework tailored to code generation models. CodeScan identifies attack targets by analyzing structural similarities across multiple generations conditioned on different clean prompts. It combines iterative divergence analysis with abstract syntax tree (AST)-based normalization to abstract away surface-level variation and unify semantically equivalent code, isolating structures that recur consistently across generations. CodeScan then applies LLM-based vulnerability analysis to determine whether the extracted structures contain security vulnerabilities and flags the model as compromised when such a structure is found. We evaluate CodeScan against four representative attacks under both backdoor and poisoning settings across three real-world vulnerability classes. Experiments on 108 models spanning three architectures and multiple model sizes demonstrate 97%+ detection accuracy with substantially lower false positives than prior methods.

代码生成模型安全投毒检测漏洞分析

Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。