TestUnity LLC

    TestUnity LLC

    Securing Technology, Empowering Innovation

    All articles
    AI SecurityRAGLLM

    Securing RAG Systems: A Practical Checklist

    TestUnity Security Team16 August 20268 min read

    Retrieval-augmented generation (RAG) is how most enterprises make AI useful: instead of relying on a model's general knowledge, you retrieve relevant chunks from your data and feed them to the model to ground its answer. It's powerful — and it opens security gaps that a plain chatbot doesn't have. Here's a practical checklist for securing a RAG pipeline end to end.

    The RAG attack surface

    A RAG system has four stages, each with its own risks:

    1. Ingestion — documents are chunked and embedded into a vector store.
    2. Storage — embeddings and source text live in a vector database.
    3. Retrieval — a user query fetches the most relevant chunks.
    4. Generation — the model answers using those chunks.

    Get the security wrong at any stage and you can leak data across users or let poisoned content steer answers.

    Ingestion

    • Validate and clean sources. Untrusted documents can carry indirect prompt injection — malicious instructions embedded in the text that the model later obeys.
    • Classify data on the way in. Know what sensitivity each document carries so retrieval can respect it.
    • Control who can add documents to the knowledge base.

    Storage (the vector database)

    • Enforce tenant isolation. In a multi-tenant product, one customer must never retrieve another's chunks. This is the most common and most serious RAG flaw.
    • Attach access-control metadata to every chunk (owner, role, sensitivity) so retrieval can filter on it.
    • Secure the vector store itself — authentication, network isolation, encryption at rest.

    Retrieval (the critical control point)

    • Filter by permission at query time. Retrieve only chunks the requesting user is allowed to see — apply their access rights before results reach the model, not after.
    • Never rely on the prompt to enforce access. "Only answer from documents the user can see" in the system prompt is not a security control.
    • Cap how much is retrieved to limit exposure and cost.

    Generation and output

    • Keep secrets out of the context window.
    • Filter outputs for sensitive data before returning them.
    • Show citations so users can verify answers and you reduce the impact of hallucinations.
    • Treat model output as untrusted if it flows into any other system.

    Governance

    • Log retrievals and answers for audit — important under the UAE PDPL if personal data is involved.
    • Support deletion. If a source document or a person's data must be removed, you need to purge it from the vector store too (a "right to be forgotten" requirement).
    • Re-test after changes to the knowledge base or retrieval logic.

    The one flaw to never ship

    If you remember one thing: enforce access control at retrieval, per user, in code. The single most damaging RAG vulnerability is cross-tenant or cross-user data leakage caused by retrieving chunks the requester should never have seen. Everything else is important; this one is non-negotiable.

    Frequently Asked Questions

    What is a RAG system?

    RAG (retrieval-augmented generation) is an AI architecture that retrieves relevant information from your own data and feeds it to a language model so its answers are grounded in that data rather than only the model's general training.

    What is the biggest security risk in RAG systems?

    Cross-tenant or cross-user data leakage. If retrieval isn't filtered by the requesting user's permissions, the system can surface information one user is not allowed to see. Access control must be enforced at retrieval time, in code — not in the prompt.

    Can RAG systems be prompt injected?

    Yes. Documents ingested into the knowledge base can contain hidden instructions (indirect prompt injection) that the model obeys when it retrieves them. Validate and clean ingested content and treat retrieved text as untrusted.

    How do I secure a RAG pipeline?

    Validate ingested sources, isolate tenants in the vector store, attach access-control metadata to chunks, filter retrieval by the user's permissions, keep secrets out of the context, show citations, and log retrievals for audit.

    Build RAG securely

    TestUnity designs and secures RAG solutions for UAE organisations — accurate, access-controlled, and audit-ready. Discuss your use case with our AI team.