20. AI Security#
AI systems add new ways to attack information systems, and IT is responsible for defending them. This chapter catalogs the main threats to AI systems, the defenses that reduce them, and red teaming as a disciplined way to test an AI system before attackers do.
AI Threats: Prompt injection, data leakage, and model abuse target AI systems in new ways.
Defenses: Input filtering, least privilege, and output checks, together called guardrails, reduce the damage an attack can do.
Red Teaming: Planned attack testing finds weaknesses before release.
Chapter Video
This explainer shows how hidden instructions can hijack an AI system, the threat at the top of the list this chapter works through.
Prompt Injection, Clearly Explained (5:46) by ByteByteAI
Hosted on YouTube; property of its original creator, embedded here for educational reference only.
Learning Objectives
By the end of this chapter, you will be able to:
Explain direct and indirect prompt injection and their consequences.
Identify ways sensitive data can leak through AI systems.
Apply layered defenses such as input filtering, least privilege, and output checks.
Plan and report a red-team test of an AI assistant.
Test an assistant against prompt injection attacks in Python.
Chapter Flow
Glossary
# |
Term |
Explanation |
|---|---|---|
1 |
Threat model |
A structured description of what could attack a system and how. |
2 |
Attack surface |
All the points where an attacker can try to interact with a system. |
3 |
Direct prompt injection |
A user typing instructions that override a system’s rules. |
4 |
Indirect prompt injection |
Malicious instructions hidden in content the model reads, such as a web page or email. |
5 |
Jailbreak |
A prompt designed to make a model ignore its safety rules. |
6 |
Data leakage |
Exposure of sensitive data through model output, logs, or prompts. |
7 |
Data poisoning |
Corrupting training or retrieval data to change a system’s behavior. |
8 |
Input filtering |
Screening input for known attack patterns before it reaches a model. |
9 |
Output filtering |
Checking model output before it is shown or acted on. |
10 |
Defense in depth |
Using several independent layers of protection. |
11 |
Red teaming |
Deliberately attacking a system to find weaknesses. |
12 |
Sandbox |
An isolated environment that limits what code or tools can affect. |
13 |
Destination allowlist |
Approved destinations under a parsed address policy. |
14 |
Rules of engagement |
Authorized targets, actions, data handling, and stop conditions. |
15 |
Benign control |
A legitimate task used to detect harmful blocking. |
16 |
Inconclusive test |
A test without a resolved security outcome. |
17 |
Residual risk |
Risk remaining after a mitigation. |
18 |
Security regression |
A repeatable check for a known failure. |
19 |
Indirect injection |
Adversarial instructions arriving through retrieved or external content. |
20 |
Trust boundary |
A boundary between inputs with different authority or permissions. |
21 |
Tool allowlist |
An explicit set of operations an application may dispatch. |
22 |
Excessive agency |
A system having broader action authority than the task requires. |
23 |
Attack success rate |
The successful fraction of a defined set of resolved attack tests. |
24 |
Guardrails |
Runtime policy checks enforced around a model on its input, output, or proposed actions. |