相同字节,不同权限:聊天模板提示注入中的保留令牌表示

·

研究论文 · 2026/09/30

当注入的指令被包装在模型自身的聊天模板中时,针对LLM代理的提示注入会变得更强。一个伪造的模板标记如<|im_start|>可以以单个保留控制令牌或一系列普通子词令牌的形式到达模型。两者解码为完全相同的文本,并且由于分词在服务器上运行,防御者而非攻击者决定模型接收哪一种。我们利用这一点来测量注入指令的权威有多少来自保留令牌的学习表示。将伪造标记编码为子词,保持文本固定并控制由此增加的额外令牌,在InjecAgent基准上,四个开放权重家族中的三个攻击成功率降低了39到66个百分点,并且这一差距延续到AgentDojo中的多轮代理任务。在Qwen3-8B上,差距为8个百分点,因为如果没有保留ID,模型仍然通过推理从文本中识别出伪造的回合;抑制推理块将差距扩大到50个百分点。权威存在于标记位置的单个学习向量中:标记的子词向量的均值无法重现它,最近普通令牌的向量在Llama-3.1上恢复了攻击,而一个搜索非保留标记的自适应攻击者在四个家族中的三个上找到了这样的嵌入邻居。在我们测试的每个基础和指令调优对中,指令调优都增强了模型对保留标记的偏好。标准缓解措施,即一种将特殊令牌编码为普通子词的分词器选项,仅适用于配置声明为特殊的令牌,因此在67个不同分词器配置中的33个中,覆盖了Hugging Face上400个下载最多的聊天模型中的255个,它保留了代理通过其读取不可信工具输出的工具协议令牌,并且差距在该通道上持续存在。

这项研究揭示了聊天模板提示注入中保留令牌表示的关键作用,挑战了标准防御措施的有效性,对LLM代理安全有重要启示。

Prompt injection against LLM agents becomes much stronger when the injected instruction is wrapped in the model's own chat template. A forged template marker such as <|im_start|> can reach the model either as a single reserved control token or as a sequence of ordinary subword tokens. The two decode to exactly the same text, and because tokenization runs on the server, the defender rather than the attacker decides which one the model receives. We use this to measure how much of the injected instruction's authority comes from the reserved token's learned representation. Encoding the forged markers as subwords, with the text held fixed and a control for the extra tokens this adds, lowers attack success on the InjecAgent benchmark by 39 to 66 percentage points on three of four open-weight families, and the gap carries over to multi-turn agent tasks in AgentDojo. On Qwen3-8B the gap is 8 points, because without reserved ids the model still recognises the forged turn from its text by reasoning; suppressing the reasoning block widens the gap to 50. The authority sits in the single learned vector at the marker position: the mean of the marker's subword vectors does not reproduce it, the vector of the nearest ordinary token restores the attack on Llama-3.1, and an adaptive attacker who searches for non-reserved markers finds such embedding neighbours on three of four families. In every base and instruction-tuned pair we test, instruction tuning strengthens the model's preference for reserved markers. The standard mitigation, a tokenizer option that encodes special tokens as ordinary subwords, applies only to tokens a configuration declares special, so in 33 of 67 distinct tokenizer configurations, covering 255 of the 400 most-downloaded chat models on Hugging Face, it leaves intact the tool-protocol tokens through which agents read untrusted tool output, and the gap persists on that channel.

阅读原文

参与讨论