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

用少量防御性令牌防御提示注入攻击

Defending Against Prompt Injection With a Few DefensiveTokens

Sizhe Chen, Yizhu Wang, Nicholas Carlini, Chawin Sitawarin, David Wagner

AI总结:

本文提出 DefensiveToken,一种测试时防御方法,通过插入少量经安全优化的特殊令牌,在不显著降低模型效用的情况下抵御提示注入攻击,并支持安全与效用的灵活切换。

摘要:

当大语言模型(LLM)系统与外部数据交互以执行复杂任务时,一种新的攻击——提示注入——成为重大威胁。通过在系统访问的数据中注入指令,攻击者能够用其指定的任意任务覆盖最初的用户任务。为保障系统安全,测试时防御(例如防御性提示)已被提出,使系统开发者能够以灵活的方式仅在需要时获得安全性。然而,它们的效果远不如改变模型参数的训练时防御。受此启发,我们提出 DefensiveToken,这是一种测试时防御方法,其提示注入鲁棒性可与训练时替代方案相媲美。DefensiveToken 作为特殊令牌被新插入,其嵌入针对安全性进行优化。在安全敏感场景中,系统开发者可以在 LLM 输入前附加少量 DefensiveToken,以最小的效用下降实现安全性。在安全性不太受关注的场景中,开发者可以简单地跳过 DefensiveToken;LLM 系统保持与无防御时相同,生成高质量响应。因此,DefensiveToken 如果与模型一同发布,可在测试时灵活切换最先进(SOTA)效用与接近 SOTA 的安全性。代码可在 https://github.com/Sizhe-Chen/DefensiveToken 获取。

英文摘要:

When large language model (LLM) systems interact with external data to perform complex tasks, a new attack, namely prompt injection, becomes a significant threat. By injecting instructions into the data accessed by the system, the attacker is able to override the initial user task with an arbitrary task directed by the attacker. To secure the system, test-time defenses, e.g., defensive prompting, have been proposed for system developers to attain security only when needed in a flexible manner. However, they are much less effective than training-time defenses that change the model parameters. Motivated by this, we propose DefensiveToken, a test-time defense with prompt injection robustness comparable to training-time alternatives. DefensiveTokens are newly inserted as special tokens, whose embeddings are optimized for security. In security-sensitive cases, system developers can append a few DefensiveTokens before the LLM input to achieve security with a minimal utility drop. In scenarios where security is less of a concern, developers can simply skip DefensiveTokens; the LLM system remains the same as there is no defense, generating high-quality responses. Thus, DefensiveTokens, if released alongside the model, allow a flexible switch between the state-of-the-art (SOTA) utility and almost-SOTA security at test time. The code is available at https://github.com/Sizhe-Chen/DefensiveToken.

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

↑