AI Security Engineering: A Practical Defense Blueprint
Threat-model the whole AI system, from input and retrieval to tool execution and output handling.
- Identify trust boundaries
- Apply least privilege
- Build a security evaluation suite
Map the system before attacking it
Draw the user interface, API, model provider, vector store, identity provider, tools and logging service. Mark which components receive confidential information and which can perform actions. Inventory assets: customer data, credentials, model configuration, documents and business operations. A threat model should describe attacker goals, entry points and potential impacts.
Prompt injection and data boundaries
Direct injection comes from a user input; indirect injection may arrive through documents or tool responses. Delimit untrusted text and instruct models not to execute instructions from it, but do not rely on prompts as a security boundary. Enforce permissions, output validation and action restrictions outside the model. A retrieved document cannot authorize a new operation.
Data and identity
Use individual identities and scoped service credentials. Enforce document access control before retrieval and verify tenant isolation. Keep API keys in server-side secret storage. Never embed a provider key in a static site’s JavaScript. Redact sensitive data in traces and define a retention period. Review what external providers receive and under which contract.
Outputs and actions
Do not send generated HTML, SQL or shell commands directly to an interpreter. Render text safely, parameterize database queries and constrain tools to allowed operations. Use sandboxed execution where appropriate. For irreversible actions, show the precise planned change and require approval from an authorized person.
Operational defense
Build an authorized test suite containing indirect injections, cross-tenant access attempts and output-encoding cases. Include ordinary workloads to measure whether defenses harm legitimate tasks. Establish incident handling: disable affected tools, rotate exposed credentials, investigate logs, and document remediation. OWASP guidance and NIST risk management provide starting points, not a guarantee of safety.
Practice & self-check
Threat-model a fictional AI support assistant. Write ten tests using synthetic data, including a prompt injection that asks the assistant to access another tenant.
Why is a system prompt not a security boundary?
The model can misinterpret or be manipulated; enforce access policy in trusted code.
What should you do if a client-side API key is exposed?
Revoke or rotate it, remove it from public assets, and investigate unauthorized usage.
