Lion Cipher Lab

Stop your RAG app from leaking documents: enforce per-user authorization in retrieval

Why it matters

Retrieval-Augmented Generation is now the default way teams put a chatbot on top of their own documents: when a user asks a question, the app RETRIEVES the most similar chunks from a document store and pastes them into the model's prompt as context, so the answer is grounded in real files instead of the model's memory. It is genuinely useful, and it ships with a dangerous default flaw. A vector store ranks by SIMILARITY, and a language model reads whatever text you hand it — neither has any notion of WHO is asking. So the naive pipeline everyone builds first will happily retrieve an HR…

What you'll learn

Steps in this lab

  1. The flaw, in one breath
  2. Set up a free, key-free, offline environment
  3. Build the multi-tenant corpus and the TF-IDF index (rag.py)
  4. Demonstrate the LEAK with your own hands (leak_demo.py)
  5. Why 'just tell the model not to reveal it' is NOT a control
  6. Fix, part A: a PRE-retrieval ACL filter (deny-by-default)
  7. Fix, part B: a POST-retrieval authorization check (belt-and-braces)
  8. Re-run the exact attack: zero leakage (secure_demo.py)
  9. MEASURE it: a leakage counter from N to 0 (measure.py)
  10. OPTIONAL (not graded): a local model, and the real-vector-DB pattern
  11. Judgment: pre vs post, index isolation, and the residual risks
  12. What you built — and the one sentence to keep

Open the full interactive lab →