Join our Newsletter — 33% off our NHI Course
Home› Glossary› Threats, Abuse & Incident Response› Context Window Hijacking
Threats, Abuse & Incident Response

Context Window Hijacking

← Back to Glossary
By NHI Mgmt Group Updated November 16, 2026 Domain: Threats, Abuse & Incident Response

Context Window Hijacking is an attack on a large language model where an attacker manipulates the text, tool output, or other content inside the model’s active context so it follows the attacker’s intent. It works by poisoning the prompt history or retrieved context, which can steer outputs, tool calls, or policy decisions.

What Context Window Hijacking Is

Context window hijacking is not a model bug in the narrow sense, but an attack on the information the model is allowed to treat as current truth. The attacker wins by shaping the active context, so the model follows injected instructions, misleading retrieval results, or manipulated tool output instead of the user’s intent.

Because the attack operates inside the model’s working memory, it can be subtle: the output may look coherent, yet it has been steered by poisoned prompt history, retrieved documents, or prior conversation state. That makes the attack especially dangerous in systems that blend chat, retrieval, and tool use.

How the Attack Works

The attacker’s goal is to smuggle influence into the portion of context the model treats as authoritative. That influence can arrive through user text, retrieved content, prior session material, or tool responses that the model consumes without sufficient trust separation. In practice, the model does not need to be “hacked” externally if its own context can be shaped.

This is closely related to prompt injection and context poisoning, but the distinctive issue is the active context window itself: what is present, what is retained, and what is ranked as most relevant. If an application compacts, truncates, or reorders context poorly, malicious content can persist while the defensive instructions disappear.

For a practical explanation of how context limits, overflow, and context length behaviour shape this attack surface, see Context Windows Explained.

Why Context Window Hijacking Is Dangerous

Once malicious content reaches the active context, it can alter what the model says, what it refuses, what it retrieves next, and which tools it tries to call. That creates a direct path from language manipulation to unsafe action, especially when the model is allowed to draft messages, update records, summarize sensitive material, or trigger downstream workflows.

The security problem is trust confusion. The model may treat untrusted text as instruction, policy, or evidence, because all of it is just tokens in the same window. If the application does not label source trust or isolate memory and retrieval inputs, attacker-controlled content can outvote the genuine user request.

This is particularly acute in agentic systems. A poisoned context can influence memory, planning, or tool selection, turning a single injection into broader compromise of the agent’s behaviour. NHIMG’s AI Agent Memory Security Guide covers the memory-poisoning and cross-user leakage patterns that often sit behind this failure mode.

Defensive Controls and Design Patterns

The safest designs treat context as a governed input stream, not as a flat pile of text. Separate trusted system instructions from retrieved content, label provenance, and avoid letting model-generated or external content overwrite higher-priority policy. Retrieval should be filtered, scoped, and minimized so the model sees only what is necessary for the task.

Compaction and truncation also need care. When context is shortened, attackers may rely on defensive instructions being dropped while their malicious content survives. That is why context management, retention, and source ranking matter as much as prompt-writing. NHIMG’s AI Agent Harness and Context Engineering Security Guide shows how to keep trust boundaries outside the model and make context sources auditable.

Where the attack path includes tool output or retrieval results, secure the upstream systems as well. A model cannot be expected to distinguish truthful content from poisoned content if the surrounding pipeline delivers both in the same trusted format. In those cases, the control problem is as much about input governance as it is about model behaviour.

Detection, Review, and Response

Detection starts with logging what entered the context, from which source, and under what trust label. That makes it possible to spot suspicious instruction shifts, unexpected tool calls, repeated jailbreak-like phrasing, or outputs that align with attacker objectives rather than the user’s request.

After suspected compromise, review the full conversation and retrieval trail, not just the final answer. The important question is whether the model consumed attacker-controlled content as actionable context. If it did, treat the event as a trust-boundary failure, then revalidate prompt templates, memory handling, retrieval filters, and tool permissions before re-enabling the workflow.

For agents that depend on retrieval, memory, and compaction, post-incident review should also check whether one poisoned turn could persist across later sessions. That persistence risk is often what turns a one-off injection into a repeatable control failure.

Risk and Threat Considerations

Context window hijacking matters because the attacker does not need to break the model, only the information boundary around it. If untrusted text can sit inside the same working context as policy, history, or retrieval, the model may execute attacker intent while appearing to behave normally.

Failure mechanism: The model ingests attacker-controlled content as if it were trusted context, then uses that content to steer generation, tool selection, or policy interpretation.

Impact: The result can be misinformation, unsafe tool use, leaked secrets, corrupted decisions, or persistent influence across later turns and sessions.

Standards & Framework Alignment

This section maps relevant standards and security frameworks to the operational risks and controls described in this guidance.

OWASP Agentic AI Top 10 and OWASP API Security Top 10 address the attack and risk surface, while NIST SP 800-53 Rev 5 sets the governance and control requirements practitioners need to meet.

FrameworkControl / ReferenceRelevance
OWASP Agentic AI Top 10ASI06 — Memory & Context PoisoningDirectly covers poisoned context and memory used to steer agent behaviour.
Recommendation — Separate trusted instructions from mutable context and monitor for context poisoning.
NIST SP 800-53 Rev 5AU-2 — Event LoggingContext hijacking defence depends on recording what entered context and from which source.
SI-4 — System MonitoringMonitoring is needed to detect suspicious context shifts and unsafe model actions.
AC-6 — Least PrivilegeTool and data access should be constrained so hijacked context cannot trigger broad actions.
Recommendation — Log context inputs, retrieval sources, and tool outputs for review. Monitor model workflows for anomalous prompts, retrievals, and tool calls. Limit tool and data permissions to the minimum required for the task.
OWASP API Security Top 10API8 — Security MisconfigurationMisconfigured APIs and tool endpoints can leak or trust unsafe context into model flows.
Recommendation — Harden API and tool endpoints so they do not expose untrusted or excessive context.

Practitioner Guidance

What to watch for: Treat any design that merges user input, retrieved text, and long-lived memory without trust labels as a warning sign. The more the system relies on context compaction, automatic retrieval, or multi-step tool use, the more carefully it needs source separation and provenance tracking.

Practitioner takeaway: The practical defence is not “better prompts”, but stronger control over what the model is allowed to see, retain, and treat as authoritative.

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
Reviewed and updated by the NHIMG editorial team on November 16, 2026.
NHI Mgmt Group — the #1 independent authority on Non-Human Identity, IAM, and Agentic AI security. nhimg.org