Skip to content
AI

RAG Security: Correcting 6 Architecture Assumptions

Supplying context to a language model shifts prompt injection targets to your vector stores rather than neutralising untrusted text.

Illustration: A transparent glass funnel pours glowing blue data shards into a deep, geometric vector database structure below.
AI-generated illustration: AppSec Scoop
Quick answer

Retrieval-augmented generation (RAG) does not sanitise untrusted text, isolate tenants, or prevent prompt injection. Connecting a vector database to an inference pipeline creates new paths for data poisoning, indirect prompt injection, and permission bypass. You must enforce access controls at retrieval and treat retrieved chunks as raw, untrusted user inputs.

Misreading: RAG solves prompt injection by grounding the model in facts

Correct reading: Retrieval mechanisms broaden your attack surface by transforming external documents into delivery vehicles for indirect attacks.

Grounding an inference run with verified knowledge bases prevents innocent factual errors, yet it does not force the underlying model to ignore malicious directions. If an external record contains embedded commands designed to override the system instructions, the model processes those commands alongside genuine reference data. Our guide to prompt injection attacks details how models struggle to separate code from input data. Ingestion pipelines that parse external websites, tickets, or emails create permanent, searchable storage for adversary instructions.

Misreading: Vector databases automatically inherit source access controls

Correct reading: Semantic search indexes flatten document permission boundaries unless your query pipeline explicitly replicates authorization checks.

Data storage engines map text chunks into a multi-dimensional array known as an embedding space, where semantic similarity dictates search results rather than user identity. An identity management token valid for an enterprise intranet directory does not restrict queries within a unified vector store. Unless you apply pre-retrieval filters that match the querying user's security identifiers, the retrieval algorithm returns sensitive extracts from restricted records to unauthorised personnel.

LayerNative Permission StateSecurity Requirement
Source Document StoreRole-based permissions per fileNative access control lists
Vector IndexUniform mathematical coordinatesPre-query identity filters
Context InjectionGlobal system prompt contextPer-chunk access verification

Misreading: Embedding models neutralise malicious text payloads

Correct reading: Mathematical vector encoding translates malicious commands into numbers without inspecting, evaluating, or defusing the underlying instructions.

Vectorisation algorithms convert token strings into high-dimensional numerical vectors. These models calculate semantic proximity; they do not run heuristic security analysis or detect adversarial syntax. When a user queries a related subject, the database returns the poisoned text verbatim to be stitched into the prompt. Our related analysis on adversarial examples explains how subtle phrase variations manipulate mathematical boundaries without tripping standard pattern-matching tools.

Ingestion Flow:

Raw File -> Chunker -> Vector Model -> Vector Store [Payload intact]

Execution Flow:

User Query -> Vector Match -> Raw Text Extracted -> Context Window [Payload executes]

Misreading: Document chunking isolates dangerous inputs

Correct reading: Text chunking fragments malicious payloads across boundaries while simultaneously providing multiple extraction hooks for search engines.

Chunking splits large documents into smaller token windows to fit context constraints. While fragmentation might split a long attack across 2 chunks, short payloads execute easily within tiny 200-token blocks. Worse, splitting paragraphs often strips away the surrounding context that human reviewers rely on to identify deceptive framing. The model receives a naked directive detached from its source caveats, increasing the likelihood that the inference engine prioritises the malicious instruction over system rules.

Misreading: RAG eliminates data exfiltration risks

Correct reading: Downstream tools connected to your retrieval loop permit silent data theft via confused deputy attacks.

Context pipelines rarely operate in isolation. When an augmented model retains access to external plugins, web hooks, or downstream APIs, an injected chunk can force the model to transmit sensitive context data to an untrusted endpoint. Treat these models using the framework set out in our guide to treating AI models as untrusted insiders. The threat does not end with the generated output text displayed in the user console; exfiltration happens silently in the background when the model calls connected actions.

  • Validate every outbound action against strict parameter schemas.
  • Restrict automated outbound network connections from the model environment.
  • Log context payloads alongside generated action calls to audit unintended data transfers.

See also: Treat AI Models as Untrusted Insiders: A Step-by-Step Implementation · AI Agent Hijacking Prevention Checklist for Secure Workflows

Infographic: RAG Security: Correcting 6 Architecture Assumptions. Retrieved documents act as unverified user inputs inside the system context window. Embedding models lack classification logic and encode hidden payload instructions directly. Document-level file system permissions do not carry over t
Infographic: RAG Security: Correcting 6 Architecture Assumptions. Free to share with a link to AppSec Scoop.

Misreading: Semantic similarity guarantees accurate security context

Correct reading: Cosine proximity prioritises topical relevance over truth, freshness, and structural integrity.

Search routines evaluate whether a query matches a vector's mathematical direction, not whether the source document is genuine or currently accurate. An attacker who populates a data source with repetitive, mathematically dense variants of an instruction can force retrieval algorithms to favour malicious chunks over genuine policy files. Security checks must review text provenance prior to vectorisation.

  • Verify file authenticity using cryptographic signatures before chunking.
  • Implement strict freshness thresholds to deprecate unmaintained internal guides.
  • Restrict vector retrieval counts to limit excessive context injection.

Key takeaways

  • Retrieved documents act as unverified user inputs inside the system context window.
  • Embedding models lack classification logic and encode hidden payload instructions directly.
  • Document-level file system permissions do not carry over to vector embeddings automatically.
Bottom line

Retrieval pipelines do not sanitize data, so every piece of retrieved context must be treated as untrusted user input. Audit your pre-retrieval identity filtering today to ensure vector searches cannot surface documents the requester has no permission to read.

Frequently asked questions

Can pre-retrieval filters stop all unauthorized data access in RAG?

Pre-retrieval filters stop unauthorized access only if they evaluate user access identity against document access control lists before semantic similarity matching occurs. If the filtering runs after mathematical scoring, metadata leakage and processing overheads can still expose sensitive boundaries.

How does indirect prompt injection enter a RAG pipeline?

Indirect prompt injection enters when ingestion jobs index untrusted external content, such as support tickets, shared documents, or scraped web pages, that contains hidden adversarial instructions. Once retrieved during a user query, those instructions run directly inside the model's context window.

Does context window encryption protect retrieved data from model exploitation?

Encryption protects retrieved data while stored at rest or moving over the network, but it does not protect the data once decrypted into plaintext within the model context window. The model requires readable text to process queries, leaving it open to instruction hijacking regardless of underlying storage encryption.

Why is chunking insufficient for isolating untrusted data?

Chunking merely divides text by token counts or punctuation boundaries without validating content semantics. Concise adversarial instructions easily fit within standard chunk sizes, stripping away contextual warnings that would otherwise alert human reviewers.

How this guide was produced: written by the AppSec Scoop editorial team with AI assistance, checked against the public references listed below, and reviewed when the facts change. See our editorial policy or report an error.

Further reading

  1. OWASP Top 10 for Large Language Model Applications
  2. MITRE ATLAS
  3. NIST AI Risk Management Framework
retrieval-augmented generation securityrag securityprompt injectionvector databases

Related stories

Prompt injection in AI desktop apps: local risks and defences

Desktop artificial intelligence tools process local files alongside remote instructions, creating silent pathways for data exfiltration.