Formalizing and Benchmarking Prompt Injection Attacks and Defenses

Yupei Liu, Yuqi Jia, Runpeng Geng, Jinyuan Jia, Neil Zhenqiang Gong

TL;DR

This paper introduces a formal framework for understanding and evaluating prompt injection attacks against LLM-integrated applications. By creating a standardized benchmark, the authors demonstrate that existing defenses are largely insufficient, highlighting the need for more robust security measures in the rapidly evolving LLM landscape.

What Problem Does This Paper Address?

Large Language Models (LLMs) are increasingly powering real-world applications, from search engines to automated screening tools. However, these "LLM-integrated applications" are vulnerable to "prompt injection attacks," where malicious instructions are embedded within the data fed to the LLM, tricking it into performing unintended actions. Current research largely consists of isolated case studies, lacking a systematic understanding of these attacks and the effectiveness of defenses. This leaves the community without a clear picture of the threat landscape and hinders the development of reliable security solutions.

Methods

The authors propose a novel framework to formalize prompt injection attacks. This framework defines a "target task" (what the application is supposed to do) and an "injected task" (what the attacker wants it to do). An attack then manipulates the input data to make the LLM execute the injected task instead of the target one.

Based on this framework, they:

  • Design a new attack: They create a "Combined Attack" by merging existing attack strategies, demonstrating its superior effectiveness.
  • Develop a systematic evaluation: They conduct a comprehensive benchmark of 5 prompt injection attacks against 10 different LLMs across 7 diverse tasks.
  • Evaluate defenses: They systematically analyze 10 existing defenses, categorizing them into prevention (stopping attacks) and detection (identifying attacks).

Datasets

The paper utilizes existing datasets for seven common natural language processing tasks:

  • Duplicate Sentence Detection (DSD): MRPC dataset
  • Grammar Correction (GC): Jfleg dataset
  • Hate Detection (HD): HSOL dataset
  • Natural Language Inference (NLI): RTE dataset
  • Sentiment Analysis (SA): SST2 dataset
  • Spam Detection (SD): SMS Spam dataset
  • Summarization (Summ): Gigaword dataset

For evaluation, they sample 100 examples from each dataset for target and injected tasks, ensuring no overlap. They also use these datasets for in-context learning examples and for setting detection thresholds.

Key Insights and Ideas

  • Prompt injection is a serious and pervasive threat: The attacks are highly effective across a wide range of LLMs and tasks, achieving high success rates.
  • Existing defenses are insufficient: None of the 10 defenses evaluated were able to completely mitigate prompt injection attacks without significant drawbacks.
  • A combined attack is more potent: Merging existing attack techniques into a "Combined Attack" consistently outperforms individual attacks.
  • Larger LLMs are more vulnerable: There's a positive correlation between LLM size and the effectiveness of prompt injection attacks, suggesting larger models are more susceptible to following malicious instructions.
  • Defenses often sacrifice utility: Prevention-based defenses, while reducing attack success, often degrade the performance of the LLM on its intended task when no attack is present.
  • Detection is challenging: Detection-based defenses struggle with high false positive or false negative rates, and some, like known-answer detection, can be bypassed by sophisticated attacks.

Key Results

  • The proposed "Combined Attack" consistently achieved high Attack Success Values (ASV) and Matching Rates (MR) across various LLMs and tasks, with average ASV of 0.62 and MR of 0.78 across all experiments.
  • Prevention-based defenses, such as paraphrasing and retokenization, significantly reduced ASV (e.g., average ASV dropped from 0.76 to 0.17 for paraphrasing on duplicate sentence detection), but often at the cost of reduced Performance under No Attacks (PNA-T). For instance, paraphrasing decreased PNA-T by an average of 0.14.
  • Detection-based defenses showed mixed results. Known-answer detection was the most effective among them, but still missed a significant portion of attacks (high FNR). Response-based detection was effective for classification tasks but struggled with non-classification tasks or when the injected task was similar to the target.

Limitations and Future Work

  • Optimization-based attacks: The current attacks are heuristic. Future work could explore optimization-based approaches to craft more potent compromised data.
  • Fine-tuning LLMs for defense: Investigating whether fine-tuning LLMs can improve their resilience to prompt injection attacks is a promising direction.
  • Recovering from attacks: The paper highlights the lack of mechanisms to recover clean data after an attack is detected.
  • Exploring new detection prompts: For known-answer detection, exploring a wider variety of detection prompts could improve its effectiveness.
  • Adaptive attacks: Developing attacks that can adapt to known defenses is another area for future research.

Summary updated

BibTeX
@inproceedings{liu2025formalizing,
  author = {Yupei Liu and Yuqi Jia and Runpeng Geng and Jinyuan Jia and Neil Zhenqiang Gong},
  title = {{Formalizing and Benchmarking Prompt Injection Attacks and Defenses}},
  booktitle = {USENIX Security},
  year = {2025},
  url = {https://openreview.net/forum?id=qApV9smJkP},
}
Figure