Direct Prompt Injection vs Indirect Prompt Injection: Complete Comparison

Direct Prompt Injection vs Indirect Prompt Injection: Complete Comparison
✨ AI Summary
OWASP risk numbers in this tutorial may follow an earlier edition of the list. See the current 2026 numbering.

⏱️ 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

Explain the difference between direct and indirect prompt injection in one clear sentence
Map each type to OWASP LLM01, MITRE ATLAS and NIST AI 100-2 identifiers
Place jailbreaks correctly as a subset of direct injection
Run a direct and an indirect injection against intentionally vulnerable labs and compare the results
Choose layered defensive controls suited to each injection type
Build a test plan that re-runs payloads whenever the model, prompt or data source changes

βœ… 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

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.

πŸ—ΊοΈ Two routes to the same model
  1. Direct: attacker types a prompt
  2. Model treats it as an instruction
  3. Indirect: attacker plants text in a page or file
  4. Innocent user asks for a summary
  5. 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.

πŸ’‘ Tip: When you read an incident report, ask one question first: who typed the prompt, and who wrote the text the model read? If those are different people, you are looking at an indirect case.

🧠 Quick check

A user asks an assistant to summarise a web page, and the page contains hidden text that changes the assistant's behaviour. Which type is this?

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

Direct prompt injectionThe user supplies the malicious instruction in their own input.
Indirect prompt injectionThe instruction hides in external content the model processes later.
JailbreakA direct injection aimed at making the model break its safety rules.
System promptThe developer's hidden instructions that frame how the model behaves.

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.

🚫 Common mistake: Do not use jailbreak and prompt injection as synonyms. A jailbreak targets the model's safety rules. A prompt injection can target your application's logic, data or tools, with no safety rule involved at all.

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

White-on-white textText coloured to match the background, so people cannot see it but the model reads it.
HTML commentMarkup that browsers hide but a scraper may pass to the model.
Unicode tag charactersNon-printing characters that can carry text invisible to the eye.
CSS-suppressed textContent hidden with styling, such as a zero-pixel font.

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.

⚠️ Watch out: Only test hidden-text ideas on pages and files you own, or inside a SecurityElites lab. Never plant payloads on real third-party sites or send them to other people's inboxes.

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.

πŸ—ΊοΈ How blast radius grows with each connector
  1. Attacker writes to a shared source
  2. Agent retrieves the content
  3. Model reads it as context
  4. Agent calls a tool with its own privileges
  5. 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.

πŸ’‘ Tip: For any agent you review, ask one question per tool: if a stranger could write the text this tool returns, what is the worst thing the agent could then do with its own permissions? That answer is your blast radius.

🧠 Quick check

An agent summarises a shared calendar. An outsider sends an invite containing hidden instructions. Which statement fits best?

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.

SIDE-BY-SIDE COMPARISON
Property | Direct | Indirect
Entry point | User's own prompt | Web page, email, file, tool output, image
Attacker | The user | Third party who controls content
Visibility | Visible in chat logs | Often hidden from the user
Scale | One session at a time | Grows with each connector and source
Typical impact | Prompt leak, policy bypass | Data exfiltration, unwanted tool actions
Detection | Easier: input is on record | Harder: payload lives in external data
Main fixes | Layered guardrails, monitoring | Privilege limits, isolation, approvals

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

OWASP LLM01The prompt injection entry in the OWASP LLM Top 10. It covers both forms and treats jailbreaking as a subset.
MITRE ATLAS AML.T0051.000 / .001Direct prompt injection is .000 and indirect is .001, according to one mapping guide.
NISTAML.018 / NISTAML.015NIST AI 100-2 E2025 uses .018 for prompt injection and .015 for indirect prompt injection.
Excessive agency (LLM06)An agent holding more permissions or autonomy than the task needs.

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.

⚠️ Watch out: Framework IDs differ between documents and versions. When you write a report, cite the exact source and version beside each identifier so a reader can verify it.

🧠 Quick check

Which identifier does one mapping guide give to indirect prompt injection in MITRE ATLAS?

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.

πŸ§ͺ HANDS-ON LAB Β· BEGINNER Β· 20 MIN Β· SECURITYELITES LAB
AI Prompt Injection β€” Sales Bot

Open this lab in a second tab and follow along with me. It is the direct half of our comparison.

What to try
β–Έ 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

Step 1 β€” Establish a baselineSend an ordinary question about shoe sizes. You should get a friendly, on-topic reply. This is your control.
Step 2 β€” Ask plainlyRequest the discount code with no tricks. I expect a polite refusal. That proves the system prompt is doing something.
Step 3 β€” Send an override attemptWrite a message that tries to change how the bot treats its earlier rules. Keep it short and change only one idea per try.
Step 4 β€” Read the responseIf the code appears, the attack worked. If you only get a refusal, rephrase and try again. Expect to need several attempts.

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.

⚠️ Watch out: Only run these payloads in the lab. Pointing override prompts at a real company's chatbot without permission is unauthorised testing, not practice.

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.

πŸ§ͺ HANDS-ON LAB Β· INTERMEDIATE Β· 25 MIN Β· SECURITYELITES LAB
AI Indirect Prompt Injection β€” Document Summariser

Use this lab for the indirect case. You write the document, and the victim is the summariser.

What to try
β–Έ 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

Step 1 β€” Baseline summaryUpload a short, clean document and ask for a summary. You should see a faithful two or three line summary.
Step 2 β€” Plant the instructionEdit the document so it contains text aimed at the model, not the reader. Save it as a new file.
Step 3 β€” Send the innocent requestAsk only for a summary. Do not mention anything else. This is the defining feature of the indirect form.
Step 4 β€” Inspect the outputIf the bot follows the planted line instead of summarising, the injection landed. Compare that with your baseline.

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.

πŸ’‘ Tip: For the real-world version of this attack, including hidden text and agent tools, read Indirect Prompt Injection 2026 after you finish the lab.

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

Step 1 β€” Inventory the trust boundariesList every source of text the model sees: user input, uploaded files, web pages, emails, calendar fields, tool output and images. For each one, ask whether an outside party can write to it. The Cloud Security Alliance puts it simply: if an outsider can write into a field the agent later summarises, that field is an injection vector.
Step 2 β€” Prepare payload variantsWrite several versions of a harmless canary instruction, such as asking the model to include a made-up marker word. Vary the wording, the position and the format, including comments and hidden text.
Step 3 β€” Test direct pathsSend the variants through the chat input and record which ones change behaviour.
Step 4 β€” Test indirect pathsPlace the same canaries in each writable source, then trigger a normal, innocent task. Note whether the marker appears or a tool is called.
Step 5 β€” Log tool callsRecord every tool call with its arguments and the content that preceded it. A tool call nobody asked for is your clearest signal.
CANARY RESULT LOG
one line per test, kept in a simple file
echo "$(date -u +%FT%TZ),source=uploaded_pdf,variant=3,marker_seen=yes" >> injection-tests.csv
tail -n 3 injection-tests.csv
2026-01-15T10:02:11Z,source=chat,variant=1,marker_seen=no
2026-01-15T10:04:40Z,source=uploaded_pdf,variant=3,marker_seen=yes

A plain CSV is enough to compare runs over time. The dates shown are only sample output.

⚠️ Watch out: Test only systems you own or have written permission to assess, and use harmless canary markers rather than payloads that try to cause real damage.

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

An agent summarises a shared calendar. Which step best finds indirect injection risk?

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.

πŸ—ΊοΈ Layered defence around the model
  1. Untrusted input or content
  2. Spotlighting and classifier
  3. Model with least privilege
  4. Tool-call validation
  5. Human approval
  6. Egress allowlist and output handling

πŸ“– Words I just used

SpotlightingA Microsoft technique that marks untrusted text so the model can tell it from trusted instructions, using randomised delimiters, datamarking between words, or encoding such as base64.
Prompt ShieldsA Microsoft classifier that detects injection attempts in external content. It is a probabilistic layer, so it can miss attacks.
Egress allowlistingLetting the application contact only approved destinations, so injected instructions cannot send data to an attacker's server.

β˜‘οΈ Controls to put in place

⚠️ Watch out: Probabilistic defences such as classifiers can cause false positives that block legitimate actions. Microsoft's Zero Trust guidance says to assume some attacks will succeed, so tune detection but never rely on it alone. Model-level options such as StruQ and SecAlign help, yet sanitisation can be costly and degrade meaning.
πŸ’‘ Tip: Rank your controls by whether they are deterministic. A tool-call policy or an egress allowlist blocks the impact every time. A classifier only lowers the odds. Build the deterministic ones first. Secure AI Development 2026 walks through this in practice.

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.

🚫 Common mistake: Treating filtering as a fix. A keyword or phrase blocklist catches the obvious direct payload and misses hidden text, encoded content and rephrased instructions. Indirect payloads come from data the agent treats as tool input, not from a user, so input filters rarely see them.
🚫 Common mistake: Trusting retrieved content. A web page, email, PDF or calendar field is not safe because your own system fetched it. If an outside party can write into a field an agent later summarises, that field is an injection vector.
🚫 Common mistake: Giving agents more privilege than the user. If the agent can do things the person prompting it cannot, one planted instruction becomes a privilege escalation. This also links to OWASP's excessive agency risk.
🚫 Common mistake: Testing only direct prompts. Passing a sales-bot style test says nothing about documents and connectors. Re-run your payload tests whenever the model, prompt or data source changes.

🧠 Quick check

Which control still limits damage when an injected instruction gets past every filter?

β˜‘οΈ 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

Treating prompt injection as a chat-box filtering problem and only screening what users type.List every source the model reads, such as web pages, emails, files, calendar fields and tool output, and treat each one as untrusted input. Any field an outsider can write to that an agent later summarises is an injection vector.
Relying on a single classifier or a strongly worded system prompt as the defence.Assume some payloads will get through. Add deterministic controls that limit impact: least privilege for the agent, tool-call validation, egress allowlists and human approval for high-impact actions. Use classifiers as an extra layer only.
Testing once, recording a pass, and never repeating the tests.Keep your payloads and harmless canary markers in a CSV regression suite. Re-run it whenever the model, the prompt or a data source changes, and log the results with the build version beside them.

What I Want You to Remember

In a direct injection the attacker is the user typing the prompt, while in an indirect injection a third party hides instructions in content the model reads later.
Both attacks work for the same reason: the model cannot reliably separate instructions it should follow from data it should only read.
A jailbreak is not a third category but a direct injection aimed at defeating the model's safety mechanisms.
Indirect injection is usually harder to detect and has a wider blast radius, because every tool, document and data source an agent reads becomes an entry point.
Prompt injection cannot be patched like SQL injection, so you rank deterministic controls such as least privilege and egress allowlists above probabilistic ones such as classifiers.
Re-run your injection payloads whenever the model, the system prompt or a data source changes, because an old result says little about the current build.

🧠 Check Your Understanding

A user asks a bot to summarise a web page, and a hidden line on that page tells the bot to leak data. Which type is this?
Where does a jailbreak fit in the classification?
Which control blocks impact every time, rather than only lowering the odds?

❓ Questions People Ask

What is the difference between direct and indirect prompt injection?
In a direct injection the attacker is the user and types the malicious instruction into the prompt. In an indirect injection a third party hides the instruction in content the model later reads, such as a web page, email or file. The user's own prompt can be completely innocent.
Is a jailbreak the same as a direct prompt injection?
Not quite. A jailbreak is a direct injection with a specific goal: making the model break its safety rules. OWASP treats jailbreaking as a subset of prompt injection, and NIST and Google DeepMind describe it as a direct injection that defeats safety mechanisms.
Why is indirect prompt injection considered more dangerous for AI agents?
Direct injection is limited to what one user can type. Indirect injection grows with every tool, connector and data source an agent reads, and the instruction comes through tool input rather than a user you could screen. If the agent has broad permissions, the damage can spread across the whole system.
Can prompt injection be fully prevented or patched?
No. The UK NCSC warned in December 2025 that it may never be totally mitigated the way SQL injection can, because language models cannot reliably distinguish data from instructions. The practical aim is to reduce likelihood and limit impact with layered controls.
How is prompt injection different from SQL injection?
SQL injection can be fixed at the root with parameterised queries, which keep code and data apart. A language model has no such hard boundary, because instructions and data share one stream of text. That is why the NCSC describes the model as an inherently confusable deputy rather than a code injection target.
What defensive controls reduce indirect prompt injection risk?
Use layers: trust boundaries, context isolation, least privilege, tool-call validation, egress allowlisting, disabling automatic image rendering and human approval for sensitive actions. Add probabilistic helpers such as Prompt Shields and Spotlighting, but do not rely on them alone. Test continuously with a regression suite.
How do OWASP LLM01, MITRE ATLAS and NIST AI 100-2 classify direct and indirect prompt injection?
OWASP groups both under LLM01 prompt injection. NIST AI 100-2 E2025 uses NISTAML.018 for prompt injection and NISTAML.015 for indirect prompt injection. One mapping guide links direct injection to MITRE ATLAS AML.T0051.000 and indirect to AML.T0051.001, so always cite the exact source and version.
πŸš€ Where to go next: Go deeper on the real-world indirect case by reading about hidden text and agent tools, then practise data exfiltration testing so you can measure the blast radius of what you find.

🧩 More in the LLM Application Security series

πŸ“š Keep Learning on SecurityElites

Written by Mr Elite. Reviewed by Mr Elite, last reviewed on .

ME
Mr Elite
Owner, SecurityElites
I teach AI red teaming and ethical hacking through hands-on labs at SecurityElites.
⚡
Join free to earn XP for reading this article Track your progress, build streaks and compete on the leaderboard.
Join Free
Lokesh N. Singh aka Mr Elite
Lokesh N. Singh aka Mr Elite
Founder, Securityelites Β· AI Red Team Educator
Founder of Securityelites and creator of the SE-ARTCP credential. Working penetration tester focused on AI red team, prompt injection research, and LLM security education.
About Lokesh ->

Leave a Comment