AI agent and LLM app security guides
How attacks on LLM apps and AI agents actually work, mapped to the OWASP Top 10 for LLM Applications, with fixes in code: tool permissions, output handling, egress control, quotas and logging.
- Prompt injection through retrieved documents (RAG) – what it is and how to contain itHow instructions hidden in retrieved documents hijack a RAG chatbot (indirect prompt injection), and the layered fixes that actually limit the damage it can do.
- LLM tool calls with over-broad permissions – a least-privilege pattern that holdsWhy giving an LLM agent run_sql or an admin key is excessive agency (OWASP LLM06), and a least-privilege design with per-user auth, schemas and confirmations.
- AI API keys and system prompts in frontend code – find them and move the call server-sideWhy OpenAI or Anthropic keys and system prompts in VITE_ or NEXT_PUBLIC_ variables are public, how to find them in your bundle, and move AI calls server-side.
- MCP server security basics – untrusted tool descriptions, local code and token scopeThe real risks of MCP servers: local code you run, tool descriptions and results the model trusts, and over-scoped tokens. Rules for users and server authors.
- LLM output rendered as HTML or run as SQL/shell – XSS and injection, and the safe patternsRendering LLM output with innerHTML or passing it to SQL or a shell is improper output handling (OWASP LLM05). How each attack works and the safe pattern.
- SSRF through an AI agent's “fetch this URL” tool – how it happens and how to block itAn AI agent's fetch_url tool can be steered to cloud metadata, localhost and internal services (SSRF). Validate the resolved IP, redirects and egress.
- Indirect prompt injection in email and calendar agents – one message, full accessHow a single email or calendar invite can hijack an AI assistant that reads your inbox, and the controls that stop data leaving: tool gating, scopes, rendering.
- Jailbreak vs prompt injection – the difference that decides your defencesJailbreaks and prompt injection are related but not the same. Who attacks, what breaks, and which defences in an LLM app actually address each one.
- Per-user token quotas for an LLM endpoint – stop unbounded consumption (OWASP LLM10)Stop one account from draining your OpenAI or Anthropic budget: a server-side key, daily per-user token quotas in Postgres, output caps and provider limits.
- Audit logs for AI agent tool calls – record enough to answer “why did it do that?”What to record for every AI agent tool call, how to keep the log append-only in Postgres, what to redact, and the queries that answer 'what did it do?'