NewWork mode: your Claude Code or Codex on work calls, answering from your project's codeSkip to content
Middle0 views

What security issues arise when RAG processes user input (for example, in customer support), and how can they be prevented?

Practice

Asked at

AI answer

The main risks are prompt injections (including in messages and documents), data leaks from context or history, mixing data from different users, malicious or erroneous documents in the database, and unsafe execution of actions through tools.

Practical measures:

  • Treat user input and retrieved documents as untrusted data; explicitly separate them from system instructions. Do not rely solely on prompt instructions to defend against injections.
  • Check access permissions before retrieval and filter documents by user or organization; do not put secrets in context unless necessary.
  • Restrict the tools available to models and their permissions, validate arguments, and require human confirmation for significant actions.
  • Verify the sources and contents of indexed documents, audit changes, and support deletion of outdated or compromised data.
  • Minimize and mask personal data, protect logs, and limit the volume and frequency of requests.
  • Test the system for injections, leaks, and cross-user access; monitor incidents and have a mechanism for stopping dangerous operations.