TKOResearch
Menu
Back to insights
Prompt InjectionPrompt InjectionField note

Indirect Prompt Injection Through Documents, Emails, Webpages, and Tool Output

How indirect prompt injection reaches AI agents through RAG systems, copilots, MCP tools, webpages, emails, PDFs, memory, and tool outputs.

Last reviewed May 4, 20268 min read

Why This Matters

Indirect prompt injection is one of the most important security risks in modern AI systems because the attacker does not need to type into the prompt box.

They only need to place malicious instructions somewhere the AI system will later read.

That can be:

  • A webpage.
  • A PDF.
  • A support ticket.
  • An email.
  • A calendar invite.
  • A RAG document.
  • A code comment.
  • A tool response.
  • MCP tool metadata.
  • Long-term memory.

OWASP describes remote or indirect prompt injection as malicious instructions hidden in external content that an LLM processes, including code comments, documentation, issue descriptions, webpages, documents, emails, attachments, and hidden text.

Why Indirect Prompt Injection Matters

Direct prompt injection is visible. A user types something malicious into the chat box.

Indirect prompt injection is different. The malicious instruction is embedded in content the model consumes during normal operation.

User asks normal question
  -> system retrieves document / email / webpage / ticket / tool result
  -> retrieved content enters model context
  -> model treats hostile content as meaningful instruction
  -> agent leaks data, changes behavior, or calls tools

The root cause is instruction/data confusion.

LLMs process natural language instructions and natural language data in the same context window. If a document contains text that looks like an instruction, the model may interpret it as part of the task rather than as untrusted content.

This is why prompt-only mitigations are not enough. You cannot reliably solve indirect prompt injection by writing a stronger system prompt. You need architecture-level controls.

Common Indirect Prompt Injection Surfaces

SurfaceWhy It Is Risky
WebpagesBrowsing agents may ingest attacker-controlled page text, hidden elements, or metadata.
PDFsHidden or low-visibility text can enter document-processing workflows.
EmailsIncoming messages can carry instructions later processed by assistants.
Support ticketsCustomers, users, or attackers can inject text into support workflows.
RAG documentsPoisoned content can persist in the retrieval layer.
Code commentsCoding assistants may treat comments or docs as task instructions.
Tool outputAPI or tool responses can influence the next model step.
MCP metadataTool descriptions and metadata are model-facing and can steer behavior.
MemoryPoisoned memories can influence future sessions.

OWASP's AI Agent Security Cheat Sheet explicitly lists direct and indirect prompt injection from user input and external sources such as websites, documents, and emails as agent security risks. It also calls out tool abuse, data exfiltration, memory poisoning, goal hijacking, excessive autonomy, and cascading failures.

Why Agents Make Indirect Prompt Injection Worse

Indirect prompt injection against a passive summarizer may produce a bad answer.

Indirect prompt injection against an agent can produce action.

Agent CapabilityPotential Impact
RetrieveUnauthorized context exposure.
SummarizeSensitive-data leakage through generated output.
SendExternal exfiltration or unauthorized communication.
WriteRecord modification or workflow tampering.
ExecuteCode execution or command misuse.
RememberPersistent manipulation.
Chain toolsEscalation from low-risk to high-risk operation.

This is why the key security question is not only whether the model can be tricked. The key question is what the system can do after the model is tricked.

Example: Document-Based Indirect Prompt Injection

A normal workflow:

User: "Summarize this uploaded vendor questionnaire."
AI system reads PDF.
AI system summarizes the document.

Risky workflow:

User uploads or retrieves a document.
Document contains adversarial instructions.
AI system treats those instructions as part of the task.
AI system changes behavior, reveals context, or calls tools.

Safer design:

ControlPurpose
Treat document text as untrusted dataPrevent content from becoming instruction.
Preserve source labelsTrack which context came from which document.
Use structured extractionReduce free-form instruction blending.
Validate outputsPrevent unsafe downstream action.
Gate tool callsRequire authorization outside the model.

Example: Email-Based Indirect Prompt Injection

Email is a dangerous ingestion surface because attackers can send email to many enterprise users.

A risky agent may read an inbound email, summarize it, retrieve internal context, compose a response, send the response externally, and store the interaction in memory.

If hostile email content can steer the assistant, a normal workflow becomes an exfiltration or social-engineering path.

ControlPurpose
Draft-first email workflowsPrevent automatic external sending.
Recipient validationEnsure generated emails go only to intended recipients.
External-content labelingMark inbound email as untrusted.
Tool-call approvalRequire human approval for send actions.
LoggingPreserve prompt, email ID, retrieved context, draft, and send decision.

Example: Webpage-Based Indirect Prompt Injection

Browsing agents ingest attacker-controlled webpages.

A safe browsing assistant should assume web content can be hostile.

ControlPurpose
HTML/text sanitizationRemove irrelevant hidden or active content.
Source trust scoringDistinguish trusted docs from public web pages.
Instruction isolationPrevent webpage text from overriding system/developer instructions.
No automatic tool chainingDo not let page content trigger unrelated tool calls.
Egress restrictionPrevent the agent from transmitting sensitive context to arbitrary destinations.

The user asked the agent to read a webpage. The webpage should not be able to instruct the agent to use unrelated tools.

Example: Tool-Output Injection

Tool output can also be hostile.

ToolInjection Path
Web fetcherAttacker-controlled page returns hidden instructions.
Ticket searchCustomer ticket text contains manipulation instructions.
CRM lookupUser-controlled field contains hostile content.
Code searchRepository comments include agent instructions.
Calendar readInvite body includes malicious instructions.
API responseUpstream response includes text that steers next action.

Tool output should be treated as data, not as a higher-priority instruction.

Defensive Design Principles

Indirect prompt injection is a system problem. Controls need to exist across the architecture.

PrincipleImplementation
Separate instruction from dataUse explicit context labels and structured prompts.
Treat retrieved content as untrustedDocuments, emails, webpages, and tool output are data.
Enforce authorization outside the modelDo not rely on model judgment for access control.
Gate high-impact toolsHuman approval for send, write, delete, execute, deploy.
Validate tool parametersTyped schemas, allowlists, policy checks.
Minimize contextRetrieve only what is needed and authorized.
Preserve source attributionTrack where every chunk came from.
Log the decision pathPrompt, retrieval, tool call, approval, output.
Regression testAdd indirect injection cases to CI/security testing.

OWASP's LLM Top 10 identifies prompt injection, insecure output handling, sensitive-information disclosure, insecure plugin design, and excessive agency as major risks. Those categories converge in indirect prompt injection against tool-using agents.

Indirect Prompt Injection Checklist

QuestionGood Answer
Do we treat retrieved content as untrusted?Yes.
Can external content override system instructions?No.
Can documents trigger tool calls?Not without policy and approval.
Can email content cause external sending?Draft-first or approval required.
Can tool output become the next instruction?No, it is labeled as data.
Is RAG authorization enforced before retrieval?Yes.
Are high-impact actions gated?Yes.
Can we reconstruct what content influenced the answer?Yes.
Do we test indirect prompt injection in CI or pre-release?Yes.
Can poisoned memory be inspected or removed?Yes.

What The Review Should Leave Behind

The review should identify the real ingestion surfaces and show where hostile content can influence context, tools, memory, or outbound actions.

DeliverableDescription
Ingestion Surface InventoryLists documents, emails, webpages, RAG sources, tools, memory, and APIs.
Trust-Boundary MapShows where untrusted content enters model context.
Indirect Injection Abuse-Case MatrixDocuments realistic hostile-content scenarios.
Tool-Call Safety ReviewValidates that retrieved content cannot trigger unsafe tool use.
RAG Poisoning ReviewTests stored malicious content and authorization boundaries.
Remediation RoadmapPrioritizes architectural fixes and regression tests.

Final Thought

Indirect prompt injection is not a strange edge case. It is a predictable consequence of connecting LLMs to real-world content.

The more sources your AI system reads, the larger the injection surface becomes. The more tools your agent can use, the larger the business impact becomes.

Before production, ask:

Which untrusted content sources can influence this agent, and what can the agent do after being influenced?

If you cannot answer that, you do not know the system's real risk.

What TKOResearch Reviews

TKOResearch performs AI Agent Security Assessments for teams deploying RAG systems, MCP tools, copilots, workflow agents, and LLM applications that ingest external or semi-trusted content.

Request AI Agent Security Review

Sources