keepcalculator

06 Numbers and Powers

AI Security Controls: 8 Must-Have Layers

Card No. 06·69820 · Updated · Standard formula, shown below

Every AI deployment needs a minimum set of security controls to protect data, models, and users. The eight essential layers are: access control, input validation, output filtering, model protection, audit logging, rate limiting, adversarial robustness, and incident response. These controls work together to prevent data leaks, prompt injection, model theft, and abusive use.

Why AI Security Differs from Traditional Software

Traditional software fails when inputs violate expected formats—SQL injection, buffer overflows, etc. AI systems fail differently because they process unstructured data (text, images, audio) and generate outputs that are probabilistic, not deterministic. This means the same attack can succeed on one prompt and fail on another. Also, AI models are often deployed as black boxes, so you cannot easily inspect their internal state. The OWASP Top 10 for LLM Applications (2023) highlights issues like prompt injection, insecure output handling, training data poisoning, and excessive agency—none of which map cleanly to classic web vulnerabilities. Therefore, security controls must be layered at the boundary, the model itself, and the surrounding infrastructure.

Core Control 1: Access Control and Authentication

Every AI endpoint must verify who is calling it and what they are allowed to do. Use standard identity providers (OAuth2, SAML) for human users, and API keys or mTLS for machine-to-machine calls. Enforce least-privilege: a user who only needs text summarization should not be able to call the model with admin parameters. For multi-tenant systems, implement row-level isolation so that one user’s data cannot leak into another’s context. Also, consider role-based access to model versions—some users may be on a stable version while others test a beta. Without this, a disgruntled insider or a compromised API key can cause disproportionate damage.

Core Control 2: Input Validation and Sanitization

AI inputs are not just data—they are instructions. Validate the length, type, and format of every input. For text, enforce maximum token counts (e.g., 4,096 tokens) to prevent denial-of-service via extremely long prompts. For images, verify file type and size, and re-encode to strip embedded metadata. Crucially, treat inputs as untrusted code: strip or escape any characters that could be interpreted as system instructions (e.g., “ignore previous instructions” is a common prompt injection). While you cannot fully prevent injection, you can reduce its impact by not passing raw user input directly into system prompts. Use a separate field for system instructions that the user cannot modify.

Core Control 3: Output Filtering and Content Moderation

AI models can generate harmful, biased, or unsafe content even when the input is benign. Apply a content filter on the output before it reaches the user. This can be a simple blocklist for obvious profanity, a classifier for hate speech, or a more nuanced policy-based filter. For example, if your model is a customer service bot, you might block outputs that give medical or legal advice. Also, consider output length limits—a model that suddenly produces a 10,000-word response to a short query may be under attack. Log all filtered outputs for audit, but be careful not to store sensitive data in logs without encryption.

Core Control 4: Model Protection and Intellectual Property

Your model weights are valuable intellectual property. Protect them by:

  • Never exposing the model directly to the internet; use an API gateway that mediates all calls.
  • Encrypting model weights at rest and in transit.
  • Using hardware security modules (HSMs) or trusted execution environments (TEEs) for high-value models.
  • Monitoring for model extraction attacks—if a user sends many similar queries, they may be trying to replicate your model.
  • Watermarking outputs (e.g., adding subtle statistical patterns) to trace leaks.

For open-source models, protection is less about weights and more about the surrounding data and fine-tuning scripts. Still, you should control access to your training data, which is often more sensitive than the model itself.

Core Control 5: Audit Logging and Monitoring

You cannot secure what you cannot see. Log every request: timestamp, user ID, input hash (not raw input, to protect privacy), model version, output hash, and latency. Store logs in a tamper-evident system (e.g., append-only storage) for at least 90 days. Set up real-time alerts for anomalies: sudden spikes in request volume, repeated failures, or outputs that trigger content filters. Also, monitor the model’s performance metrics—a drop in accuracy or an increase in perplexity may indicate adversarial tampering. For regulated industries (healthcare, finance), these logs are often required for compliance with HIPAA or SOX. Remember to anonymize personal data in logs to avoid creating a new data breach surface.

Core Control 6: Rate Limiting and Quotas

AI inference is expensive—both in compute and in potential data exfiltration. Implement rate limiting per user, per API key, and per IP address. Use a sliding window (e.g., 100 requests per minute) rather than a fixed reset, to avoid bursts. For high-risk operations (e.g., generating a full report), use a separate, lower quota. Also, set a maximum request size and a maximum response size. This prevents both denial-of-service (overloading the GPU) and data theft (a user slowly pulling your entire knowledge base). For paid APIs, quotas are also a billing control—unexpected spikes may indicate a compromised key.

Core Control 7: Adversarial Robustness and Testing

AI models can be fooled by carefully crafted inputs—e.g., adding imperceptible noise to an image changes the classification. To mitigate this:

  • Use adversarial training: include perturbed examples in your training set.
  • Apply input transformation (e.g., JPEG compression, random cropping) to break adversarial perturbations.
  • Run regular red-team exercises: have a dedicated team try to bypass your filters, extract data, or cause the model to misbehave.
  • Test for common attacks: prompt injection, data poisoning, model inversion (reconstructing training data), and membership inference (determining if a specific record was in training).

No model is perfectly robust, so combine these with the other controls. For example, even if an attacker crafts a prompt that bypasses the filter, rate limiting and logging will reduce the blast radius.

Core Control 8: Incident Response and Recovery

Assume a breach will happen. Have a written incident response plan that includes:

  1. Detection: monitoring alerts and user reports.
  2. Containment: the ability to kill the model endpoint (via a kill switch) or roll back to a previous version.
  3. Eradication: removing the compromised model or data.
  4. Recovery: restoring from a clean backup.
  5. Post-mortem: documenting what happened and updating controls.

Also, maintain model versioning so you can quickly revert to a known-good state. Practice tabletop exercises quarterly. For critical deployments, have a backup model (even a simpler rule-based system) that can take over if the AI fails. This is often overlooked but is essential for business continuity.

Common Mistakes and Misconceptions

One common mistake is thinking that a single “AI firewall” product covers everything. In reality, security is layered, and each control addresses a different attack vector. Another misconception is that open-source models are inherently safer because they are transparent—but they are also easier for attackers to study and exploit. Also, many teams forget to secure the data pipeline that feeds the model. If an attacker can poison your training data, they can control the model’s behavior without touching the deployment. Finally, do not rely solely on the AI provider’s security if you are using a third-party API—you still need to control your own inputs, outputs, and logs.

How to Choose the Right Controls for Your Deployment

Start by assessing your risk: What data does the model process? What is the impact of a failure? Then, prioritize controls based on your threat model:

  • If you handle personal data (health, financial), prioritize access control, encryption, and audit logging.
  • If your model is public-facing, prioritize input validation, output filtering, and rate limiting.
  • If your model is proprietary, prioritize model protection and adversarial testing.
  • If you are in a regulated industry, consult the relevant standards (e.g., NIST AI RMF, ISO/IEC 42001) for specific requirements.

Remember that security is not a one-time setup—it requires continuous monitoring and updating as the model and threats evolve.

Frequently Asked Questions

What is the most important security control for AI?

There is no single most important control—it depends on your deployment. However, access control is often the highest priority because it prevents unauthorized use and data exposure. If an attacker cannot reach the model, other attacks are much harder. For public-facing models, input validation and output filtering are equally critical to prevent prompt injection and harmful content.

Can AI models be hacked like traditional software?

Yes, but the attack surface is different. Traditional hacks exploit code bugs (e.g., SQL injection). AI models are hacked through their inputs (prompt injection) or their training data (poisoning). Also, models can be stolen or reverse-engineered via API queries. The same security principles apply—validate inputs, monitor outputs, and restrict access—but the specific techniques differ.

How do I protect my model from being copied?

Use API gateways to prevent direct model access, monitor for unusual query patterns, and consider watermarking outputs. For high-value models, use hardware-based protection (HSMs/TEEs). Also, limit the number of requests a single user can make, and use rate limiting to slow down extraction attempts. There is no perfect defense, but these measures raise the cost of stealing.

What is prompt injection and how do I stop it?

Prompt injection is when an attacker crafts input that overrides the model’s system instructions, causing it to perform unintended actions (e.g., revealing hidden prompts or executing malicious commands). You cannot fully prevent it, but you can reduce risk by separating system and user instructions, filtering inputs for known attack patterns, and not giving the model access to sensitive tools unless absolutely necessary. Also, validate and sanitize all outputs.

Do I need to hire a security expert for my AI project?

If your AI handles sensitive data or is public-facing, yes—at least for a security review. Even a small project can benefit from a consultant who understands AI-specific threats. For low-risk internal tools, you can start with the controls listed here, but you should still involve security personnel early to avoid costly rework.

Are there any legal requirements for AI security?

Yes, depending on your industry and location. The EU AI Act imposes obligations on high-risk AI systems, including risk management and logging. GDPR requires data protection by design and default. HIPAA applies to health data. NIST and ISO provide voluntary frameworks. Always consult a legal expert to determine which regulations apply to your specific use case.

Related

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.

More cards in this drawer

The whole Numbers and Powers drawer →