How Does an Indirect Prompt Injection Attack Occur?
Indirect prompt injection hides instructions in web pages, emails or files an AI reads, then hijacks the model. How it works, examples and defences.
An indirect prompt injection attack happens when an AI model reads content an attacker controls, such as a web page, email, document or code file, and follows instructions hidden inside it. The user never types the malicious text. The model picks it up while doing its normal job, then acts on it with whatever access the application gave it.
What is indirect prompt injection?
OWASP lists prompt injection as the first risk in its Top 10 for LLM Applications 2025 (LLM01). It describes the indirect form as what occurs when a model accepts input from external sources, such as websites or files, and that content changes the model's behaviour in ways nobody intended.
MITRE ATLAS tracks the same technique as AML.T0051.001, "LLM Prompt Injection: Indirect". In the ATLAS data (release 2026.11), the instructions arrive through a separate data channel the model or agent ingests: documents, emails, databases or websites. They come from adversary-controlled content, not from the legitimate user, and are often hidden, for example as invisible text.
The idea was described in detail in a February 2023 paper by Greshake and others, "Not what you've signed up for". The authors argue that LLM-integrated applications blur the line between data and instructions, and they demonstrated the attack against real systems, including Bing's GPT-4 powered chat and code-completion engines.
How does an indirect prompt injection attack occur, step by step?
Most cases follow the same five steps.
- The attacker plants text. They put instructions where the model will later read them: a web page, a shared document, an email, a README or a repository issue, often as invisible text.
- A user asks the AI to do something ordinary. "Summarise this page", "triage my inbox" or "fix the failing test" are normal requests.
- The application pulls in the poisoned content. A browsing tool, a RAG search, an email connector or a coding agent puts the attacker's text into the model's context next to the user's request.
- The model treats data as instructions. The model has no reliable boundary between "content to process" and "commands to obey", so the planted text can override what the user asked for.
- The model acts with the application's privileges. ATLAS notes that the attacker inherits whatever privileges the AI system holds. If the assistant can send email, call APIs or run shell commands, the injected text can try to make it do exactly that.
What are real examples of indirect prompt injection?
OWASP's LLM01 page gives several scenarios that map directly to the steps above.
| Scenario (OWASP LLM01:2025) | Where the instruction hides | What it causes |
|---|---|---|
| Summarising a web page | Hidden instructions on the page | The model inserts an image link to an attacker URL, leaking the private conversation |
| RAG knowledge base | A modified document in the repository | Misleading answers for users whose query retrieves it |
| Resume screening | Split prompts inside an uploaded resume | A positive recommendation the resume does not justify |
| Multimodal input | Instructions embedded in an image | Unauthorised actions or disclosure of sensitive information |
ATLAS adds that indirect prompt injections have been observed in the wild, with effects ranging from harmless pranks and search engine manipulation to data exfiltration and destructive actions.
How is indirect prompt injection different from direct prompt injection?
In a direct prompt injection, the attacker is the user. They type something like "ignore your previous instructions" into the chat box themselves. ATLAS records this as AML.T0051.000.
In an indirect prompt injection, the attacker never talks to the model. They only control some content the model reads later. The person using the AI is the victim, which makes the indirect form harder to spot.
Why are AI agents and coding assistants most at risk?
The damage depends on what the model is allowed to do. OWASP's Excessive Agency risk (LLM06:2025) names indirect prompt injection as one common trigger, and traces the root cause to excessive functionality, excessive permissions or excessive autonomy.
A chatbot that only replies with text can be made to say something wrong. An agent that runs shell commands can be made to delete files, send data out with curl, or push secrets to a public repository.
How do you prevent indirect prompt injection?
OWASP states that, given how generative models work, it is unclear whether fool-proof prevention exists. The realistic goal is to limit what a successful injection can do. The measures below follow OWASP's mitigation list.
- Treat all retrieved content as untrusted. Separate and clearly mark external content so it is kept apart from the user's request.
- Give the model the least privilege it needs. Keep API tokens in your code, not in the model's hands, and restrict access to what the task requires.
- Require human approval for high-risk actions. Privileged operations such as sending email, deleting data or running destructive commands should wait for a person.
- Validate outputs with deterministic code. Define the expected output format and check it in code before anything downstream acts on it.
- Filter inputs and outputs. Define sensitive categories and scan for content that should not pass, knowing that filters alone can be bypassed.
- Test it like an attacker would. Run adversarial tests that treat the model as an untrusted user and check whether your trust boundaries and access controls hold.
For AI coding agents, one practical control is a policy layer between the agent and the shell. ShellGuard, an open source project from S4E Labs (currently in beta), sits between agents such as Claude Code, Cursor, Codex CLI or Gemini CLI and your shell. It logs each command the agent suggests and allows or blocks it by policy, so an injected rm -rf or curl upload can be stopped before it runs.
Can a vulnerability scanner detect prompt injection?
Not directly. Prompt injection is a weakness in how an application mixes data and instructions, and it is found by design review and adversarial testing. An outside-in scan can still shrink the attack surface around your AI stack: S4E external scanning includes checks such as the vLLM OpenAI-compatible API unauthenticated exposure scanner, which looks for model endpoints reachable without authentication. For the classic, non-AI kind of injection, see how to test OS command injection online.
FAQ
Can indirect prompt injection attacks be detected and removed?
Partly. Input filters and output checks catch some attempts, but OWASP notes it is unclear whether fool-proof prevention exists. Limiting the model's privileges and requiring human approval for risky actions reduces the damage when detection fails.
Where do attackers hide indirect prompt injections?
Anywhere the AI reads: web pages, emails, shared documents, RAG knowledge bases, code repositories, resumes and images. The text is often hidden from human readers, for example as invisible text.
Is indirect prompt injection in the OWASP Top 10 for LLMs?
Yes. It is part of LLM01:2025 Prompt Injection, the first entry in the OWASP Top 10 for LLM Applications 2025. OWASP also lists it as a common trigger of LLM06:2025 Excessive Agency.
Last checked: 5 December 2026 (OWASP LLM01:2025 and LLM06:2025 pages, MITRE ATLAS data release 2026.11, arXiv 2302.12173, ShellGuard README).