TryHackMyAI

AI security lesson

What Is RAG Security? Attacks, Poisoning, and Defenses

RAG security protects retrieval-augmented generation systems from untrusted documents, manipulated retrieval, data leakage, and instructions hidden inside retrieved content.

How does rag security work?

A RAG application retrieves documents and adds them to model context. Attackers may poison a source, influence ranking, or embed instructions that the model follows as if they were trusted application rules.

  1. Poisoned document
  2. Retrieval
  3. Model context
  4. Instruction override attempt

Safe example

A synthetic benefits document contains a hidden instruction to ignore policy. When retrieved, it attempts to steer the assistant. The lab executes this trace against an isolated local corpus.

How to test safely

  1. Inventory document sources, ingestion controls, and trust labels.
  2. Test poisoned documents in an isolated corpus.
  3. Inspect which passages were retrieved and why.
  4. Verify citations, access controls, and behavior when evidence conflicts.

Defense comparison

ControlEffectivenessWhy it helps
Source provenanceHighIt restricts ingestion and retrieval to accountable sources.
Content filteringMediumIt catches known patterns but can miss novel instructions.
Response groundingMediumIt constrains claims to approved evidence.
Action authorizationHighRetrieved text cannot independently approve consequential tools.

Practice in the RAG System Exploitation lab

Practice identifying poisoned retrieved context and adding provenance, grounding, and authorization controls.

Start public lab

Frequently asked questions

What is RAG poisoning?

RAG poisoning is the placement or manipulation of content so a retrieval system supplies misleading data or malicious instructions to a model.

Are retrieved documents trusted?

No. Retrieved content should be treated as untrusted data even when it comes from an internal index.

Your learning

Finish this lesson

Mark this lesson complete to save it to your learning history.

Sign in to save progress
YOUR NEXT STEP

Opening your learning space

Getting the page ready and syncing your saved progress.

DESKTOP LAB EXPERIENCE

This lab works best on a desktop

The lab console has a terminal, live objectives, and side-by-side details. A laptop or desktop gives you more room to work. You can still continue on this device.

Your account and learning progress stay saved.