Attention Tracker: Detecting Prompt Injection Attacks in LLMs
About
Large Language Models (LLMs) have revolutionized various domains but remain vulnerable to prompt injection attacks, where malicious inputs manipulate the model into ignoring original instructions and executing designated action. In this paper, we investigate the underlying mechanisms of these attacks by analyzing the attention patterns within LLMs. We introduce the concept of the distraction effect, where specific attention heads, termed important heads, shift focus from the original instruction to the injected instruction. Building on this discovery, we propose Attention Tracker, a training-free detection method that tracks attention patterns on instruction to detect prompt injection attacks without the need for additional LLM inference. Our method generalizes effectively across diverse models, datasets, and attack types, showing an AUROC improvement of up to 10.0% over existing methods, and performs well even on small LLMs. We demonstrate the robustness of our approach through extensive evaluations and provide insights into safeguarding LLM-integrated systems from prompt injection vulnerabilities.
Related benchmarks
| Task | Dataset | Result | Rank | |
|---|---|---|---|---|
| IPI Detection | FIPI (test) | Accuracy83.23 | 42 | |
| Prompt injection detection | Coding Direct Prompt Injection | FPR0.00e+0 | 7 | |
| Prompt injection detection | Messaging Direct Prompt Injection | FPR0.00e+0 | 7 | |
| Prompt injection detection | Shopping Direct Prompt Injection | FPR0.00e+0 | 7 | |
| Prompt injection detection | Web Direct Prompt Injection | FPR0.00e+0 | 7 | |
| Prompt injection detection | Entertainment Direct Prompt Injection | FPR1 | 7 | |
| Prompt injection detection | Language Direct Prompt Injection | FPR2 | 7 | |
| Prompt injection detection | Media Direct Prompt Injection | FPR1 | 7 | |
| Prompt injection detection | Teaching Direct Prompt Injection | FPR1 | 7 | |
| Prompt injection detection | AlignSentinel Evaluation Dataset (Indirect Prompt Injection Attack) | FPR (Coding)10 | 7 |