Embedding Large Language Models (LLMs), retrieval-augmented generation (RAG), and tool-calling agents into web applications introduces new trust boundaries alongside traditional web and API risks. When an application passes untrusted user text—or external documents, emails, and web pages—into a model that can query data or invoke backend functions, attackers look for ways to steer model outputs and tool calls.
Four high-priority risks in AI-enabled web applications
Aligned with the OWASP Top 10 for LLM Applications, security testing of AI features focuses on where model inputs and outputs cross into application code and customer data:
- Direct and indirect prompt injection (LLM01): crafting user prompts—or embedding hidden instructions inside uploaded documents, tickets, or web pages ingested by a RAG pipeline—to override system instructions.
- Insecure output handling (LLM02): rendering model-generated markdown or HTML into the browser without sanitization (causing XSS), or passing model-generated strings directly into SQL queries, shell commands, or URL fetchers.
- Cross-tenant RAG and vector-store leakage: retrieving embeddings or context snippets from a shared vector database without filtering by the signed-in user's `tenant_id` and document permissions.
- Excessive agency in tool calling (LLM08): allowing an LLM agent to invoke state-changing tools (such as sending emails, issuing refunds, or modifying records) without deterministic authorization checks and user confirmation.
Architectural guardrails for LLM features
Never treat a system prompt as an authorization boundary. Enforce tenant and role filters inside the database and vector-retrieval query layer before context ever reaches the model, sanitize all model output before rendering it in the DOM, cap per-user token and tool-invocation budgets, and require explicit server-side permission checks and human confirmation before executing any state-changing tool call.
Treat LLM outputs as untrusted data, enforce tenant filtering in your database and vector queries, and gate every agent tool call behind deterministic authorization.