Indirect Prompt Injection via Retrieval-Augmented Generation Pipelines

Poisoned documents hijack RAG systems, so defenses must span the pipeline.

· 9 min read
Cover illustration for “Indirect Prompt Injection via Retrieval-Augmented Generation Pipelines”
Emerging Vulnerabilities · November 9, 2026 · 9 min read · 1,935 words

Indirect prompt injection through retrieval-augmented generation pipelines attacks the material a system reads in response to a user’s question. That difference changes where defenses belong. Input validation cannot stop instructions that are hidden in retrieved content. Protecting a RAG system requires controls over ingestion, retrieval, context assembly, and tool use, with tests that follow the attack through the whole pipeline.

Why RAG creates a structurally different injection problem than direct prompt manipulation

A direct attack arrives in the user query, where the application can inspect, filter, or rate-limit it. An indirect attack plants instructions in material that the application will retrieve later. The user can ask a legitimate question in a legitimate session.

This changes the trust boundary the application must defend. Retrieved text enters the model’s context as supporting material, but the model has no inherent mechanism that reliably separates “data to summarize” from “instructions to execute.” A support article can thus give the model facts it needs along with a command that competes with the application’s instructions. The source becomes an instruction channel. Hardening the chat interface leaves that channel untouched, while output guardrails act only after the hostile material has reached the model.

How the retriever becomes the attack's delivery mechanism

The retriever selects text for relevance. The normal pipeline embeds a query, retrieves matching chunks, assembles context, and asks the model to generate a response. An attacker uses that same route. A benign question about a refund policy can retrieve a support article containing an instruction to call an API endpoint and return session tokens. The model then receives the policy text and the malicious command together.

The attacker needs influence over a source. Enterprise corpora can include vendor documentation, customer-submitted tickets, shared drives, and externally sourced content. Each source creates a possible entry point for text that will later be treated as useful context. The legitimate user supplies the occasion by asking a question that matches the poisoned material.

However, planting a document does not establish that anyone will retrieve it. Semantic ranking is a chokepoint because a payload outside the retrieved set cannot influence generation through that request. Chang et al.’s study, Overcoming the Retrieval Barrier, found that unoptimized injection payloads were rarely retrieved under natural queries across realistic corpora. Earlier lab evaluations often assumed that step had already succeeded. That assumption skipped the practical barrier between a malicious document and an exposed model.

How attackers guarantee their payload gets retrieved

Chang et al. addressed that barrier by splitting the malicious document into a trigger fragment and an attack fragment. The trigger is engineered to win retrieval for a target query, while the attack fragment contains the instruction the attacker wants followed. Their black-box method needs only API access to the embedding model. It does not require access to the vector store, application, or retriever internals. Across the evaluated benchmarks and embedding models, it achieved near-100% retrieval at very low cost per targeted query.

The malicious instruction no longer needs to resemble the user’s question closely enough to rank well on its own. Related adversarial embedding techniques use gradient-based optimization to make document vectors highly similar to target query vectors. The resulting text can be incoherent to a human reader yet score strongly under cosine similarity. Relevance in vector space is not evidence of trustworthy meaning.

AgentPoison research also shows high attack success when only a tiny fraction of stored documents is poisoned. Corpus size is therefore not a dependable dilution defense. An optimized document competes for a particular query. Scanning only for obvious commands also misses part of how the attack works, because the retrieval trigger and malicious instruction do different jobs. Once retrieval is reliable, the remaining practical challenge is getting the document through review.

The concealment techniques that bypass document review

A document’s visible appearance is not its extracted text. PDF parsers including PyPDF2, PDF.js, and pdfminer can extract white text placed on a white background, even though a reviewer cannot see it on the page. The parser delivers that text to the pipeline like any other content. Snyk’s 2024 demonstration against a banking application used this technique to override a credit score analysis without access to pipeline internals.

Invisible Unicode creates a related gap between display and extraction. Non-printing characters can make injected content appear as whitespace in a document viewer while remaining present in the extracted string. The common weakness is a mismatch between what review approves and what ingestion supplies to the model. Encryption protects data at rest and in transit, and ingestion legitimately extracts the document’s contents, including any hidden instructions.

These techniques exploit the processing path after visual review. EchoLeak, tracked as CVE-2025-32711, shows how hidden content that enters a RAG system can change answers and lead to data loss. The next boundary is therefore not merely whether the model produces an incorrect sentence. It is what the application allows that sentence, or a resulting action, to do.

What a successful injection can actually do, especially in agentic pipelines

Markdown can turn generated output into an exfiltration channel. An injected instruction can cause a model to place sensitive context inside a URL, exposing it when the destination is fetched. In Slack AI’s August 2024 incident, a message in a public channel caused the system to build a clickable link that contained data from a private channel. Automatic image fetching removes even that click. EchoLeak affected Microsoft 365 Copilot, where injected instructions produced Markdown image links that sent context data to an attacker server without victim interaction. The vulnerability received a CVSS score of 9.3.

A model restricted to answering can return attacker-selected content or disclose context, while an agent authorized to call APIs or execute code can act on the same hostile instruction. Chang et al. demonstrated that a single poisoned email could coerce a leading model into exfiltrating SSH keys in a multi-agent workflow. The user had issued a natural summarization query. The attack redirected an ordinary reading task into credential theft.

The poisoned source can also outlast the session. A document remains dormant until a relevant query retrieves it, potentially affecting different users over time. In the financial services HR assistant case, document upload permissions to a shared SharePoint corpus were enough to influence the assistant’s responses for all users. No special access beyond those permissions was required. Multi-agent systems add another propagation route because a compromised agent can pass tainted instructions to peers, extending the effect beyond the first pipeline.

Why the standard framing of this as an OWASP compliance item understates the problem

OWASP correctly places prompt injection at the front of the risk discussion. Its LLM Top 10 for 2026, released August 4, 2026, ranks Prompt Injection first, Sensitive Information Disclosure second, and Excessive Agency third. Those categories cover linked harms that a successful RAG attack can cause. The same edition expands injection coverage to cross-modal attacks and memory persistence, while LLM09 addresses Vector and Embedding Weaknesses. The taxonomy recognizes that retrieved content is a first-class attack surface.

Some researchers question injection’s leading position because the public incident record is thin, while OWASP attributes that scarcity to heavy defensive investment. A prompt classifier at the output layer cannot govern which documents enter a corpus or which tools an agent may invoke. Treating “addresses prompt injection” as a single completed compliance item hides those distinctions.

Singh et al.’s study, Adversarial Intent is a Latent Variable, shows that additional stateless checkpoints can provide zero marginal benefit when homogeneous filters produce perfectly correlated detections. That is a conditional finding that leaves room for useful filtering. Its practical warning is narrower and stronger. More checkpoints are not automatically more evidence when each one judges the same artifact in the same way.

Where defenses must actually sit — and what stateless guardrails miss

At ingestion, source trust tiers should distinguish first-party curated material from internal user-generated content, external partners, and the open web. Access permission alone does not make content trustworthy. User-generated and external material should still be treated as potentially hostile and checked for hidden content and known instruction patterns before indexing. Prompt Security’s embedding-layer research shows why checks for more advanced variants must look beyond obvious text templates.

Entry rules determine which sources may contribute, while preserved authorship, versions, and integrity hashes retain provenance through chunking and embedding. Retrieval constraints then limit what a query, user, or agent may fetch. These controls address the trigger-fragment attack at its delivery stage rather than relying on the generator to reject everything it receives. Pattern matching catches naive instructions, but cannot stand in for retrieval controls.

Context assembly needs its own separation of authority. Hierarchical prompt structures and explicit precedence markers reinforce the priority of core directives over retrieved text, raising the difficulty of injection. Because generation can still fail, tool authorization must grant only the permissions needed for the current task and withhold ambient session permissions. Sandboxing limits the consequences, while output monitoring looks for unexpected tool calls, out-of-scope content, and reproduction of attacker-controlled strings.

Stateful defense connects evidence that isolated checks discard. Singh et al.’s MMA-RAGT framework maintains a belief state about adversarial intent across pipeline checkpoints. This lets the framework keep updating its assessment with what it sees during retrieval, planning, and generation. Their tests found that it reduced attacks much more than stateless multi-point filtering did, and that removing the belief state made attacks succeed significantly more often.

These layers also need repeated adversarial testing as the system changes. Continuous red-teaming should cover white-font text, metadata instructions, hidden speaker notes, and optimized trigger fragments when the corpus, retriever, or prompt template changes. Promptfoo’s RAG red-team mode automates much of this with a configuration file that defines the pipeline and attack categories that are built in. Automation helps exercise the architecture, but test design still has to distinguish where an attack entered from where it succeeded.

What testing a RAG pipeline for injection actually requires

Diagram: Three Isolation Layers: Where RAG Pipeline Tests Must Land. Visualizes: Show a stepped sequence of three distinct test types that must be run on a RAG pipeline, each targeting a different stage.

Security tests must distinguish failures in retrieval from failures in generation. A retrieval isolation test places known payloads in a test corpus using white-font text, metadata instructions, hidden speaker notes, and footer directives. Benign representative queries then reveal whether poisoned chunks reach the retrieved set. This tests document processing and exposure before generation. It does not establish whether the model would obey the injected instruction.

A generator isolation test asks the other question. Fabricated retrieved chunks containing payloads go directly to the model, bypassing the retriever, to measure whether generation follows hostile instructions. End-to-end tests then put the whole pipeline back in place and use optimized trigger fragments aimed at target queries. If basic retrieval isolation passes but optimized end-to-end testing fails, the retrieval layer needs investigation rather than an automatic rewrite of the generation prompt.

Tool-call tests should try to make the system make unauthorized API calls, carry out Markdown-based data exfiltration, and generate and execute code. Tests should assess whether an injected instruction can cross the authorization boundary, going beyond whether its wording appears in a response. Re-testing should follow changes to the corpus, retriever, embedding model, or prompt template. Each can alter which payloads arrive and how the system handles them.

For pipelines where findings support SOC 2, HIPAA, or ISO 27001 obligations, penetration testing should include whitebox access to ingestion, retriever configuration, prompt assembly, and tool authorization settings. Testing only through the chat interface cannot check those internal boundaries. A benign question is compatible with a successful attack, so a clean user-input test says little about the material retrieved on its behalf. The security test has to follow that material all the way to the action it can cause.

Sources

  1. Adversarial Intent is a Latent Variable: Stateful Trust Inference for Securing Multimodal Agentic RAG
  2. Overcoming the Retrieval Barrier: Indirect Prompt Injection in the Wild for LLM Systems

More in Emerging Vulnerabilities