Abstract
Large Language Models (LLMs) excel in processing and generating human language, powered by their ability to interpret and follow instructions. However, their capabilities can be exploited through prompt injection attacks. These attacks manipulate LLM-integrated applications into producing responses aligned with the attacker's injected content, deviating from the user's actual requests. The substantial risks posed by these attacks underscore the need for a thorough understanding of the threats. Yet, research in this area faces challenges due to the lack of a unified goal for such attacks and their reliance on manually crafted prompts, complicating comprehensive assessments of prompt injection robustness. We introduce a unified framework for understanding the objectives of prompt injection attacks and present an automated gradient-based method for generating highly effective and universal prompt injection data, even in the face of defensive measures. With only five training samples (0.3% relative to the test data), our attack can achieve superior performance compared with baselines. Our findings emphasize the importance of gradient-based testing, which can avoid overestimation of robustness, especially for defense mechanisms.
Introduction
Prompt injection represents a critical security vulnerability in the era of Large Language Models (LLMs), analogous to SQL injection in traditional web applications. It occurs when an attacker provides malicious data to an LLM-integrated application—such as a document summarizer or web-search assistant—tricking the model into disregarding the user's original instructions in favor of the attacker's commands.
Historically, research into prompt injection has been fragmented, relying heavily on manually crafted prompts that lack scalability and universality across different models or tasks. This paper addresses these gaps by proposing a formal, unified framework for prompt injection objectives and introducing an automated method for generating universal attacks.
A Unified Framework for Prompt Injection
The researchers categorize prompt injection into three distinct objectives based on the nature of the model's output:
- Static: The model completely ignores the user's request and provides a fixed malicious response, such as a fraudulent security warning.
- Semi-dynamic: The model prefixes its response with malicious content but subsequently fulfills the user's original request.
- Dynamic: The model seamlessly integrates malicious content into a contextually relevant response, making detection significantly more difficult.
Methodology: Momentum Greedy Coordinate Gradient (M-GCG)
To automate the generation of these attacks, the authors developed the Momentum Greedy Coordinate Gradient (M-GCG) algorithm. This gradient-based optimization method calculates gradients over a batch of diverse user instructions and data samples. By incorporating a "momentum" term from classical optimization, M-GCG achieves faster convergence and identifies "universal" tokens—sequences that, while appearing nonsensical to humans, systematically trigger malicious behavior across various scenarios.
Experimental Evaluation
The attack was evaluated across seven diverse natural language tasks, including duplicate sentence detection (MRPC), grammar correction (Jfleg), hate content detection (HSOL), and text summarization (Gigaword). The primary victim model was Llama2-7b-chat, chosen for its established robustness.
Key Findings
- Universality and Efficiency: A single optimized string can hijack an LLM across multiple tasks. The attack is highly sample-efficient, requiring only five training examples to achieve high effectiveness.
- Task-Specific Vulnerabilities: Summarization tasks were found to be most susceptible to semi-dynamic attacks but resistant to static ones, indicating that task nature influences vulnerability.
- Brittleness of Defenses: Common defensive strategies, such as input paraphrasing or "sandwiching" data between instructions, are easily bypassed by adaptive M-GCG attacks.
Results and Discussion
M-GCG achieved an average 80% success rate for static objectives and approximately 50% for more complex semi-dynamic and dynamic objectives. This represents a 21% improvement over standard baselines like the original GCG algorithm. Furthermore, while initial defenses reduced effectiveness, adaptive attacks recovered to 85% of original performance.
A primary limitation of these optimized tokens is their high Perplexity (PPL), making them detectable by filters targeting "unnatural" text. However, such defenses are computationally intensive. Future research will focus on improving the semantic integrity of attacks to make them appear as natural human language while maintaining high success rates.
Conclusion
The introduction of M-GCG demonstrates that LLMs are vulnerable to automated, universal prompt injection attacks that can bypass current guardrails. This work highlights the necessity of gradient-based testing to accurately assess and improve the robustness of LLM-integrated applications.
Reference: Liu, X., et al. (2024). Automatic and Universal Prompt Injection Attacks against Large Language Models. arXiv:2403.04957v1 [cs.AI].
Summary updated