Skip to content
Back to insights
Prompt 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 6 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.

That is indirect prompt injection: 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, and the prompt injection entry in our OWASP Top 10 for AI guide summarizes the attacker path and detection signals.

Test both the model's response and the application's enforcement. A refusal may stop this attempt. If the model follows the paragraph, the application still needs to reject an unauthorized read or send.

Follow the questionnaire through the normal path

The authorized task is simple:

User: "Summarize this uploaded vendor questionnaire."
Application extracts the document text.
Assistant produces a summary for the authorized user.

Now put a hostile paragraph in the source fixture and let it pass through the same parser, chunker and retrieval process ordinary documents use. Keep the requested destination inert and use test records. A payload pasted directly into the model skips these steps and answers a different question.

Watch the transitions. Was the paragraph extracted? Did retrieval select it? Did the model change the summary, request another document or propose a tool call? Did policy allow that operation? Did the downstream system change?

Extracting the paragraph is not a model failure. A model that requests a send does not establish that the send occurred. Recording each step is what makes the result useful for remediation.

Choose surfaces an attacker can actually influence

SourceA realistic entry pointFollow-on concern
Document or PDFText added to a file the user uploads or the agent retrievesAnother source is requested, or the answer includes protected material.
Email or ticketA message from outside the organizationA reply changes recipient, adds an attachment or persists a false instruction.
WebpagePage text, metadata or content exposed by the fetcherThe agent requests an unrelated URL or tool operation.
RepositoryA comment, README or other file read by a coding assistantSource content influences commands, dependencies or code changes.
Tool responseA customer-controlled field inside an otherwise legitimate API responseThe next tool call inherits instructions from returned data.
MemoryA record written during an earlier interactionThe instruction affects a later session or a different workflow.

Source reputation does not settle the trust question. An approved internal wiki may contain an external paste. A trusted API can return user-controlled text. Work out who controls the particular field, then test how the application handles it.

Tool access changes what the instruction can accomplish

A summarizer can disclose protected context through its answer even if it has no write tools. Adding email, record updates or command execution creates further paths. The blast radius walkthrough follows a single hostile ticket to each of those outcomes and puts bounds on them.

For the questionnaire example, inspect both the data permission and the destination permission. The user might be allowed to read an internal file without being allowed to email it to the address in the document. If you check those two permissions independently, you can miss the prohibited transfer.

A draft-first workflow gives a person a chance to review a message. Bind any approval to the actual recipients, content and attachments, and recheck authority before sending. Where a workflow permits automated sends, enforce its recipient and content rules outside the model. The source document cannot expand that policy.

The same rule applies to a tool chain. A successful search or API call does not authorize the next operation. Validate its parameters, target and current permissions again.

Separate useful mitigations from the final check

Label source content and preserve its origin. Structured extraction can reduce instruction blending and make a response easier to validate. Strip unnecessary hidden or active content at ingestion where that fits the document type.

None of those measures guarantees that the model will ignore hostile prose. A visible sentence can carry the attack, and stripping every imperative can destroy legitimate content. Test the model with the source representation your application actually uses.

At execution, require typed inputs and server-side authorization. Limit the tools and destinations available to the workflow. Keep credentials outside context. Use network and runtime restrictions where an agent can fetch URLs or execute code. A model-generated claim that the user approved an action must not satisfy the approval check.

Retrieval needs its own authorization checks before protected content reaches a model, an external reranker or the user. Output filtering cannot undo disclosure to an upstream processor.

Check persistence and recovery

If the assistant saves a summary or memory, check whether the injected instruction survives there. Removing the original document may leave a copied instruction in a cache, index, draft or later conversation. The memory review package covers write authority, provenance and deletion for those stored records.

Record source references and derived copies so an operator can correct the affected state. Test whether disabling a tool or revoking a credential stops queued and in-flight work. An “off” switch in the interface is incomplete if the worker continues to act.

Keep limits on retries, time and resource use. An attacker may seek repeated operations or cost rather than a single dramatic disclosure.

Record attempts and effects separately

For each test, retain the source fixture, authorized task, model and configuration, proposed tool arguments, policy result and downstream observation. Store safe parameter fields and protected references instead of unrestricted prompts, secrets or customer documents in ordinary logs.

Include a legitimate task beside the attack case. If the fix rejects every document or disables every tool, it may contain the attack while breaking the intended workflow. Acceptance should cover both the denied operation and the permitted one.

The report should name the failed boundary and the smallest correction that addresses it. A redirected model stopped by a working policy gate calls for a different response from a confirmed disclosure. Keep the test's limitations visible when the result is summarized for a release decision.

The two-tenant RAG walkthrough provides an inert hostile-document fixture and local access checks. An AI agent security assessment runs this kind of trace against one workflow's real tools and credentials, with the accounts, permitted actions and stop conditions agreed first. Either way, add a separately authorized model evaluation before making claims about your deployed assistant.

Sources

For occasional technical updates, get Field Notes by email.