三层次防护框架有效抵御RAG聊天机器人中的提示注入攻击
A Layered Security Framework Against Prompt Injection in RAG-Based Chatbots

- 分三层拦截直接与间接提示注入,覆盖整个推理流程
- 在三种模型上将攻击成功率从71.4%降至11.3%,误报率仅4.8%
- 无需修改大模型,可作为中间件部署,适合安全敏感场景
提示注入被OWASP LLM应用十大漏洞列为最严重威胁,但现有防御局限于单一处理阶段且不完整。输入过滤无法检测检索文档内容,输出监控也无法阻止恶意载荷进入模型。因此,检索增强生成(RAG)聊天机器人仍易受间接注入攻击——被污染的知识库文档会危害所有检索到它的用户。本文提出一个三层框架,在推理全流程中拦截直接与间接提示注入。第一层使用规则模式库和微调的语义异常分类器筛查用户输入;第二层在上下文组装时采用基于来源的指令优先级机制,防止检索内容覆盖操作员策略;第三层在交付前用策略规则引擎与语义漂移检测器审计模型输出。持续审计循环收集结构化日志并支持分类器重训练以应对新型攻击。该框架模型无关,可作为中间件部署。在GPT-4o、Llama 3和Mistral 7B上对5,080个样本的评估显示,攻击成功率从71.4%降至11.3%,优于最佳单层基线27.3个百分点,优于已发表防护系统23.8个百分点,误报率4.8%,平均延迟增加61.2毫秒。消融实验证明三层防护具有互补性,联合效果超过各层之和。
原文摘要 · Abstract (English)
Prompt injection is ranked as the most critical vulnerability in large language model (LLM) deployments by the OWASP Top 10 for LLM Applications, yet existing defenses operate at isolated pipeline stages and remain incomplete. Input filters cannot inspect retrieved documents, while output monitors cannot prevent malicious payloads from reaching the model. Consequently, retrieval-augmented generation (RAG) chatbots remain vulnerable to indirect injection, where a poisoned knowledge-base document compromises every user whose query retrieves it. We present a three-layer framework that intercepts both direct and indirect prompt injection throughout the inference pipeline. Layer 1 screens user input using a rule-based pattern library and a fine-tuned semantic anomaly classifier. Layer 2 enforces a provenance-based instruction hierarchy during context assembly, preventing retrieved content from overriding operator policy. Layer 3 audits model output using a policy rule engine and semantic drift detector before delivery. A continuous audit loop aggregates structured logs and supports retraining to adapt the classifier to emerging attack patterns. The framework is model-agnostic and deploys as middleware without modifying the underlying LLM. Evaluation on 5,080 samples across GPT-4o, Llama 3, and Mistral 7B shows that the framework reduces Attack Success Rate (ASR) from 71.4\% to 11.3\%, outperforming the best single-layer baseline by 27.3 percentage points and a published guardrail system by 23.8 percentage points, while maintaining a 4.8\% false positive rate and a median latency overhead of 61.2 ms. Ablation studies confirm that all three layers provide complementary protection and that their combined effect exceeds the sum of individual contributions.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。