SecurityΒ forΒ LLMΒ andΒ agentΒ systems
Introduction
Generative features inherit the same engineering bar as any internet-facing serviceβwith extra attack surface from untrusted text in context, tools and MCP servers callable by the model, and retrieval that can pull in poisoned or private material. The checklist below matches the Security lens used on Production Agent-RAG Architectures: data ingest and index, API and edge, LLM and prompt safety, then privacy and operations.
DataΒ ingestion:Β cleaningΒ andΒ sanitization
Everything you chunk, embed, or index is attacker-controlled surface once it can enter a prompt. Ingestion should assume messy sources, deliberate poisoning, and compliance constraints.
- π₯ Trust and scope β define allowed sources; control who may upload or sync; require approval for untrusted corpora when risk warrants it.
- π₯ Pipeline shape β extract β normalize β de-boilerplate β preserve structure β chunk β embed β index; keep failure reasons inspectable.
- π₯ Uploads β allowlisted MIME types; hard max size; reject executables; malware scan; extract text in a sandbox with no execution of file payloads.
- π₯ Metadata and access β ACL, tenant, and role on every chunk; enforce at query time; dedupe by content hash (update or skip re-uploads).
- π₯ Failure handling β dead-letter queue with reason (parse errors, oversize, virus); never silently drop audit-critical rejects.
- π₯ Storage β object storage with no execution from the bucket; short-TTL signed URLs when you must hand out direct reads.
AIΒ APIΒ security
Model and orchestration endpoints are high-cost, high-blast-radius APIs: abuse for scraping, credential theft, and chained tool calls.
- π₯ Transport and edge β TLS only; HSTS for browser surfaces; CDN or reverse proxy with DDoS and WAF (coarse rules, not a substitute for app validation).
- π₯ AuthN and AuthZ β short-lived access JWTs with refresh rotation and revocation; mTLS or service identity for internal hops; tenant-scoped authorization on every request.
- π₯ Headers and browser policy β set secure headers (XSS, CSRF, SSRF protections as applicable); CORS intentionally; CSRF strategy when you use cookie sessions.
- π₯ Validation and abuse β schema-based bodies; global and per-tenant rate limits and quotas; timeouts on LLM and vector DB calls; max payload sizes.
- π₯ API design β versioned paths; idempotency keys for mutating and ingest jobs.
- π₯ Errors and logging β centralized handling; generic errors to clients; no secrets or raw stack traces in responses; redact tokens from logs; lock down OpenAPI in production if it leaks internals.
- π₯ Orchestration and tools β allow-lists for MCP and HTTP tools; scoped credentials; confirmations on destructive, financial, or cross-tenant actions.
InputΒ handlingΒ forΒ AIΒ workloads
Chat, uploads, and retrieved spans share one context unless you separate policy from dataβwhere indirect prompt injection and tool abuse actually land.
- π₯ Moderation β classify user input and optionally model output; block or clamp when above risk thresholds.
- π₯ Tools β strict allowlist; no shell, arbitrary fetch, or code execution unless routed through a gated pipeline; stricter limits on agent and tool routes than on plain chat.
- π₯ Prompting β clearly delimit user or document content; keep developer instructions apart from retrieved facts; treat every retrieved string as untrusted (indirect injection).
- π₯ Policy and governance β system rules for scope and refusal; human review for high-risk corpora or admin-only uploads when needed.
- π₯ RAG hygiene β cap and score context; tombstone or rebuild poisoned segments; never let a hit override system policy by wording alone.
- π₯ Multimodal β sandbox parsers; treat extracted text as hostile; do not let filenames or EXIF steer behavior.
- π₯ Downstream use β encode outputs when rendered as HTML; validate tool arguments before side effects.
PrivacyΒ &Β operations
- π₯ Logging β PII classification; retention limits; redaction where required (GDPR-style).
- π₯ Monitoring β latency, retrieval health, cost, failures (as in Monitoring / Analytics).
Conclusion
Ingest, API edge, prompt surface, and privacy ops are one system: weak ingestion poisons retrieval; weak edge control leaks keys; weak prompt boundaries let tools misfire; weak logging hides abuse. Revisit the checklist whenever you change models, corpora, or tool allowlistsβand keep it aligned with how you ship Agent-RAG in production.