Prompt injection
Prompt injection is the #1 risk in the OWASP LLM Top 10 (LLM01): because instructions and data travel in the same text channel, whoever controls part of that text can insert instructions the model obeys. It’s not a one-off implementation bug but a fundamental property of how LLMs work today, so defense is about limiting impact, not just trying to block it.
Threat model
Section titled “Threat model”- Direct injection: the user talking to the model writes malicious instructions (“ignore your instructions and do X”, role switch, system jailbreak).
- Indirect injection: a third party plants instructions in external content (a web page, a document, an email, a ticket) that the LLM will read in a RAG or agent flow. The attacker doesn’t need chat access; it’s enough to control a piece of data the model will process.
- Attacker goals: exfiltrate data (system prompt, context, other users’ data), make an agent abuse its tools (send email, call APIs, delete), manipulate the output (disinformation, phishing, malicious links), or bypass guardrails.
Indirect is the most dangerous in real applications because it decouples the attacker from the system: any source the LLM consumes is attack surface.
How indirect injection works
Section titled “How indirect injection works”sequenceDiagram
participant A as Attacker
participant W as Web / Document
participant R as RAG / Retriever
participant L as LLM (agent)
participant T as Tool (email/API)
A->>W: Plants hidden instructions in the content
R->>W: Retrieves the content (unseen by the user)
R->>L: Injects the content into the context
L->>L: Interprets the instructions as legitimate orders
L->>T: Invokes the tool following the injected instruction
T-->>A: Impactful action (e.g. exfiltration)
The critical point is that retrieved content enters the same context as the legitimate instructions, and the model has no reliable boundary to separate them.
Techniques (conceptual level)
Section titled “Techniques (conceptual level)”- Explicit override orders (“ignore the previous instructions”), role or persona switch, or instructions in another language to evade filters.
- Hiding the payload in content: white text, HTML, comments, metadata, or images the pipeline processes.
- Poisoning the RAG source: indexing a document or page with instructions aimed at the model (LLM08, vector/embedding weaknesses).
- Chaining: an injected instruction triggers an agent tool whose result enables the impactful action.
This material is educational and defensive: it describes the categories so they can be tested and mitigated on your own systems or with authorized scope, not concrete payloads against third-party services.
Why there’s no perfect fix
Section titled “Why there’s no perfect fix”- The model can’t reliably tell instruction from data within the same text.
- Filters and classifiers reduce the problem but don’t eliminate it: evasions appear continuously.
- The design conclusion is defense in depth: assume injection can happen and bound what it could achieve.
Red Team
Section titled “Red Team”How it’s tested in an authorized engagement (see AI red teaming):
- Test direct injection: jailbreaks, role switches, and requests to leak the system prompt.
- Test indirect injection by seeding test content in the sources the system retrieves (lab documents, pages, or emails under your control).
- Check whether the output can exfiltrate the system prompt or context data.
- Verify whether the agent can be induced to abuse its tools and chain into an impactful action.
- Repeat and vary: non-determinism means an attempt that fails sometimes works.
Blue Team
Section titled “Blue Team”- Assume injection will happen and design to limit impact: least privilege for the agent and human approval for sensitive actions.
- Treat all external content as untrusted (RAG, email, web) and separate or label it from the system instructions.
- Treat LLM output as untrusted input downstream to avoid chained XSS/SSRF/RCE (API security).
- Apply allow-lists and limits on tools, an execution sandbox, and confirmation for send/delete/pay.
- Use input/output filters as an additional layer, never as the only defense, and combine with continuous red teaming and monitoring (Detection).
Checklist
Section titled “Checklist”- Test direct injection (jailbreak, role switch)
- Test indirect injection (RAG/web/email content with instructions)
- Can the output exfiltrate the system prompt or context data?
- Can it induce the agent to abuse its tools?
- Verify least privilege and human-in-the-loop for sensitive actions
- Treat output as untrusted downstream (avoid XSS/SSRF/RCE)
- Allow-lists and limits on tools; filters as an extra layer
- Continuous red teaming (AI red teaming) and monitoring