Cyber Knowledge · Domain 11 of 11 · Practitioner field guide

AI Security

AI security protects the complete socio-technical system around models: data pipelines, model artifacts, prompts, retrieval, application code, identities, plugins, agents, MCP servers, infrastructure, people, and decisions. This guide connects engineering, adversarial testing, monitoring, response, and governance so teams can move from a demo that “uses AI” to a system with explicit boundaries and reviewable evidence.

Scope and safety boundary

Use adversarial techniques only against systems you own or are explicitly authorized to assess. Model output is untrusted data, not authority. Never give an AI system broader tool, data, or network access than the task requires, and never treat an automated score as proof of security, privacy, compliance, or model correctness.

Version 1.0 Published Source review: Status: maintained practitioner guide Maintained by Andrey Pautov Editorial policy and corrections

Purpose, mental model, and learning outcomes

AI security is not a synonym for prompt filtering. A production system may combine a hosted or local model, system prompts, retrieval indexes, user content, memory, APIs, tools, agents, browsers, files, queues, databases, and human approvals. Each component has a different owner and trust level. The security objective is therefore to preserve confidentiality, integrity, availability, accountability, and safe human decision-making across the whole chain.

You will be able to

  • Draw a data-flow and trust-boundary model for an AI application.
  • Separate model behavior risks from ordinary application and infrastructure vulnerabilities.
  • Design least-privilege retrieval, agent, and MCP tool access.
  • Build abuse cases, tests, telemetry, response playbooks, and release evidence.

Evidence you should produce

  • System inventory, model/data provenance, and owner register.
  • Threat model with assumptions, abuse cases, and control owners.
  • Adversarial test corpus, results, residual-risk decisions, and regression gates.
  • Runtime audit trail, incident playbooks, and governed change history.

Map the AI system before testing it

AI security architecture connecting data provenance, model integrity, retrieval and RAG, agent tools and MCP, and monitoring and governance around a protected model
Security is a property of the connected system—not the model in isolation.
LayerAssetsTypical trust failureRequired evidence
ExperienceUI, API, conversation, filesUntrusted content becomes an instructionInput origin, tenant, policy decision, output destination
OrchestrationSystem prompt, routing, memory, agent loopInstruction hierarchy or state is confusedPrompt version, route, tool plan, approval event
KnowledgeDocuments, embeddings, vector index, graphPoisoned or unauthorized context is retrievedSource identity, ACL, chunk lineage, retrieval score
ModelWeights, tokenizer, adapters, endpointUntrusted artifact or unsuitable model is deployedDigest, origin, evaluation, deployment approval
ActionFunctions, plugins, MCP servers, credentialsModel output invokes excessive capabilityActor, arguments, authorization, result, rollback
PlatformCompute, network, secrets, logs, CI/CDConventional compromise reaches AI assetsConfiguration baseline, identity, telemetry, build provenance

Fourteen-module learning path

Module 01

AI security foundations and threat landscape

Begin with three distinct questions: can an attacker compromise the application around the model, can untrusted content manipulate model-mediated behavior, and can the system cause unacceptable harm even without a conventional exploit? These overlap but require different tests and owners. An authorization flaw is still an authorization flaw; a retrieved document that changes an agent’s goal is an indirect prompt-injection problem; a plausible but false answer is a reliability and decision-control problem.

Use the NIST AI Risk Management Framework to organize governance and risk work, the OWASP GenAI Security Project for application abuse classes, and MITRE ATLAS for adversary behaviors. Treat these as complementary lenses rather than interchangeable checklists.

Working method

  1. Define business purpose, affected people, unacceptable outcomes, and accountable owner.
  2. Classify system type: predictive model, generative assistant, RAG service, autonomous workflow, or security copilot.
  3. Inventory external dependencies and conventional attack surface.
  4. Record which decisions are advisory, human-approved, or automatically executed.
  5. Translate risks into observable security properties and testable acceptance criteria.
Boundary: “The model refused my prompt” is not a security control assessment. Test the application, identities, data paths, and downstream effects.
Module 02

Architecture, assets, trust boundaries, and AI threat modeling

Create both a component diagram and a data-flow diagram. Mark every transition where content, identity, authority, or provenance changes. Model user input, uploaded documents, web retrieval, system instructions, conversation memory, vector search, model calls, tool calls, human approval, and output publication as separate flows. Shared infrastructure does not imply shared authorization.

Extend ordinary STRIDE-style analysis with AI-specific abuse cases: instruction override, retrieval poisoning, model extraction, membership inference, unsafe tool planning, resource exhaustion, insecure output consumption, and cross-tenant context leakage. For each case, document preconditions, attacker-controlled inputs, affected asset, observable signal, preventive control, recovery control, and residual uncertainty.

Threat-model record

  • System claim: what the feature is allowed to do—and explicitly cannot do.
  • Authority: whose identity is used for retrieval and action.
  • Untrusted channels: prompts, files, pages, connectors, model output, and tool output.
  • Decision gates: deterministic policy checks and human approvals outside the model.
  • Failure containment: rate limits, timeouts, transaction scope, rollback, and kill switch.

Connect the model to application threat modeling, cloud architecture boundaries, and the scenario-based risk process.

Module 03

Training data, ingestion, retrieval, RAG, and knowledge integrity

Data security spans collection, licensing, classification, preprocessing, training, embedding, indexing, retrieval, caching, retention, and deletion. A RAG system creates a new authorization surface: a document may be legitimate to store but illegitimate to retrieve for a particular user, tenant, task, or model. Embeddings are not an access-control boundary, and vector similarity is not evidence quality.

Preserve source URL or object identity, author/publisher, collection time, tenant, handling marking, checksum, parser version, chunk offsets, ACL, and supersession state. Apply authorization before retrieval results reach the prompt. Quarantine unknown formats, scan uploads, constrain parsers, and prevent fetched content from being interpreted as system authority. Detect duplicate, stale, contradictory, and poisoned material.

RAG integrity workflow

  1. Accept only permitted sources and record provenance.
  2. Normalize without destroying the original evidence.
  3. Classify sensitivity and bind source ACLs to every chunk.
  4. Validate parser output and reject active or malformed content.
  5. Measure retrieval relevance, authorization correctness, citation accuracy, and poisoning resistance.
  6. Reconcile additions, updates, deletions, and embedding-model changes.
1200km implementation context: compare these controls with the AdversaryGraph unified RAG and MCP guide, where source-linked CTI, IOC, CVE, and ATT&CK context must remain attributable and analyst-reviewable.
Module 04

Model and dependency supply-chain security

Models are executable dependencies with large transitive trust. Record provider, repository, model card, license, intended use, training disclosures, digest, serialization format, tokenizer, adapters, quantization, runtime, evaluation set, and deployment approval. Pin immutable revisions. Never load an untrusted pickle-like artifact into a privileged environment merely because it is called a model.

Apply ordinary software supply-chain controls to Python packages, containers, inference runtimes, GPU drivers, prompt templates, evaluation code, browser automation, MCP servers, and model gateways. Generate an SBOM where supported, scan artifacts, verify signatures or attestations, isolate conversion jobs, and retain a reproducible build path. Provider model aliases can change behavior without changing your code; production systems should detect and review that drift.

Release evidence

  • Approved model and dependency inventory with owners and end-of-life dates.
  • Artifact hashes, signature/attestation status, malware scan, and isolated load test.
  • Task-specific quality and abuse evaluations against the exact deployed configuration.
  • Rollback candidate and compatibility evidence for prompts, embeddings, and tools.

See software supply-chain assurance and model/artifact triage principles.

Module 05

Prompt injection, instruction hierarchy, and secure output handling

Prompt injection is the attempt to make untrusted content influence instructions or decisions. Direct injection arrives from the user; indirect injection arrives through retrieved documents, email, web pages, images, tool responses, or memory. Delimiters, hidden prompts, and “ignore previous instructions” filters may improve robustness, but they do not create a security boundary.

Keep policy enforcement outside the model. Separate instructions from content in the application data model, label provenance, minimize context, and let deterministic code authorize tools and output destinations. Treat every generated value as untrusted: validate JSON against a strict schema, constrain enumerations and lengths, encode for the destination, parameterize database operations, and never execute generated shell, SQL, HTML, or URLs without independent controls.

Test corpus

  • Direct and multilingual override attempts.
  • Instructions embedded in HTML, PDFs, images, metadata, and tool output.
  • Requests to reveal system prompts, secrets, memory, or other tenants’ data.
  • Malformed structured output, dangerous URLs, command substitution, and stored payloads.
  • Multi-turn attacks that progressively alter state or exploit approval fatigue.
Accept only when: high-impact actions remain blocked by authorization and approval controls even when the model follows the attacker’s instruction.
Module 06

Privacy, secrets, confidential data, and model leakage

Map personal data, credentials, source code, customer content, security evidence, and regulated records across prompts, files, logs, traces, caches, vector stores, fine-tuning datasets, provider retention, and support channels. “Do not train on my data” addresses only one part of the lifecycle. Define purpose, minimization, locality, retention, deletion, access, export, and incident obligations for every copy.

Use secret detection before model submission, but do not rely on redaction alone: transformed or encoded values can remain sensitive. Prefer short-lived scoped credentials delivered only at the tool boundary. Prevent the model from reading raw secret stores. Evaluate memorization and extraction risk for custom models; test cross-session and cross-tenant leakage; and ensure logs preserve security evidence without silently becoming a second sensitive-data lake.

Review questions

  • Which provider and region receive each class of content?
  • Can users delete conversations, uploaded sources, embeddings, and derived memory?
  • Who can access prompts and traces for support or monitoring?
  • What happens when content is quoted in an evaluation dataset or incident ticket?

Pair this module with privacy engineering and data governance and cloud data protection.

Module 07

Agents, tools, plugins, browsers, and MCP security

An agent turns model output into state change. Its risk is determined by reachable capability, credential scope, data visibility, autonomy, iteration count, and reversibility—not by the model’s marketing name. MCP standardizes discovery and invocation of tools and resources, but it does not automatically make a server, tool description, returned content, or authorization policy trustworthy.

Maintain an allowlist of server identities and pinned versions. Authenticate both sides where applicable. Validate tool schemas, constrain arguments, and authorize each invocation using the requesting user and task—not a universal agent credential. Separate read from write tools; isolate high-risk tools in containers or sandboxes; block arbitrary command execution and unrestricted egress; cap recursion, time, tokens, cost, and result size; and require explicit approval for destructive, external, or privilege-changing actions.

Agent transaction pattern

  1. Planner proposes a bounded action with reason and expected effect.
  2. Deterministic policy evaluates user, tenant, tool, arguments, data class, and risk.
  3. Human approval is requested for material external effects.
  4. Executor uses a scoped, short-lived credential in an isolated environment.
  5. Result is treated as untrusted content and validated before reuse.
  6. Audit record links request, policy, approval, execution, result, and rollback.

Explore the local ecosystem through the HexStrike AI security testing guide, AI-assisted offensive-security analysis, and AdversaryGraph MCP architecture.

Module 08

Identity, authorization, tenancy, and human approval

Authenticate the human or workload at the application boundary, propagate identity deliberately, and re-authorize at retrieval and action boundaries. Do not let the model infer permissions from natural-language claims. A user who may ask about a record does not necessarily have permission to retrieve its raw source, export it, or invoke an action against it.

Use tenant-aware object identifiers, row/document-level controls, explicit workspace membership, and service identities per environment. Protect system prompts and administrative configuration as privileged objects. Approval dialogs must state the exact action, target, data leaving the boundary, credential context, and rollback—not merely ask “Allow AI?”. Prevent replay and bind approval to immutable arguments and expiry.

Abuse cases

  • Cross-tenant retrieval through ambiguous entity names or cached context.
  • Confused-deputy action using a more privileged service account.
  • Privilege escalation by editing a tool description, prompt template, or routing rule.
  • Approval substitution where displayed arguments differ from executed arguments.

Continue with identity threat detection and response and application identity and session security.

Module 09

Infrastructure, network, resource, and availability security

Protect inference endpoints, gateways, notebooks, training jobs, vector stores, queues, object stores, GPU nodes, and management planes with ordinary hardening and segmentation. Private deployment does not remove supply-chain, insider, or tenant risks. Restrict network egress so model-mediated fetches cannot become SSRF, metadata-service access, internal discovery, or data exfiltration.

Availability threats include expensive prompts, unbounded context, decompression bombs, high-cardinality retrieval, recursive agents, adversarial inputs that trigger slow paths, provider quota exhaustion, and cascading retries. Enforce input and output limits, concurrency budgets, per-tenant quotas, circuit breakers, queue backpressure, timeouts, and cost alerts. Design a degraded mode that disables risky automation while preserving essential operations.

Baseline evidence

  • Network and identity policy for every AI service and data store.
  • Secret delivery, rotation, and emergency revocation test.
  • Capacity, quota, timeout, and cost-abuse test results.
  • Backup, restore, regional/provider failure, and kill-switch exercises.

Use the cloud AI workload controls and cloud response evidence as companion material.

Module 10

AI red teaming, evaluation, and reproducible security testing

Security evaluation must be task-, architecture-, language-, and impact-specific. Separate model robustness tests from end-to-end security controls. Build a versioned corpus from threat models, production incidents, public techniques, internal policy, and expected user behavior. Include benign controls so the team measures over-blocking as well as bypass.

Record exact model/provider, temperature and relevant parameters, system prompt revision, retrieval snapshot, tool set, policy version, tester, time, attempts, and result. Because model behavior is probabilistic, repeat tests and report rates with sample size instead of presenting a single transcript as proof. Sanitize external test data and avoid sending protected content to unapproved services.

Assessment sequence

  1. Confirm authorization, targets, data handling, stop conditions, and communications.
  2. Map exposed functions and ordinary web/API vulnerabilities.
  3. Test prompt, retrieval, output, tool, tenancy, privacy, and availability abuse cases.
  4. Validate impact through safe canaries and reversible actions.
  5. Retest controls, add regression cases, and document residual risk.

See AI and MCP offensive testing, AI-assisted vulnerability research, and the hands-on AI penetration-testing lab.

Module 11

Logging, monitoring, detection, and security analytics

Log enough to reconstruct decisions without indiscriminately copying sensitive content. Useful events include authenticated actor and tenant, session/request ID, model and prompt-policy version, retrieval source IDs, policy decisions, tool proposals and calls, approval events, output validation, safety-control outcomes, latency, tokens, cost, errors, and data destination. Protect logs against tampering and apply strict access and retention.

Detect unusual tool sequences, new servers, denied-action spikes, cross-tenant lookup attempts, repeated extraction patterns, sudden output-volume or cost changes, sensitive-data indicators, retrieval of quarantined sources, prompt-template changes, and policy bypass. Correlate AI events with IAM, endpoint, cloud, proxy, and application telemetry. Behavioral alerts are investigation leads, not automatic proof of malicious intent.

Detection engineering loop

  1. Define the abuse hypothesis and required telemetry.
  2. Generate a safe positive case and ordinary negative cases.
  3. Write, test, and version the analytic.
  4. Measure visibility, precision, latency, and investigation cost.
  5. Attach response actions and rerun after model or workflow changes.

Operationalize this with detection engineering, CTI-to-detection handoff, and AdversaryGraph for analyst-reviewed relationships and validation context.

Module 12

AI incident response and forensic readiness

Define AI-specific incident categories before an event: unauthorized disclosure, poisoned knowledge, compromised model or dependency, abusive automation, unauthorized tool action, cross-tenant leakage, integrity failure, availability/cost attack, and unsafe published output. Establish ownership across security, ML/AI engineering, application, privacy, legal, provider management, and business operations.

Preserve the exact prompt and policy versions, conversation and request IDs, retrieved source identities, model endpoint/version, tool arguments and results, approval record, relevant configuration, and surrounding cloud/application events. Avoid assuming a transcript alone explains the decision: orchestration, retries, hidden context, caches, and policy layers matter. Revoke credentials and disable tools independently from shutting down the entire service.

Response sequence

  1. Declare severity from observed impact and reachable capability.
  2. Contain identities, tools, connectors, sources, routes, or model versions.
  3. Preserve evidence with handling and access controls.
  4. Determine whether the failure was compromise, abuse, misconfiguration, drift, or expected model uncertainty.
  5. Recover with fixed policy and regression evidence.
  6. Notify affected owners and meet contractual or legal duties.

Use the broader incident triage and incident governance workflows.

Module 13

Governance, risk, assurance, transparency, and human factors

Maintain an inventory of AI use cases, owners, models, providers, data classes, affected users, decision authority, connected tools, deployment status, and review date. Classify risk from context and impact rather than model size alone. Shadow AI and embedded vendor features belong in the inventory when they process organizational data or influence decisions.

Document intended use, prohibited use, limitations, human oversight, user notice, appeal/escalation path, evaluation evidence, change triggers, incident history, and residual-risk acceptance. Claims such as “secure,” “private,” “compliant,” or “bias-free” require scoped evidence. Track provider and regulatory change, but consult qualified counsel for applicability; a field guide cannot determine legal obligations.

Assurance questions

  • Can an independent reviewer trace each material claim to evidence?
  • Are human reviewers trained, given time, and able to reject automation?
  • Do metrics include harmful misses, false blocks, near misses, and downstream impact?
  • Does a material model, data, prompt, tool, or purpose change trigger reassessment?

Integrate with AI governance and safe GRC automation and the section’s source and AI-assistance policy.

Module 14

Secure AI development lifecycle and production release gate

Embed AI security into product discovery, architecture, data onboarding, implementation, evaluation, release, monitoring, and retirement. Maintain controls as code where appropriate, but keep accountable decisions visible. Every material change to model, provider, embedding, knowledge source, system prompt, tool, permission, or output destination can invalidate earlier evidence.

A production gate should combine ordinary application security with AI-specific checks. Require model and dependency provenance, data and privacy approval, threat model closure, retrieval authorization tests, prompt-injection and output-validation tests, tool-policy tests, tenancy tests, monitoring coverage, incident playbook, rollback, and explicit residual-risk acceptance. A successful benchmark or frontend build alone is not a release decision.

Minimum release gate

  • Named owner, approved use case, system map, and risk classification.
  • Pinned deployable configuration and rollback candidate.
  • No unresolved critical conventional or AI-specific abuse path.
  • High-impact actions protected by deterministic authorization and approval.
  • Evaluation report includes configuration, samples, rates, limitations, and negative controls.
  • Telemetry, alert routing, response playbook, and kill switch tested.
  • Change and periodic review dates recorded.
Release decision: approve only the tested configuration and scope. Record exceptions with owner, expiry, compensating control, and retest date.

Threat-to-control decision map

ThreatPreventDetectRecover
Indirect prompt injectionConstrain sources and capabilities; external authorizationSource lineage, denied tool calls, canary instructionsQuarantine source; revoke session/tool; regression test
RAG poisoningApproved ingestion, provenance, ACLs, reviewDrift, contradiction, duplicate, and anomalous-source checksRemove chunks, rebuild index, invalidate cache
Unsafe agent actionLeast privilege, schema validation, approval, sandboxAction sequence and argument policy alertsStop agent, revoke token, roll back transaction
Cross-tenant leakageTenant-scoped storage and pre-retrieval authorizationCross-tenant access and canary monitoringContain, preserve, notify, rotate, repair isolation
Model supply-chain compromiseTrusted source, hash/signature, isolated validationArtifact/config drift and runtime behavior monitoringRollback, rebuild, revoke, hunt affected systems
Cost/availability abuseQuotas, limits, timeouts, recursion capsToken, cost, queue, latency, and retry anomaliesCircuit breaker, degraded mode, provider failover

End-to-end case studies

Case 1: RAG security analyst

Scenario: Internal reports, IOC records, CVEs, and ATT&CK data support analyst questions.

  1. Classify sources and preserve record/chunk provenance.
  2. Enforce workspace and TLP policy before retrieval.
  3. Test poisoned reports, conflicting facts, and source deletion.
  4. Require citations and analyst approval before downstream use.
  5. Monitor source, retrieval, provider, and response lineage.

Evidence: authorization matrix, poisoning tests, citation accuracy, reconciliation report, audit trail.

Case 2: MCP vulnerability-assessment agent

Scenario: An assistant proposes authorized scanner actions against inventory assets.

  1. Bind target ownership and assessment authorization.
  2. Allowlist tools and constrain target, ports, rate, and network route.
  3. Require approval for active scanning and prohibit arbitrary command execution.
  4. Validate scanner output before model reuse.
  5. Store tool evidence separately from AI interpretation.

Evidence: target authorization, policy decision, tool arguments, raw result, interpretation, rollback/stop test.

Case 3: Customer-support assistant

Scenario: A multi-tenant assistant reads account records and drafts actions.

  1. Authorize every lookup by customer and agent identity.
  2. Prevent conversation memory crossing account boundaries.
  3. Block untrusted attachments from changing tool authority.
  4. Require confirmation for refunds or account changes.
  5. Test deletion, export, and support-log access.

Evidence: tenant isolation tests, approval binding, privacy flow, audit reconstruction.

Case 4: AI-assisted security research

Scenario: A researcher uses a local model to classify code and evidence.

  1. Keep samples and secrets in an isolated lab.
  2. Record model/prompt versions and label generated claims.
  3. Validate findings with disassembly, execution evidence, or source documentation.
  4. Prevent generated commands from running automatically.
  5. Publish limitations and reproducible evidence.

Evidence: lab boundary, prompt/output record, analyst corrections, independent validation.

Hands-on lab programme

Lab 1 — Prompt and output boundary

Build a small document summarizer. Seed one document with an indirect instruction, enforce source labeling, validate structured output, and demonstrate that no model response can authorize a filesystem or network action.

Lab 2 — Tenant-safe RAG

Create two tenant corpora with canary records. Implement authorization before retrieval, run cross-tenant query variations, test deletion/reindexing, and prove canaries never enter unauthorized context.

Lab 3 — Least-privilege MCP

Expose one read-only and one state-changing tool. Pin server identity, validate arguments, require approval for the write, cap execution, record an audit chain, and test a malicious tool response.

Lab 4 — AI detection and response

Generate safe prompt-injection, enumeration, denied-tool, and cost-spike events. Correlate them with identity and application logs, investigate, disable a connector, preserve evidence, and rerun a regression test.

Use only isolated, authorized targets. Relevant ecosystem practice includes 1200km security labs, AI-PT-Lab, HexStrike AI, and the browser-based Threat Matrix for ATT&CK exploration.

Production readiness checklist

  • Every model, data source, connector, tool, and owner is inventoried.
  • Trust boundaries and high-impact abuse cases are documented.
  • Retrieval and actions use caller-aware authorization.
  • Model output is validated and encoded for its destination.
  • Secrets and sensitive content are minimized and governed across providers and logs.
  • Agent and MCP capabilities are allowlisted, scoped, bounded, and auditable.
  • Adversarial tests cover direct/indirect injection, tenancy, leakage, tools, and availability.
  • Monitoring can reconstruct a decision without exposing unnecessary content.
  • Containment, credential revocation, source quarantine, rollback, and kill switch are tested.
  • Residual risk is accepted by a named owner for the exact deployed configuration.

Authoritative frameworks and ecosystem reading

External primary references