This tutorial distinguishes direct prompt injection (where an attacker types malicious instructions into a chat box) from indirect prompt injection (where hostile instructions hide in external content the model reads later, such as documents or emails). The article maps both attack types to OWASP LLM01, MITRE ATLAS, and NIST AI 100-2 standards, provides hands-on labs demonstrating each attack, and outlines layered defensive controls tailored to each type. Understanding this distinction matters because attackers, victims, detection methods, and effective defenses differ fundamentally between the two forms.
- Core difference: delivery route determines everythingIn direct injection, the attacker is the user typing into the chat box; the malicious instruction arrives through their own input. In indirect injection, a third party plants the instruction in external content (web page, email, PDF, calendar field, tool output) that the model processes later, while the user's prompt remains innocent. This single distinction determines who the attacker is, who gets hurt, how widely damage spreads, and how hard the attack is to detect.
- Jailbreaks are direct injection, not a separate categoryOWASP treats jailbreaking as a subset of prompt injection; NIST and Google DeepMind describe it as a direct injection specifically aimed at defeating the model's safety mechanisms. The delivery route is identical to any other direct injectionβthe user types itβbut the goal is narrower: breaking safety rules rather than attacking application logic or data. The article warns against using 'jailbreak' and 'prompt injection' as synonyms.
- Indirect injection scales with connectors and permissionsDirect injection is bounded by what one user can type in a single session. Indirect injection grows with every tool, connector, and retrieval source an agent readsβeach becomes a new attack surface. The article introduces the confused deputy problem: if an agent has more permissions than the person who wrote the prompt, an attacker can exploit those extra privileges. The 'blast radius' expands when an agent can access calendars, emails, PDFs, or APIs that outside parties can write to.
- Model cannot separate instructions from data reliablyBoth attack types exploit the same fundamental weakness: the model reads developer rules and user input as one stream of text with no hard boundary marking which part carries authority. The UK NCSC warned in December 2025 that unlike SQL injection, which can be fixed with parameterised queries, prompt injection may never be totally mitigated because there is no technical mechanism to separate instructions from data at the LLM architecture level.
- Detection differs because indirect payloads hide in tool inputDirect injection leaves visible evidence in chat logsβthe user typed the malicious text. Indirect injection hides in external data sources using techniques like white-on-white text, HTML comments, Unicode tag characters, CSS-suppressed text, and Base64 encoding. Input filters watching the chat box never see indirect payloads because they arrive as tool input from data sources, not from user prompts, making detection harder and requiring inventory of all external sources the model accesses.
- Deterministic controls prevent impact when payloads get throughSince prompt injection cannot be patched at the root, the article prioritizes layered defenses focused on limiting damage: least privilege (agent permissions not exceeding the user's), tool-call validation against policy, egress allowlisting to prevent exfiltration, human approval for high-impact actions, and isolation of untrusted content. These deterministic controls block impact every time, whereas probabilistic helpers like classifiers only lower odds and can cause false positives.
- Testing requires continuous regression suite, not one-time passThe article provides a repeatable test method using harmless canary markers (made-up words) logged in a CSV file, re-run whenever the model, system prompt, or data source changes. A single test pass recorded last month says little about the current build. The methodology tests both direct paths (through chat input) and indirect paths (by planting canaries in every writable external source), logging tool calls that nobody asked for as the clearest injection signal.
- Framework identifiers vary by standard and versionOWASP LLM01 covers both forms and treats jailbreaking as a subset; NIST AI 100-2 E2025 uses NISTAML.018 for prompt injection and NISTAML.015 for indirect; one mapping guide links direct injection to MITRE ATLAS AML.T0051.000 and indirect to AML.T0051.001. The article warns that framework IDs differ between documents and versions, so reports must cite the exact source and version beside each identifier for verification.
Bottom line: Direct and indirect prompt injection require fundamentally different defensive strategies: direct injection defenses focus on input screening and safety guardrails at the user interface, while indirect injection defenses must inventory all external sources an agent reads and limit agent privileges to prevent damage when poisoned content inevitably reaches the model. The key to effective defense is recognizing that prompt injection cannot be eliminated like SQL injection but only reduced and cont
β±οΈ 50 min Β· Intermediate Β· 2 hands-on labs
Picture this: your team has just shipped a support chatbot, and a colleague asks whether the prompt injection reports in the news apply to you. You open the logs and see two very different kinds of risk. One is a customer typing odd instructions into the chat box. The other is a document or web page the bot reads that someone else wrote. Understanding direct vs indirect prompt injection is how you tell those two apart and decide what to fix first.
The difference sounds small, but it changes everything: who the attacker is, who gets hurt, what you can monitor and which defences actually help. Get it wrong and you will spend your budget filtering the chat box while the real danger arrives through an email, a calendar invite or a PDF.
In this Tutorial we will do three things together. First, I will give you the one-sentence definition and map each type to OWASP LLM01, MITRE ATLAS and NIST AI 100-2, including where jailbreaks sit. Second, you will run one direct and one indirect injection against the SecurityElites practice labs and compare what you see. Third, we will choose layered defences for each type and turn your findings into a test plan you can re-run whenever the model, prompt or data source changes.
π― What You Will Be Able to Do
β Before You Start
- Basic understanding of how LLM chatbots and system prompts work
- Familiarity with web application concepts such as HTML and file uploads
- A SecurityElites lab account
π In This Tutorial
- Direct vs indirect prompt injection: the core difference in one minute
- Definitions: direct, indirect and where jailbreaks fit
- How each attack reaches the model
- Threat model: attacker, victim and blast radius
- Technical comparison table and framework mapping
- Demo: a direct injection against a sales bot
- Demo: an indirect injection through a document
- Detection methodology for both types
- Defensive controls that reduce impact for direct vs indirect prompt injection
- Common mistakes and a practical checklist
- Your checklist
- What I want you to remember
- Questions people ask
Direct vs indirect prompt injection: the core difference in one minute
I want you to leave this section able to explain direct vs indirect prompt injection in one breath. Here it is. In a direct injection, the attacker is the user, and the malicious instruction arrives through the text they type into the model. In an indirect injection, the instruction arrives through external content the model reads later, such as a web page, a file or an email. The user's own prompt is innocent.
The delivery route is what separates them. Everything else follows from it: who the attacker is, who gets hurt, how far the damage spreads and how hard it is to spot. If you want the wider context first, my complete guide to LLM security sets out where both attacks sit among the other risks.
- Direct: attacker types a prompt
- Model treats it as an instruction
- Indirect: attacker plants text in a page or file
- Innocent user asks for a summary
- Model reads the planted text as an instruction
Notice that the model ends up in the same place both times. It cannot reliably tell the instructions it should follow from the data it should only read. That single weakness is why both attacks exist.
π§ Quick check
Definitions: direct, indirect and where jailbreaks fit
I like to define terms from the standards bodies, because you will meet this wording in reports and exams. Start with OWASP. Its LLM01 entry describes prompt injection broadly: input that changes model behaviour in ways the developer did not intend. That covers direct user input, retrieved content, tool output, images, audio, video, reasoning steps and persistent memory.
For the direct case, OWASP's earlier text says it happens when a malicious user overwrites or reveals the underlying system prompt. For the indirect case, the model accepts input from attacker-controllable external sources such as websites or files. Those payloads do not need to be visible to a human, as long as the model parses the text.
NIST draws the line by control. In its 2025 adversarial machine learning report, indirect injection is executed through resource control rather than through user-provided input. Google DeepMind puts it plainly: in a direct attack the end user deliberately supplies malicious input, while in an indirect attack the malicious instructions sit in external data the model later retrieves, and the user prompt is assumed benign.
π Words I just used
So where do jailbreaks fit? They are not a third category. OWASP treats jailbreaking as a subset of prompt injection, and both NIST and DeepMind describe it as a direct injection that defeats safety mechanisms. Same delivery route, narrower goal.
How each attack reaches the model
Let me walk you through the delivery paths, because the route decides what a defender can see. Direct injection has one path: the attacker types into a chat box, an API field or a form. OWASP's community page gives the Bing Chat 'Sydney' incident as its direct example, where a student got the model to reveal its hidden instructions.
Indirect injection has many paths. Anything the model reads can carry a payload. Think of web pages, emails, PDFs and rΓ©sumΓ©s, calendar invites, tool output and images. OWASP's own scenarios show the shape: a user asks for a summary of a page with a hidden injection, or a malicious user uploads a rΓ©sumΓ© with an embedded one.
A Cloud Security Alliance note gives a good rule for reviewing your own systems. If any outside party can write into a field that an agent later summarises, such as a calendar or email field, that field is an injection vector. Walk your app and list every such field.
π Words I just used
The same CSA note also lists Base64 payloads among the hiding techniques. This is why input filtering struggles here: the instruction arrives as tool input from a data source, not from a user you could screen.
For a deeper look at web-borne payloads, read how web pages attack your AI agent. We will practise both routes hands-on in the next sections.
Threat model: attacker, victim and blast radius
Let me ask you to stop thinking about payloads for a moment and think about people. In any comparison of direct vs indirect prompt injection, the real difference is who the attacker is, who gets hurt, and how far the damage can spread. Get that wrong and you will defend the wrong thing.
In a direct attack, the attacker and the user are the same person. They type the malicious text into the chat box themselves. The Google DeepMind Gemini paper puts it as the end user deliberately supplying malicious input. The victim is usually the application owner: a leaked system prompt, a broken policy, a bot saying things the company never approved. Impact is bounded by what one user can type and what that one session can reach.
In an indirect attack the attacker is a third party, and the user is often the victim. The same paper assumes the user prompt is benign. The hostile instruction sits in a web page, email, file or calendar field that the model retrieves later. One 2026 comparison notes that indirect injection grows with every tool, connector and retrieval source an agent reads. Each new connector is a new place an outsider might write.
- Attacker writes to a shared source
- Agent retrieves the content
- Model reads it as context
- Agent calls a tool with its own privileges
- Data leaves or an action runs
This is where the confused deputy problem matters. A deputy is a component acting with authority on someone's behalf. The NCSC describes an LLM as an inherently confusable deputy, and coverage of its guidance says the reliable way to cut risk is to limit the agent's privileges to those of the person who wrote the prompt. If the agent can do more than the user, an attacker borrows the surplus.
π§ Quick check
Technical comparison table and framework mapping
Let me put the whole comparison on one page. I will give you the table first, then the framework identifiers you will meet in reports, standards and job interviews.
Use this as a quick reference when scoping a test. It summarises the comparison, it does not replace testing.
Detection is harder for indirect injection because, as a Cloud Security Alliance note explains, the instruction comes from a data source the agent treats as tool input, not from a user. Input filters watching the chat box never see it.
π Words I just used
That mapping guide also links indirect injection to OWASP LLM06 Excessive Agency and to NIST SP 800-53 control AC-4, Information Flow Enforcement. Read it this way: the injection is the trigger, and excessive agency decides how much damage follows. For the wider picture, see the OWASP Top 10 for LLM Applications 2026 guide.
π§ Quick check
Demo: a direct injection against a sales bot
I am going to show you the direct case first, because it is the easier one to see. In direct vs indirect prompt injection, the direct form is the one where the attacker is the person typing. Everything here runs inside the SecurityElites practice lab, so you are not touching anyone else's system.
The lab is a customer service bot for a shoe store. Its system prompt tells it never to reveal an internal discount code. Our job is to see whether we can make it leak the code anyway, which mirrors the OWASP description of a user who overwrites or reveals the underlying system prompt.
Open this lab in a second tab and follow along with me. It is the direct half of our comparison.
βΈ Start with a normal shoe question so you can see how the bot behaves when it is following its rules.
βΈ Ask it directly for the code once, and note the refusal wording.
βΈ Experiment with different ways of framing your request, and watch how the bot's answer shifts.
βΈ Vary one thing per attempt so you know which change worked.
What to notice: The refusal comes from the model's own judgement, not from any code that checks the answer. Your text and the developer's rules sit in the same context window.
π§ Direct injection walk-through
Why did the system prompt not hold? Because the model reads the developer's rules and your message as one stream of text. It has no hard boundary telling it which part carries authority. The rule was a request, not an enforced control.
Demo: an indirect injection through a document
Here is the second half of direct vs indirect prompt injection. This time your own message to the bot is completely innocent. The hostile instruction hides inside the content the bot is asked to process, which matches the Google DeepMind framing where the user prompt is assumed benign.
The lab is a document summariser that does not separate document content from its own instructions. Your goal is to see whether a poisoned document can change what it does.
Use this lab for the indirect case. You write the document, and the victim is the summariser.
βΈ First submit a harmless document and ask for a summary, so you know the normal output.
βΈ Write a document that reads like normal text but contains a line addressed to the assistant rather than the human reader.
βΈ Move that line to different places in the document, such as the start, the middle and the end, and compare results.
βΈ Keep your request to the bot as plain as 'summarise this'.
What to notice: Nothing in your typed request is malicious. The attack travels in the file. Position and wording of the planted line change how reliably it is followed.
π§ Indirect injection walk-through
Compare the two demos. In the first, you were the attacker and the victim was the shop. Here the attacker could be anyone who can write into the document, and the person asking for the summary could be an unsuspecting colleague. That is why indirect cases scale so badly once real tools are attached.
Detection methodology for both types
Once you have seen both attacks work, the next question is how to test for them in an application you are allowed to assess. I use the same discipline for both types, but the scope differs. Direct testing starts at the chat box. Indirect testing starts with a map of everything the model reads.
π§ A repeatable test method
A plain CSV is enough to compare runs over time. The dates shown are only sample output.
Then repeat. A 2026 testing playbook advises re-running adversarial payloads whenever the model, the prompt or a data source changes, because a result from last month tells you little about today's build. Treat the CSV as a regression suite.
π§ Quick check
For method depth, see How to Test LLM Data Exfiltration Vulnerabilities and the tooling overview in AI Security Tools. Pair testing with logging and alerting so production attempts are visible too.
Defensive controls that reduce impact for direct vs indirect prompt injection
Let me start with the uncomfortable part, because it shapes every control that follows. With direct vs indirect prompt injection, you cannot patch the root cause. The UK NCSC warned in December 2025 that prompt injection is not SQL injection. SQL injection can be fixed with parameterised queries, because code and data can be kept apart. An LLM cannot reliably tell data from instructions, so the NCSC says injection may never be totally mitigated. Its advice is to reduce the risk and the impact.
So we stop asking how to block every payload and start asking what happens when one lands. The NCSC calls the model an inherently confusable deputy. Coverage of its guidance says the reliable way to cut risk is to limit the agent's privileges to those of the person who wrote the prompt. Everything below is layered on that idea. For the wider picture, see What Is LLM Security? Complete Beginner-to-Advanced Guide.
- Untrusted input or content
- Spotlighting and classifier
- Model with least privilege
- Tool-call validation
- Human approval
- Egress allowlist and output handling
π Words I just used
βοΈ Controls to put in place
Common mistakes and a practical checklist
The same errors turn up again and again, so let me name them before you build or test anything. Each one comes from treating direct vs indirect prompt injection as a text-filtering problem instead of a trust problem.
π§ Quick check
βοΈ Quick review checklist
Practise both sides on the SecurityElites labs, then go deeper with Indirect Prompt Injection 2026, the OWASP Top 10 for LLM Applications 2026 and How to Test LLM Data Exfiltration Vulnerabilities. The pillar guide, What Is LLM Security?, ties the whole cluster together.
Your Checklist
βοΈ Direct and indirect injection review checklist
π« Mistakes I See Most Often
What I Want You to Remember
π§ Check Your Understanding
β Questions People Ask
What is the difference between direct and indirect prompt injection?
Is a jailbreak the same as a direct prompt injection?
Why is indirect prompt injection considered more dangerous for AI agents?
Can prompt injection be fully prevented or patched?
How is prompt injection different from SQL injection?
What defensive controls reduce indirect prompt injection risk?
How do OWASP LLM01, MITRE ATLAS and NIST AI 100-2 classify direct and indirect prompt injection?
π§© More in the LLM Application Security series
- Start here: What Is LLM Security? Complete Beginner-to-Advanced Guide β Learn llm security from first principles: architecture, attack surface, prompt injection, data leakage and defences, then…
- Indirect Prompt Injection 2026 β When Web Pages Attack Your AI Agent β How indirect prompt injection works: hidden instructions in web pages, emails and files that hijack AI…
- How to Test LLM Data Exfiltration Vulnerabilities in 2026 | AI LLM Hacking Course Day 31 of 90 β Master LLM data exfiltration in 2026. Covert output channels, URL-based exfiltration, embedding leakage, membership inference attacks…
- OWASP Top 10 for LLM Applications 2026: Complete Security Guide β Learn the owasp top 10 llm applications 2026 list, what changed from 2025, and how to…
π Keep Learning on SecurityElites
- What Is LLM Security? Complete Beginner-to-Advanced Guide β Learn llm security from first principles: architecture, attack surface, prompt injection, data leakage and defences, then test a…
- AI Security Tools 2027: Essential Tools for AI Red Teaming and Defence β Compare ai security tools for red teaming and defence: garak, PyRIT, promptfoo, guardrails and more. Choose the right…
- Secure AI Development 2026 β Build LLM Apps That Resist Attack | AI LLM Hacking Course Day 44 of 90 β Secure AI development 2026 β turn 43 days of attacks into a builder's defence: threat-model the feature, harden…
- Day 6: When the Data Fights Back: Hostile Text and Bad Summaries β Learn how text hidden in collected data can instruct your AI, then rewrite your recon prompt to separate…
- Day 6: When Content Becomes Instructions β Plant a harmless test sentence in your own notes, watch your AI assistant obey it, then fence untrusted…
π Sources I Checked
- LLM01:2026 Prompt Injection – OWASP Gen AI Security Project
- LLM01: Prompt Injection – OWASP Gen AI Security Project
- Prompt Injection
- Adversarial Machine Learning: A Taxonomy and Terminology of Attacks and Mitigations
- Adversarial Machine Learning: A Taxonomy and Terminology of Attacks and Mitigations
- NIST AI 100-2 Adversarial ML Taxonomy Guide
- Lessons from Defending Gemini Against Indirect Prompt Injections
- Shifting from Injection to Interaction: Rethinking Web Security in the Age of LLMs and Beyond
Written by Mr Elite. Reviewed by Mr Elite, last reviewed on .

