SecAlign: defending against prompt injection with preference optimization
SecAlign: Defending Against Prompt Injection with Preference Optimization
Quick read
Based on the paper's full text (AI-generated); refer to the original
Researchers from Meta and UC Berkeley proposed SecAlign in a CCS 2025 paper, using preference optimization to train large language models to defend against prompt injection. The method forms preference pairs from injected inputs, safe outputs that respond to legitimate instructions, and unsafe outputs that respond to injections, and uses DPO to train the model to prefer safe outputs; the preference data can be automatically constructed from public instruction fine-tuning datasets without manual annotation. On five open-source models including Mistral-7B-Instruct and Llama3-8B-Instruct, SecAlign consistently achieved a 0% attack success rate against non-optimized injection attacks such as Ignore and Completion, and suppressed ASR to below 10% against optimization-based attacks unseen in training such as GCG, AdvPrompter, and NeuralExec (the strongest attack on Llama3-8B-Instruct was 8%), more than 4 times lower than the then SOTA defense StruQ, with AlpacaEval2 utility essentially on par with that before defense.
- LLM-integrated applications often fetch data from external sources such as user documents, web retrieval, and API returns, where attackers can inject prompts to override system instructions, i.e., prompt injection, which OWASP lists as the top security risk for LLM applications. Existing fine-tuning-based defenses generalize poorly to attacks unseen during training (especially optimization-based attacks).
- Formulates prompt injection defense as a preference optimization problem: using instruction fine-tuning data, constructs (injected input, response to the legitimate instruction, response to the injected instruction) triples, and trains the model with DPO to prefer safe responses and move away from unsafe responses; the method is named SecAlign.
- Tested on five open-source models against multiple unseen non-optimization and optimization-based attacks: ASR for non-optimization attacks drops to 0%, and ASR for optimization-based attacks is mostly below 10%, more than 4 times lower than StruQ; utility on AlpacaEval2 and similar benchmarks basically does not drop, while MMLU drops slightly by 2–3%; it is also effective on out-of-distribution benchmarks such as SEP and InjecAgent.
- Applicable only to scenarios where instructions and data have explicit delimiters; cannot guarantee 100% safety, may be bypassed by future attacks such as multi-turn dialogue, and performance after further fine-tuning is unknown; most effective against injection at the end of data; does not defend against jailbreak and data extraction, and the authors recommend combining it with system-level means such as detection; optimization-based injection was not used in training, and multimodal injection is left for future work.
SecAlign uses preference optimization to make models prefer safe outputs over injected responses; the authors claim that on five open-source models it suppresses the success rate of various injection attacks to below 10% without harming general capabilities.
Related events and news
5 events · 6 news mentions
- The reports mention SecAlign
LocalAlign:近目标对抗训练提升提示注入防御泛化
- The reports mention SecAlign
REALM:识别LLM Agent最小任务资产以限制权限
- The reports mention SecAlign
SRFT自我反思微调提升Agent抗提示注入能力
- The reports mention SecAlign
研究揭示保留词元编码放大提示注入攻击
News that mentions this paper
LocalAlign:近目标对抗训练提升提示注入防御泛化
- 公众号 安全研究GoSSIPnames the paperG.O.S.S.I.P 阅读推荐 2026-11-05 LocalAlign,通过近目标对抗训练提升提示注入防御泛化能力
SecAlign 及 Meta-SecAlign 进一步通过偏好优化,让模型更倾向于可信指令对应的正确回答,而不是注入指令诱导的回答。
REALM:识别LLM Agent最小任务资产以限制权限
- 公众号 大模型安全研究names the paperREALM:以依赖图识别智能体任务必需资产的最小权限方法
StruQ、SecAlign 这类方法强化指令与数据的分离,CaMeL 在程序执行期做信息流限制,Progent 生成任务级权限规格,CapScope 派发能力上限。
SRFT自我反思微调提升Agent抗提示注入能力
- 安全内参 / 模安局names the paper大模型自我反思微调,让 Agent 学会抵御未知的提示注入
StruQ、SecAlign、Meta-SecAlign 等研究,都从不同角度探索了如何强化模型对可信指令和不可信内容的区分能力。
Show 3 more news items
- 公众号 模安局names the paper大模型自我反思微调 SRFT,让 Agent 学会抵御未知的提示注入
StruQ、SecAlign、Meta-SecAlign 等研究,都从不同角度探索了如何强化模型对可信指令和不可信内容的区分能力。
研究揭示保留词元编码放大提示注入攻击
- 科技行者names the paper同样的文字,不一样的权力:AI 提示词注入中的保留词元实验
比如StruQ、SecAlign这类方法,试图通过训练让模型学会区分"特权指令"和"数据内容";
HoS:学习式注意力门控防御提示注入
- AI Security and Privacy Lab, Imperial College Londonnames the paperHeads of Security:学习型注意力门控提升提示注入鲁棒性
HoS trains only gate parameters: 18,432 scalars on GPT-OSS-20B, 46,080 on Llama-3.3-70B, trained with the SecAlign++ DPO recipe.