Skip to content

SecAlign: defending against prompt injection with preference optimization

SecAlign: Defending Against Prompt Injection with Preference Optimization

arXiv· arXiv:2410.05451· ACM CCS 2025· Sizhe Chen, Arman Zharmagambetov, Saeed Mahloujifar, Kamalika Chaudhuri, David Wagner, Chuan Guo·Indexed by this site · 16 days ago· Originally publishedSelected DefensesSelectedAttention38

Quick read

Based on the paper's full text (AI-generated); refer to the original

AI summaryResearchers 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.

Questions
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).
Methods
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.
Experiments and results
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.
Limitations and future work
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.
Why it was selectedSecAlign 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.

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

News that mentions this paper

LocalAlign:近目标对抗训练提升提示注入防御泛化

REALM:识别LLM Agent最小任务资产以限制权限

SRFT自我反思微调提升Agent抗提示注入能力

Show 3 more news items

研究揭示保留词元编码放大提示注入攻击

HoS:学习式注意力门控防御提示注入

Read originalACM CCS 2025