AI Security Overview
🎯 Introduction
Once an AI application connects to knowledge bases, databases, and tools, it can retrieve business data and initiate operations as well as generate answers. Without security controls, it may expose user information, perform unauthorized operations, or incur excessive model usage costs. This article introduces common risks, attack surfaces, trust boundaries, and defense in depth to help you identify risks and decide where controls belong.
🧱 What security risks do AI applications face?
Traditional web applications need authentication, access control, and resource limits. AI applications need these protections too, along with controls over how models process input and how applications use model output.
For example, an attacker can insert malicious instructions into user input or external documents to try to make a model violate the application's rules. This is called prompt injection. A model may mistake text in reference material for instructions, so prompts alone cannot guarantee security.
An attack surface consists of the entry points and features an attacker could exploit, such as chat endpoints, file uploads, knowledge base retrieval, and tool calls.
The following table lists common risks to consider when developing AI applications:
| Stage | Common risks | Protection |
|---|---|---|
| Receiving requests | Malicious instructions, policy violations | Input validation, content moderation |
| Building context | Sending unnecessary personal information or secrets to the model | Sensitive data protection |
| Retrieving knowledge | Providing another user's documents to the model | Document access control |
| Connecting external tools | Connecting to untrusted MCP servers | Server provenance and tool permissions |
| Performing business operations | Unauthorized data modification or deletion | Server-side authorization, operation confirmation |
| Using model output | Rendering malicious model-generated HTML directly on a page | Output validation, safe rendering |
| Storing conversation memory | Mixing memories from different users | Data isolation, memory write validation |
| Using model resources | Exhausting quotas through excessive requests | Rate, concurrency, and cost limits |
Not every AI application includes all these features. Choose controls based on the features your application actually provides.
🧱 What is a trust boundary?
A trust boundary separates areas with different trust levels or permission scopes. When information or requests cross this boundary, their contents alone cannot establish identity or prove that an operation is authorized.
For example, a user claiming to be an administrator in a conversation must not receive administrator privileges on that basis. The server should verify identity through login credentials, then apply permission rules to determine which operations are allowed.
A model-generated tool call request is not authorization to perform an operation either. The following diagram shows where security checks are needed as information enters the model and its output is used.
Key security checks in an AI application
User input
Questions, instructions, uploaded files
External material
Knowledge bases, web pages, tool results
Application server
Input and data access checks
Verify identity, validate requests, and restrict model data access
AI model
Generate answers or tool call requests
Application
Output checks
Validate answers for their intended use
Frontend
Safe display
Application server
Tool call checks
Validate permissions and arguments
Business system
Execute after checks pass
Dashed boxes mark checks at trust boundaries. Reject or handle failed requests according to application rules.
🧱 What is defense in depth?
Suppose you build an AI assistant that can search documents, and instruct the model to search only documents the current user can access. What happens if the model ignores that instruction and requests another user's private documents?
Before searching, the server must also check the signed-in user's permissions and reject unauthorized requests. That way, even if the model ignores the application instruction, this query cannot expose another user's documents.
Defense in depth means applying multiple security controls at different stages so that other defenses still work when one fails.
❓ Questions and answers
Q1: Do locally deployed models still need AI security controls?
Yes. Local deployment can reduce the risk of sending data to external model services, but it does not automatically address prompt injection, unauthorized access, or unsafe output handling.
Q2: Does passing content moderation authorize a request's business operations?
No. Content moderation and business authorization address different concerns. A request may contain no prohibited content while still asking to access another user's data or perform an unauthorized operation.
🧪 Exercise
Suppose you are building an AI assistant with file uploads, personal document retrieval, and answer generation. For each case below, identify the risk and where the security check should take place:
- An uploaded file contains an API key, and the application is about to send the entire file to the model.
- Knowledge base retrieval returns another user's private documents.
- The model generates HTML that the frontend is about to insert directly into the page.
Acceptance criteria: Identify sensitive data exposure, unauthorized data access, and unsafe output handling respectively. Propose removing secrets before sending data, filtering retrieved documents by user permissions, and rendering output safely as text.
🎉 You can now identify common AI application risks and decide where security controls are needed.
Custom Agents
Build an agent with model nodes, ToolNode, and conditional routing, then integrate it with writing, review, and human approval.
Prompt Injection
Understand direct and indirect prompt injection through information disclosure and unauthorized tool call experiments, and learn basic defenses.
