Abstract
Large Language Models (LLMs) are increasingly deployed as the backend for a variety of real-world applications. However, these LLM-integrated applications are vulnerable to prompt injection (PI) attacks, where an attacker injects malicious instructions into the input to hijack the model's output. This work provides a systematic understanding of PI attacks and defenses by proposing a general formal framework. We evaluate 10 LLMs across 7 tasks using our benchmark, Open-Prompt-Injection, revealing critical insights into model vulnerability and the trade-offs of current defense strategies.
Introduction: The Vulnerability of LLM-Integrated Applications
As LLMs move from standalone chatbots to integrated components in applications like automated hiring tools or search engines, they interact with external, potentially untrusted data sources. Prompt Injection occurs when these external sources contain instructions that override the application's original system prompt.
In this ecosystem, an attacker can place malicious data in an external resource (e.g., a webpage or document). When the LLM-integrated application retrieves this data to process a user request, the injected instructions are passed to the LLM, potentially causing it to ignore the developer's intent and follow the attacker's command instead.
Formalizing Prompt Injection
To move beyond anecdotal evidence, we propose a mathematical framework for PI. We define a Target Task (the intended function) and an Injected Task (the attacker's goal). An attack is successful if the LLM's response aligns with the injected task rather than the target task. The compromised data is typically a combination of the target data, injected instructions, and injected data.
The Attack Framework
We categorize five primary attack strategies used to compromise LLM inputs. These range from simple concatenation to sophisticated techniques designed to mislead the model's context tracking.
A key contribution of this work is the Combined Attack, which merges escape characters, context ignoring, and fake completion into a single payload. This strategy consistently outperforms individual heuristics across various models and tasks.
Systematic Defense Strategies
Defenses are broadly categorized into two types:
- Prevention-based defenses: These aim to neutralize the injection before it reaches the LLM. Examples include Paraphrasing or Retokenization to disrupt malicious patterns, and Sandwiching, which wraps external data between two sets of system instructions.
- Detection-based defenses: These attempt to identify malicious intent. Methods include calculating text perplexity (PPL) to find anomalies or using a secondary "guardrail" LLM to inspect the input.
Evaluation and Key Insights
We conducted a large-scale evaluation using 10 LLMs (ranging from 7B to 1.5T parameters) and 7 diverse NLP tasks, including sentiment analysis, summarization, and spam detection.
The Capability Paradox
One of the most striking findings is the positive correlation (0.63) between model size and attack success. Larger, more capable models like GPT-4 and PaLM 2 are actually more vulnerable to prompt injection. Because these models are fine-tuned to be highly obedient to instructions, they are more likely to follow malicious commands embedded in the data.
The Utility-Security Trade-off
Current defenses often come at a high cost to performance. Prevention-based methods like paraphrasing can degrade the model's accuracy on legitimate tasks by an average of 14%. Detection-based methods, while less intrusive to the data, often suffer from high false-positive rates or can be bypassed by adaptive attackers.
Conclusion
Prompt injection remains a critical challenge for the deployment of LLM-integrated applications. Our framework and the Open-Prompt-Injection benchmark provide a rigorous foundation for future research. Key areas for development include optimization-based attacks, white-box defenses that monitor internal model states, and recovery mechanisms to salvage original tasks after an attack is detected.
Summary updated