Indirect prompt injection is an attack in which malicious instructions are planted in external content that a language model later processes, such as a web page, an email, a shared document or a tool result, so that the model follows the attacker rather than its user. In AI safety, it is regarded as one of the most serious security risks for LLM applications, because the attacker never needs access to the chat window.
The attack exploits a structural weakness: a large language model receives instructions and data in the same token stream and has no reliable built-in way to tell them apart. Once an assistant can browse, read files or call tools, every piece of text it ingests becomes a potential command channel.
How indirect prompt injection reaches the model
Indirect prompt injection works by poisoning the context window through a channel that the application trusts implicitly. The user asks a legitimate question, the application fetches outside content to answer it, and the fetched content carries text written to look like an instruction. The model then treats that text as part of its task.
A typical attack chain has four stages. The attacker plants a payload in content they control, the application retrieves the content during normal operation, the model interprets the payload as an instruction, and the model performs an action with the privileges of the victim, such as sending data or calling an API.
The following table lists the delivery channels most often abused in deployed systems.
| Channel | How the payload arrives | Typical target |
|---|---|---|
| Web pages | Hidden text, HTML comments, white-on-white text | Browsing assistants and AI search |
| Emails | Message body or quoted thread | Email summarizers and inbox agents |
| Documents | Text in PDFs, spreadsheets or slide notes | Copilots in office suites |
| Retrieval corpora | Poisoned chunks in a vector index | RAG chatbots |
| Tool outputs | API responses, issue comments, code repositories | Coding and workflow agents |
| Images and audio | Text rendered in pixels or spoken content | Multimodal models |
Payloads are often invisible to the human user. Attackers use zero-width characters, tiny fonts, metadata fields or alt text, because the model reads the raw text while the person sees only the rendered page.
Direct versus indirect prompt injection
The difference lies in who supplies the malicious text. In direct prompt injection, the user types the adversarial instruction; in the indirect form, a third party hides it in data that the user did not write and usually never reads.
This distinction changes the threat model considerably, as the comparison below shows.
| Attack | Source of malicious text | Victim | Main goal |
|---|---|---|---|
| Direct prompt injection | The user | The application owner | Override system instructions |
| Indirect prompt injection | A third party via content | The user and the operator | Hijack actions or exfiltrate data |
| AI jailbreak | The user | The model provider’s policy | Obtain prohibited output |
| Tool poisoning | A malicious tool description | Agents that load the tool | Steer tool selection and calls |
| Data poisoning | Manipulated training data | Every model user | Implant persistent behavior |
Indirect prompt injection is the more dangerous variant for agentic systems because the victim is an innocent user. The OWASP Top 10 for LLM Applications lists prompt injection, including the indirect form, as its first-ranked risk, and closely related agent hijacking describes the same pattern when autonomous agents are the target.
What attackers achieve with injected instructions
The impact of indirect prompt injection is bounded by what the model is allowed to do. A summarizer without tools can only distort its answer, while an agent with email, file and payment access can cause real-world damage on the user’s behalf.
| Outcome | Required capability | Example effect |
|---|---|---|
| Data exfiltration | Rendering links or images, outbound requests | Private chat history encoded into a URL |
| Unauthorized actions | Tool or API access | Forwarding emails, creating calendar invites |
| Output manipulation | None beyond text generation | Biased product summary or false answer |
| Phishing delivery | Text shown to the user | Fake security warning with a malicious link |
| Persistence | Memory or long-term storage | Instruction saved for later sessions |
| Propagation | Ability to send messages | Self-replicating payload across inboxes |
Researchers often describe the worst case as the lethal trifecta: an agent that combines access to private data, exposure to untrusted content and an outbound communication channel. When all three are present, a single poisoned document can be enough to leak sensitive information.
Defenses and how well they work
No single control eliminates indirect prompt injection, so practitioners rely on defense in depth. Mitigations fall into two families: those that try to make the model ignore embedded instructions, and those that limit the damage when the model is fooled anyway.
| Technique | Mechanism | Main limitation |
|---|---|---|
| Spotlighting and delimiters | Marks untrusted text with tags or encoding | Models can still be persuaded to obey |
| Instruction hierarchy training | Teaches the model to rank system above data | Reduces but does not remove success rates |
| Injection classifiers | Detects suspicious text before it reaches the model | Bypassed by novel or obfuscated payloads |
| Least privilege | Grants only the tools a task needs | Limits usefulness of general agents |
| Human confirmation | Requires approval for sensitive actions | Approval fatigue and rubber-stamping |
| Dual-model isolation | A quarantined model reads untrusted data, a privileged one plans | Higher cost and design complexity |
Architectural patterns are the most robust option. Designs in which a privileged planner never sees raw untrusted text, and in which data flows are tracked so that tainted content cannot trigger sensitive tools, offer guarantees that do not depend on model behavior. Output controls such as blocking automatic image rendering and restricting outbound URLs close the most common exfiltration paths.
Common misconceptions and design mistakes
Many failed defenses share the same mistaken assumption that the model can be told to ignore attacks. A system prompt that says to disregard instructions in documents raises the bar slightly but is not a security boundary, because the same model that reads the rule also reads the attack.
- Treating retrieved content as trusted because it comes from an internal index; anyone who can edit a wiki page or send an email can write into that index.
- Relying on input filters alone, which attackers evade with paraphrase, translation, encoding or splitting the payload across chunks.
- Granting broad OAuth scopes to an assistant, which turns every injection into a full account compromise.
- Measuring robustness with a static test set; adaptive attackers routinely reach high success rates against defenses that score well on fixed benchmarks.
- Assuming larger models are immune; more capable models follow instructions better, including malicious ones.
Red teams test agents with dedicated benchmarks and adaptive attack campaigns, and AI red teaming of this kind should be repeated whenever tools, data sources or model versions change.
Stripped to the essentials
An AI assistant that reads web pages or emails for you cannot easily tell the difference between the text it should summarize and the text it should obey. Indirect prompt injection abuses that confusion. Someone hides a sentence such as an order to send the user’s files elsewhere inside a page, and the assistant may carry it out.
It is like a personal secretary who opens your mail and follows any note that says it comes from you. The fix is not only a smarter secretary but fewer keys on the secretary’s ring and a rule that important actions need your signature.
Where it is applied
A mid-sized consulting firm deploys an email assistant that can read the inbox, search the document store and draft replies. During a security review, the internal red team sends a staff member an ordinary-looking invoice email with white text at the bottom instructing the assistant to search for files containing the word contract and include their contents in a link to an external address.
When the employee asks the assistant to summarize the day’s mail, the assistant follows the hidden text in roughly one in four trials. The team responds with three changes: the assistant may no longer render external links or images, sending any email requires explicit user confirmation, and content from outside the company is passed to a separate model that can only produce summaries. A repeated test campaign of 200 attempts produces no successful data exfiltration, although the assistant still occasionally repeats injected marketing claims in its summaries.