A year ago, most organisations' AI applications were thin wrappers around a model API. Today, they look more like distributed systems: users authenticate, requests pass through gateways, prompts are assembled from templates and retrieved documents, models call tools, and results flow back into other systems. OpenAI's launch this month of a store for custom GPTs, many of which call external APIs through "actions", is another sign of how quickly AI applications are becoming integrations rather than chatbots.
Securing them requires the same layered thinking we apply to any application stack. Here is that stack, layer by layer.
Layer 1: users and identity
Threats: unauthenticated access, account takeover, abusive automation, users acting outside their permissions.
Controls:
- strong authentication and session management, as for any application,
- identity propagated through every downstream layer so retrieval and tools act as the user,
- per-user rate limits, quotas and abuse detection, and
- clear terms of use and reporting mechanisms for harmful outputs.
Layer 2: application and AI gateway
Many organisations now route model traffic through an AI gateway: a central service between applications and model providers.
Threats: API keys scattered across applications, no visibility into usage, sensitive data sent to unapproved providers, runaway costs.
Controls a gateway provides:
- central management of provider credentials, so applications never hold them,
- routing only to approved models and providers,
- data policies (for example, redacting identifiers or blocking certain data classes for certain providers),
- logging of prompts and responses for audit and debugging, with privacy controls, and
- quotas and cost limits per application and team.
Layer 3: prompts, retrieval and tools
This is where most real-world impact happens.
Prompts. Threats: direct prompt injection, system prompt leakage. Controls: no secrets in prompts, delimited untrusted input, versioned and tested templates.
Retrieval (RAG). Threats: oversharing through missing permission checks, indirect prompt injection in documents, poisoning of the knowledge base. Controls: permission-aware retrieval, controlled ingestion sources, treatment of retrieved text as untrusted.
Tools and plugins. Threats: excessive agency, where a manipulated model triggers privileged actions; insecure tool implementations. Controls: narrow tools with strict schemas, least-privilege credentials, authorisation in code, human approval for side effects.
flowchart TB
U[User] -->|identity| APP[Application]
APP --> GW[AI gateway<br/>policy, logging, quotas]
APP --> CTX[Context assembly]
CTX --> RAG[(Retrieval<br/>permission-filtered)]
GW --> M[Model providers /<br/>self-hosted models]
M -->|tool call proposals| AZ[Authorisation in code]
AZ --> T[Tools & APIs<br/>scoped credentials]
subgraph Data
RAG
DS[(Operational data)]
end
T --> DSLayer 4: models
Threats: provider compromise or outage, unannounced behaviour changes, unsafe self-hosted model files, backdoored open models, model theft for self-hosted models.
Controls:
- approved provider list with contractual data terms,
- pinned model versions and re-evaluation before upgrades,
- safe formats and provenance checks for open models,
- access control and monitoring for self-hosted model weights and endpoints.
Layer 5: data and infrastructure
Threats: training and fine-tuning data leakage or poisoning, exposed vector databases, secrets in notebooks and pipelines, vulnerable ML infrastructure.
Controls:
- classification and access control for all data used by AI systems,
- encryption and network isolation for vector stores and data pipelines,
- secrets management and short-lived credentials,
- patching and hardening of ML frameworks and serving infrastructure.
Cross-cutting: observability and testing
Across all layers:
- tracing that links a user request to retrieval, model calls and tool actions,
- evaluation suites covering quality, safety and security cases, run on every change,
- red teaming before launch and periodically after, and
- incident response plans that include disabling features, rotating keys and purging indexes.
Mapping ownership
| Layer | Typical owner |
|---|---|
| Users & identity | Identity / AppSec |
| Application & gateway | Platform engineering |
| Prompts, RAG & tools | Product engineering team |
| Models | AI platform / architecture |
| Data & infrastructure | Data platform / cloud security |
| Testing & monitoring | Security (with all of the above) |
Clear ownership per layer prevents the most common failure: everyone assuming someone else handled it.
The bottom line
AI applications are stacks, and they are secured the way stacks always have been: layer by layer, with identity flowing through, controls at each boundary and observability across the whole. The layers that most often go wrong (retrieval and tools) are also the ones most under the control of application teams, which makes them the place to start.
Our application security testing assesses AI applications across the full stack, and our agentic AI security team builds them with these controls from the start.