SecPO: Principled Adversarial Training for Prompt Injection Security

LLM DPO AI Safety / AI Ethics PIAAP RA
2026年10月30日
提示注入攻击被公认为对人工智能代理(AI agents)最严重的威胁之一,它允许来自不可信数据源(如电子邮件、文档、网站)的指令操控代理的运行行为。目前防御效果最佳的大语言模型 Meta-SecAlign 虽然采用直接偏好优化(DPO)损失函数进行训练,但在面对自适应式提示注入攻击时,其攻击成功率(ASR)仍高达近100%。其原因之一在于:DPO 以一个未经防护的参考模型为锚点进行优化,而该参考模型本身即存在安全缺陷。我们指出,一种理想化的参考模型——即具备“注入不变性”且能保持任务效用的“神谕模型”(oracle)——尽管看似难以实现,却可在训练过程中被有效逼近;其关键洞见在于:该理想化参考模型在训练阶段的输出分布实际上可通过特定方式获得。这一新发现为构建具有严格理论依据的“安全偏好优化”(SecPO)损失函数提供了基础。 Meta-SecAlign 的另一项不足在于,其训练过程仅依赖于较弱的模拟攻击样本。为此,我们设计并实现了高效对抗训练(AT)流程,可自动生成强鲁棒性的注入式输入(在240次采样中选取最优者),并以此对模型进行训练。相较于 Meta-SecAlign,我们的对抗训练策略在三种当前最先进的自适应攻击下,将攻击成功率降低了1.5至14.5倍;而进一步引入 SecPO 损失函数(替代原有 DPO 损失)后,攻击成功率又额外下降了2.4至4.6倍。在实际代理工作流(agentic workflows)评估中,我们基于 Qwen3.6-27B 构建的 SecPO + AT 防御模型展现出显著更强的安全性:在“攻击者后手”(AttackerMovesSecond)攻击场景下,其在 AgentDojo 基准上的 ASR@800 指标仅为8.8%,远低于 Meta-SecAlign 的78.8%。此外,该防御模型在涵盖代理式工具调用、指令遵循、科学推理与数学能力等九大基准测试中,均未表现出任何可察觉的良性任务性能下降。我们已开源全部代码、训练数据集(含对抗训练所优化生成的高质量注入样本)及最终模型,相关资源分别发布于:[GitHub 代码仓库](//github.com/Sizhe-Chen/SecPO)、[Hugging Face 训练数据集](//huggingface.co/datasets/Sizhe-Chen/Qwen3.6-27B-Instruct-SecPO-trainset) 和 [Hugging Face 模型页](//huggingface.co/Sizhe-Chen/Qwen3.6-27B-Instruct-SecPO)。
Recognized as a top threat to AI agents, prompt injection allows instructions from untrusted data (email, documents, websites) to manipulate the agent's operation. The existing best-defended LLM, Meta-SecAlign, is trained with the DPO loss but still suffers from attack success rates (ASRs) approaching 100% under adaptive prompt injections. One reason is that DPO anchors the model around the undefended reference model, which is insecure. We show an idealized reference model---an injection-invariant, utility-preserving oracle---can nevertheless be approximated, as its output distribution in training is interestingly accessible. This new observation motivates a theoretically principled SecPO loss. Another Meta-SecAlign shortcoming is that it trains on weak simulated attacks. We implement an efficient adversarial training (AT) pipeline that synthesizes strong injected inputs (best@240), and train the model on them. Our AT reduces ASRs by 1.5-14.5$\times$ across three SoTA adaptive attacks, compared with Meta-SecAlign; the SecPO loss reduces them by a further 2.4-4.6$\times$ compared with using DPO loss. In agentic workflows, our SecPO + AT Qwen3.6-27B is much more secure than Meta-SecAlign: 8.8% vs. 78.8% AgentDojo ASR@800 under the AttackerMovesSecond attack. Moreover, our defended model shows no noticeable reduction in benign utility in nine benchmarks covering agentic tool calling, instruction following, science, and math. We release our $\href{//github.com/Sizhe-Chen/SecPO}{\text{code}}$, $\href{//huggingface.co/datasets/Sizhe-Chen/Qwen3.6-27B-Instruct-SecPO-trainset}{\text{training data}}$ (with optimized injections from AT), and $\href{//huggingface.co/Sizhe-Chen/Qwen3.6-27B-Instruct-SecPO}{\text{model}}$.
许愿