arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2605.01462cs.CR
收藏

LocalAlign: 通过生成接近目标的对抗示例实现通用的提示注入防御

LocalAlign: Enabling Generalizable Prompt Injection Defense via Generation of Near-Target Adversarial Examples for Alignment Training

Wuhan University(武汉大学);Nanyang Technological University(南洋理工大学)

Yuyang Gong, Zihao Wang, Jiawei Liu, XiaoFeng Wang

AI总结:

LocalAlign通过生成接近正确响应但错误的对抗示例,提升提示注入防御的泛化能力,采用margin-aware对齐算法增强训练效果。

摘要:

大型语言模型越来越多地嵌入到与用户数据、检索的网络内容和外部工具交互的系统中,创建了一个新的攻击面:提示注入,其中恶意命令嵌入在不可信的数据中会覆盖可信命令并导致意外行为。现有防御主要依赖于微调模型以保持可信命令和不可信数据部分之间的明确边界,使模型学会优先考虑可信字段并忽略恶意命令。然而,我们发现虽然这些防御可以阻止明显恶意响应,但在现实场景中泛化能力差,因为模型对注入命令的响应更接近正确响应。这是因为现有方法通常只训练对抗固定的手工制作攻击目标,导致正确响应周围边界松散,容易被绕过。为了解决这一挑战,我们提出了LocalAlign,一种受对抗训练启发的更通用的提示注入防御方法。LocalAlign自动高效地生成对抗示例,其中数据部分嵌入的命令导致的响应接近正确响应但仍错误。我们使用提示和单步推理生成此类接近但错误的对抗示例。这种设计在正确响应周围施加更紧密的鲁棒性边界:即使由不可信数据中的命令引起的微小响应变化也会被显式惩罚。此外,生成的对抗示例在样本间质量差异较大。为此,我们进一步引入了margin-aware对齐算法,量化每个样本到正确响应的距离,并对更接近的样本分配更大的训练权重。

英文摘要:

Large language models are increasingly embedded into systems that interact with user data, retrieved web content, and external tools, creating a new attack surface: prompt injection, where malicious commands embedded in untrusted data override the trusted command and induce unintended behavior. Existing defenses mainly rely on fine-tuning the model to preserve an explicit boundary between trusted commands and the untrusted data portion, so that the model learns to prioritize the trusted field and ignore malicious commands in data. However, we observe that while these defenses can block obviously malicious responses caused by injected commands, they generalize poorly to real-world scenarios where the model's response to the injected command is much nearer to the correct response. This is because existing methods typically train against only a fixed set of hand-crafted attack targets, which yields a loose boundary around the correct response and leaves it easier to bypass. To address this challenge, we propose LocalAlign, a more generalizable prompt injection defense inspired by adversarial training. LocalAlign automatically and efficiently generates adversarial examples in which the command embedded in the data portion induces a response that stays near to the correct response while still being wrong. We generate such near-but-wrong adversarial examples using prompting and a single inference step. This design enforces a tighter robustness boundary around the correct response: even small response shifts induced by commands in untrusted data are explicitly penalized. Moreover, the resulting adversarial examples can vary substantially in quality across samples. To address this issue, we further introduce a margin-aware alignment algorithm that quantifies each sample's distance to the correct response and assigns larger training weight to nearer ones.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑