arXiv:2410.05451cs.CRcs.LG2024-10被引 199

用偏好优化提升大模型抗提示注入能力,成功率低于10%。

SecAlign: Defending Against Prompt Injection with Preference Optimization

  • 构建含恶意注入的偏好数据集,训练模型偏好安全输出
  • 对多种复杂攻击防御成功率达90%以上,未知攻击也有效
  • 保持模型实用性能,适合部署于真实系统中

大型语言模型(LLMs)在现代软件系统中广泛应用,常通过用户文档、网络检索、API调用等外部数据源完成任务。这为攻击者提供了通过提示注入操控模型的机会,恶意提示可覆盖原指令并执行非法操作。为应对这一威胁,本文提出基于偏好优化的防御方法SecAlign。该方法首先构建包含注入输入、安全输出(符合原始指令)和不安全输出(响应注入指令)的偏好数据集,然后在此基础上进行偏好优化,使模型倾向于选择安全输出。实验表明,该方法将各类提示注入攻击的成功率降至10%以下,且对训练时未见过的更复杂攻击仍具强泛化能力。同时,经防御训练后的模型在实用性上与原始模型相当。代码已开源。

原文摘要 · Abstract (English)

Large language models (LLMs) are becoming increasingly prevalent in modern software systems, interfacing between the user and the Internet to assist with tasks that require advanced language understanding. To accomplish these tasks, the LLM often uses external data sources such as user documents, web retrieval, results from API calls, etc. This opens up new avenues for attackers to manipulate the LLM via prompt injection. Adversarial prompts can be injected into external data sources to override the system's intended instruction and instead execute a malicious instruction. To mitigate this vulnerability, we propose a new defense called SecAlign based on the technique of preference optimization. Our defense first constructs a preference dataset with prompt-injected inputs, secure outputs (ones that respond to the legitimate instruction), and insecure outputs (ones that respond to the injection). We then perform preference optimization on this dataset to teach the LLM to prefer the secure output over the insecure one. This provides the first known method that reduces the success rates of various prompt injections to <10%, even against attacks much more sophisticated than ones seen during training. This indicates our defense generalizes well against unknown and yet-to-come attacks. Also, SecAlign models are still practical with similar utility to the one before defensive training in our evaluations. Our code is at https://github.com/facebookresearch/SecAlign

大模型安全提示注入偏好优化

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