Join our Newsletter — 33% off our NHI Course
Home› Guides› LLM Security Guide: Prompt Injection, Jailbreaks and Data…
Guide AI Security

LLM Security Guide: Prompt Injection, Jailbreaks and Data Leakage

← All guides
By Lalit Choda, NHI Mgmt Group Updated 16 October 2026 17 min read
On this page

A large language model application is an untrusted, probabilistic component wired into trusted systems, and most LLM incidents happen because teams forget that on one side of the model or the other. Attackers talk the model out of its safety behaviour, extract data it should never have seen, push its output into browsers, shells and databases, and run up the inference bill. This guide covers jailbreaks, data leakage and system prompt extraction, output handling, model and endpoint security, and how the OWASP Top 10 for LLM Applications 2025 and MITRE ATLAS describe them. Prompt injection is summarised and linked to its own guide. It is written for application security engineers, AI platform teams and architects who build or approve LLM applications, and it contains no working attack prompts.

Key takeaways

  • Treat the model as an untrusted user on both sides. Inputs can steer it and outputs can carry payloads, so validation, encoding and authorisation belong in deterministic code around the model, not in the prompt.
  • Jailbreaks are a when, not an if. Many-shot, multi-turn and format-based jailbreaks have transferred across every major model family tested; plan for the model's safety training to fail and limit what a jailbroken model can reach.
  • The system prompt is not a secret or a control. OWASP LLM07 is explicit: keep credentials, roles and business limits out of prompts and enforce them in code.
  • Data leakage is mostly an access control problem. A model can only disclose what it was trained on, retrieved or handed in context, so scope data sources per user before inference.
  • Inference endpoints are high-value infrastructure. Rate limits, quotas, authentication, logprob restrictions and key hygiene stop denial of wallet, model extraction and LLMjacking.

The LLM application attack surface

An LLM application has more trust boundaries than a typical web app, each with its own failure mode.

LayerWhat attackers targetOWASP LLM 2025MITRE ATLAS
User promptOverride application intent, bypass safety trainingLLM01 Prompt InjectionAML.T0051, AML.T0054 LLM Jailbreak, AML.T0065 LLM Prompt Crafting
Context (system prompt, RAG, memory)Extract instructions, retrieve other users' data, poison retrievalLLM02, LLM07, LLM08 Vector and Embedding WeaknessesAML.T0056 Extract LLM System Prompt, AML.T0057 LLM Data Leakage, AML.T0071 False RAG Entry Injection
Model outputXSS, SQL injection, code execution, data exfiltration through renderingLLM05 Improper Output Handling, LLM09 MisinformationAML.T0050 Command and Scripting Interpreter, AML.T0077 LLM Response Rendering
Tools and pluginsUse the model's permissions as a confused deputyLLM06 Excessive AgencyAML.T0053 AI Agent Tool Invocation
Inference endpointDenial of service, denial of wallet, model extraction, stolen keysLLM10 Unbounded ConsumptionAML.T0029 Denial of AI Service, AML.T0034 Cost Harvesting, AML.T0024 Exfiltration via AI Inference API, AML.T0055 Unsecured Credentials
Model and data supply chainBackdoored weights, malicious adapters, poisoned fine-tuning dataLLM03 Supply Chain, LLM04 Data and Model PoisoningAML.T0010 AI Supply Chain Compromise, AML.T0058 Publish Poisoned Models, AML.T0020 Poison Training Data

ATLAS IDs are from the ATLAS 5.6.0 data file; check them against the current matrix when mapping detections.

Prompt injection in brief

Prompt injection (OWASP LLM01) underlies many risks below: content the model reads, typed by the user (direct) or embedded in a web page, email, document or tool result (indirect), changes what the model does. Inside the model there is no reliable boundary between instructions and data, so injection is a residual risk. The controls that hold are outside the model: least privilege for tools, human approval for consequential actions, egress restrictions and output handling. See the Prompt Injection Guide for channels, hiding techniques and design patterns. The EchoLeak zero-click flaw in Microsoft 365 Copilot shows indirect injection and output rendering combining into data exfiltration.

Jailbreaks: how they work and how to contain them

A jailbreak targets the model provider's safety training rather than your application's logic. ATLAS tracks it as AML.T0054 LLM Jailbreak under Privilege Escalation and Defense Evasion; Microsoft notes that jailbreaks are also called direct prompt injection attacks. Microsoft classifies Skeleton Key as "Explicit: forced instruction-following" by someone with legitimate access: for enterprise apps jailbreaks are mostly an authenticated-user problem, for consumer apps a public abuse problem.

Technique familyMechanism (high level)What the research showedContainment
Many-shot jailbreakingA single long prompt containing a fabricated dialogue of many compliant answers, then the real requestAnthropic (April 2024) tested up to 256 shots; success followed a power law in shot count, and larger models were often more susceptibleClassify and modify prompts before inference (one method cut success "from 61% to 2%"); cap context length per use case
Multi-turn escalation (Crescendo)Starts with a benign question and escalates gradually, building on the model's own repliesRussinovich et al. reported high success across ChatGPT, Gemini, LLaMA and Anthropic models, and automated itScore the whole conversation, not only the last turn; reset or end sessions on escalation
Guideline augmentation (Skeleton Key)Persuades the model to "update" its rules and add a warning instead of refusingMicrosoft found it worked on most models tested in April and May 2024Input filtering, system message, output filtering and abuse monitoring as separate layers
Format and role play (Policy Puppetry)Prompt dressed as an XML, INI or JSON policy file, combined with role play and leetspeakHiddenLayer (April 2025) reported one template transferring across major frontier and open models, and adapted it for system prompt extractionDo not rely on RLHF alone; output-side classifiers; red team with format variants
Obfuscation and encodingBase64, other languages, character substitution to slip past keyword filtersKeyword and deny-list filters miss encoded or translated requestsClassifiers on decoded text; avoid deny-lists
Fine-tuning circumventionCustom fine-tuning removes safety behaviour from an aligned modelQi et al. (2023) broke GPT-3.5 Turbo guardrails with 10 examples for under $0.20; benign fine-tuning also degraded safetyRe-run safety evaluations after every fine-tune; restrict who can fine-tune and on what data
  • Layer, do not trust a single filter: Microsoft's stack for Skeleton Key is input filtering, a system message, output filtering and separate abuse monitoring; none is sufficient alone.
  • Classify outputs as well as inputs: obfuscated prompts are hard to classify; the harmful output usually is not.
  • Decide what a jailbreak can actually reach: a jailbroken chatbot with no tools and no private data produces embarrassing text. The DPD chatbot incident and the Chevrolet dealer chatbot $1 Tahoe were reputational. The same jailbreak against an agent with write access is an incident.

Data leakage and system prompt extraction

OWASP LLM02:2025 Sensitive Information Disclosure covers personal data, credentials, business data and proprietary logic exposed through output. Each of the four sources needs a different control.

Source of leaked dataExamplePrimary control
Training or fine-tuning dataModel reproduces memorised records or secretsScrub and minimise training data, differential privacy where feasible, extraction testing before release (AML.T0024.000)
Retrieved context (RAG)Another user's documents appear in an answerPermission-aware retrieval that filters by the caller's identity before the model sees content
System prompt and hidden instructionsCredentials, internal limits or role names extracted (AML.T0056)Nothing sensitive in prompts; enforce rules in code
User input sent to the providerStaff paste source code or customer data into a public toolApproved tools with no-training terms, input DLP, logging and retention limits
  • System prompt leakage (LLM07): OWASP says disclosure of the prompt itself "does not present the real risk"; the risk is an application that delegates "strong session management and authorization checks" to the model. Attackers can often infer guardrails from behaviour anyway, so assume the prompt is public.
  • Prompt-level restrictions are weak: OWASP warns that system prompt restrictions on what data to return "may not always be honored and could be bypassed via prompt injection or other methods". Redact or tokenise sensitive fields before they reach the context window.
  • Cross-user leakage: shared caches, vector indexes and conversation history keyed only by session are common causes. Partition by tenant and user, and test with two accounts. See the Permission-Aware RAG Guide.
  • Shadow use: the Samsung ChatGPT source code leak began with staff pasting code into a public tool; offer an approved alternative, not just a ban. See the AI and Privacy Guide for training data and personal data obligations.
  • Logs are a leakage store: prompt and completion logs need the classification and retention of the source data; the DeepSeek database exposure leaked chat logs and API secrets from an open database.

Output handling: never execute what the model says

OWASP LLM05:2025 Improper Output Handling is "insufficient validation, sanitization, and handling of the outputs" before they reach downstream components, leading to XSS, CSRF, SSRF, privilege escalation or remote code execution. Whoever influences the prompt reaches whatever consumes the output.

Output sinkFailureControl
Browser (chat UI, generated HTML or Markdown)XSS; Markdown images that send data to an external URLContext-aware output encoding, strict Content Security Policy (img-src and connect-src allowlists), disable remote image rendering
DatabaseGenerated SQL runs with the app's privilegesParameterised queries or prepared statements, read-only database role, allowlisted query templates
Shell, eval, code interpreterRemote code executionNo exec or eval on output; sandbox with no network, no secrets, seccomp and setrlimit limits
File systemPath traversal from generated file namesCanonicalise paths, fixed base directory, allowlisted extensions
Package installs from generated codeHallucinated package names registered by attackersInstall only from an internal mirror or allowlist; verify package existence and age
Other tools and pluginsCross plugin request forgeryNo plugin-to-plugin calls by default; authenticated user confirmation
  • Remote code execution is real: the LLMSmith study (Liu et al., ACM CCS 2024) tested 6 frameworks and 51 apps, found 13 vulnerabilities (7 CVEs scored 9.8) and 16 apps vulnerable to remote code execution, and recommends least privilege and environment isolation. The Langflow CVE-2025-3248 exploitation shows what happens when an AI workflow server executes code reachable from the network.
  • Confused deputy through plugins: Johann Rehberger's cross plugin request forgery (May 2023) used a browsing plugin to load a page whose hidden instructions made ChatGPT call an email plugin and send a summary to an attacker's URL. Zapier fixed it with an authenticated confirmation step; an unauthenticated confirmation link can itself be clicked by the model.
  • Misinformation is an output risk too: LLM09 covers confident but wrong answers; the Air Canada chatbot ruling made the airline liable for its bot's answer. Ground policy and price answers in approved sources.

Model and endpoint security

OWASP LLM10:2025 Unbounded Consumption covers an application that "allows users to conduct excessive and uncontrolled inferences": variable-length input floods, denial of wallet, continuous input overflow that keeps hitting the context window limit, resource-heavy queries, model extraction through the API and functional replication by training on outputs. The matching ATLAS techniques are AML.T0029 Denial of AI Service, AML.T0034 Cost Harvesting and AML.T0024.002 Extract AI Model.

  • Bound every request and caller: maximum input and output tokens, timeouts, caps on queued actions, and per-user and per-tenant rate limits and spend caps, with provider budget alerts as a second line.
  • Reduce what the API reveals: OWASP recommends restricting or obfuscating logprobs and logit_bias, which help extraction attacks. Expose them only to callers who need them.
  • Authenticate inference servers: self-hosted inference and orchestration servers (vLLM, Ollama, Ray, Langflow and similar) must not listen on public interfaces without authentication. The ShadowRay attacks on exposed Ray clusters stole cloud credentials and AI tokens from unauthenticated AI infrastructure, and the McKinsey Lilli incident started with unauthenticated APIs.
  • Secure the model artefact: OWASP LLM03 warns that model cards "offer no guarantees on the origin of the model" and that malicious LoRA adapters can compromise a base model. Verify signatures and hashes, prefer weight formats that do not execute code on load, and record models and adapters in an AI bill of materials. See the AI Supply Chain and AI-BOM Guide.
  • Protect fine-tuning pipelines: restrict write access to training data and model registries, and re-run safety and leakage evaluations after each training run.

Where identity fits

Provider API keys, gateway master keys, retrieval service accounts and plugin OAuth tokens are non-human identities with direct cost and data impact (ATLAS AML.T0055 Unsecured Credentials). Stolen keys become free inference for attackers, as the LLMjacking campaigns and Storm-2139 abuse of Azure OpenAI showed. Keep keys in a secrets manager, scope them per application and environment, prefer workload identity federation, and give retrieval connectors the caller's identity, not a broad service account. See the LLMjacking Guide and the API Key Management Guide.

Choosing controls for your deployment

DecisionOption AOption BChoose A when
Model hostingProvider API (managed)Self-hosted open-weight modelThe provider's data terms fit your classification; choose B for strict residency or offline use, accepting that you then own patching, authentication and abuse monitoring
GuardrailsProvider content filtersSeparate guardrail service or classifier you controlSingle provider, low risk; choose B for several models or consistent policy and logging
Data accessContext passed per request, filtered by the caller's permissionsFine-tuning on internal dataData has per-user access rules (most enterprise data); fine-tune only on data every user may see
Output useHuman reads the outputOutput drives code, queries or actionsAlways possible; B needs output schemas, validation, sandboxing and approval gates first
  • Small organisations: a managed provider with enterprise data terms, its content filters and spend limits on, read-only use cases, and a proxy for logging and keys.
  • Large organisations: a central LLM gateway that owns provider keys, per-team quotas, guardrail policy, logging and model allowlists, so teams do not each rebuild them.

Implementing LLM security in phases

  1. Inventory: list every LLM application, model, provider, key, data source and tool, including shadow use seen in proxy and expense data.
  2. Threat model each application: map it to OWASP 2025 and ATLAS, and record what a fully jailbroken model could reach.
  3. Fix the deterministic layer first: move secrets out of prompts, enforce authorisation in code, apply output encoding, parameterised queries and CSP, and remove exec paths.
  4. Bound the endpoint: token limits, timeouts, per-identity quotas, spend alerts, authentication on every inference and orchestration server.
  5. Add guardrails in monitor mode: run input and output classifiers in log-only mode for two to four weeks, measure false positives on real traffic, then enforce on high-risk categories.
  6. Red team before release and after change: test jailbreaks, extraction, cross-user leakage and output injection with tooling such as PyRIT, and re-run after model, fine-tune and prompt changes. See Red Teaming AI Agents for Identity Abuse.
  7. Roll out in rings: internal pilot, limited group, then general availability, behind a feature flag that disables tools or reverts the model and prompt. Version prompts and guardrail policies like code so rollback is a deployment.

Detection and measurement

Log each request with caller identity, application, model and version, prompt template version, token counts, guardrail verdicts, tools called with arguments, and output destination; retain full prompt text only where retention rules allow. The NCSC guidelines for secure AI system development put logging and monitoring in the operation and maintenance stage.

  • Alert on: spikes in tokens or spend per identity, many long prompts near the context limit, repeated refusals or guardrail hits from one account, requests for logprobs at volume, outputs containing URLs to unknown domains, and API key use from new networks.
  • Guardrail block rate and false positive rate: measured per category; a falling block rate with stable traffic can mean a new bypass.
  • Red team attack success rate: per jailbreak family and per release, with denominators, tracked over time.
  • Applications with secrets in prompts: target zero, checked by scanning prompt templates in source control.
  • Endpoints without authentication or quotas: target zero across self-hosted and gateway routes.
  • Mean time to revoke a leaked LLM API key: from detection to revocation and replacement.

Framework mapping

Control areaOWASP LLM 2025NIST SP 800-53 Rev. 5CIS Controls v8.1ISO/IEC 27001:2022 Annex A
Input validation and guardrailsLLM01SI-10 Information Input Validation16 Application Software SecurityA.8.28 Secure coding
Output filtering and encodingLLM05, LLM02SI-15 Information Output Filtering16A.8.28
Least privilege for tools and dataLLM06, LLM07AC-6 Least Privilege6 Access Control ManagementA.8.2 Privileged access rights, A.5.15 Access control
Endpoint limitsLLM10SC-5 Denial-of-Service ProtectionNo direct safeguardA.8.6 Capacity management
Model and data supply chainLLM03, LLM04SR-3 Supply Chain Controls and Processes16A.5.21 Managing information security in the ICT supply chain
Logging and monitoringLLM10AU-2 Event Logging, SI-4 System Monitoring8 Audit Log ManagementA.8.15 Logging, A.8.16 Monitoring activities
Adversarial testingAllCA-8 Penetration Testing18 Penetration TestingA.8.29 Security testing in development and acceptance

NIST AI 600-1 lists Information Security, Data Privacy, Confabulation and Value Chain and Component Integration among its 12 generative AI risks, and suggests red-teaming against prompt injection and data poisoning (MS-2.7-007).

Common failure patterns

  • Authorisation in the system prompt: "only discuss the user's own account" written as an instruction while retrieval can read every account; one jailbreak and the rule is gone.
  • Rendering untrusted Markdown: the chat UI loads remote images and links from model output, giving any injected instruction an exfiltration channel, as in EchoLeak.
  • Agent tools with the developer's privileges: a code interpreter or SQL tool running with write access, no sandbox and outbound network, which the LLMSmith study found exploitable to remote code execution.
  • Unauthenticated AI infrastructure: inference, notebook and orchestration servers exposed to the internet by default, as in ShadowRay and Langflow.
  • Long-lived provider keys in code and clients: keys in front-end bundles, mobile apps or public repositories, with no spend cap, leading to LLMjacking and large bills. The Sourcegraph token leak turned a leaked admin token into a free LLM proxy.
  • Testing once: safety evaluated on one model version; then the model, prompt or fine-tune changes and nobody re-runs the tests.

Practitioner checklist

  • Maintain an inventory of LLM applications, models, versions, providers, keys, data sources and tools.
  • Remove credentials, role structures and business limits from system prompts and enforce them in code.
  • Filter retrieved data by the caller's permissions before it enters the context window.
  • Encode all output for its destination, set a strict CSP, block remote image rendering and use parameterised queries.
  • Run any model-generated code in a sandbox with no secrets and no outbound network.
  • Set per-identity token limits, timeouts, quotas and spend alerts, and restrict logprobs and logit_bias.
  • Require authentication on every inference, gateway and orchestration endpoint, and keep provider keys in a secrets manager.
  • Run input and output guardrails, tuned in monitor mode before enforcement, plus abuse monitoring at conversation level.
  • Red team jailbreak, extraction and output injection paths before release and after every model, prompt or fine-tune change.
  • Verify model and adapter provenance with signatures and hashes, and record them in an AI-BOM.

Standards and references

Related NHI Mgmt Group resources: Prompt Injection Guide · LLMjacking Guide · Enterprise AI Copilot Security Guide · AI Supply Chain and AI-BOM Guide · Agentic AI Security Guide

Free weekly newsletter

Subscribe to the NHI & AI Identity Journal

The latest on NHI and Agentic AI security – articles, research, breaches, news and events every week.

Bonus 33% off our NHI Course when you subscribe.

NHIMG Editorial Note
Written and reviewed by Lalit Choda, NHI Mgmt Group. Last updated 16 October 2026.
NHI Mgmt Group — the #1 independent authority on Non-Human Identity, IAM, and Agentic AI security. nhimg.org