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.

By Kevin O'Connor

Published Last reviewed 7 min read

A user asks an assistant to summarize a vendor questionnaire. A paragraph in the questionnaire tells the assistant to send internal files to a different address. The paragraph is part of the material being reviewed; it has no authority to change the task.

Indirect prompt injection occurs when instructions embedded in retrieved or otherwise external content influence the model's behavior. The attacker may control a document, email, webpage, ticket field, tool description or tool result without controlling the user's request. OWASP's prompt-injection guidance describes these external-content paths.

I would assess both parts of the failure: whether the content redirects the model and whether the application lets the resulting request cross a data or action boundary. A model refusal is useful, but the authorization layer still has work to do if that refusal fails.

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.

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 dataPreserve the intended instruction boundary; test model behavior separately.
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 isolationLabel source content and reduce instruction confusion; do not treat labels as a guaranteed barrier.
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.

Sanitization removes some unwanted content, but visible prose can carry an injection too. Source reputation is also insufficient: an approved wiki can contain a customer paste or a compromised page. Test the content path and the enforcement path together.

Indirect Prompt Injection Checklist

QuestionGood Answer
Do we treat retrieved content as untrusted?Yes.
Does hostile content redirect the model in the tested cases?Record observed behavior and enforce action policy independently.
Can documents trigger tool calls?Not without policy and approval.
Can email content cause external sending?Draft-first or approval required.
Can tool output influence the next action?Assume it can; every resulting tool call receives fresh validation and authorization.
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.

Record attempts and effects separately

For a synthetic test, retain the source fixture, the authorized user task, the proposed tool arguments, the policy result and the downstream result. Report a redirected model that hit an effective deny rule differently from a confirmed disclosure or write. Both observations are useful, but they call for different remediation.

The two-tenant RAG walkthrough provides an inert hostile-document fixture and local access checks. Add a separately authorized model evaluation before using it to make claims about your deployed assistant.

Sources