Summary
Hermes-Agent 2026.4.23 contains a prompt injection vulnerability in the _scan_context_content function of agent/prompt_builder.py, where untrusted content is inserted into model prompts without sufficient sanitization.
A remote attacker who can influence context content can inject malicious instructions into the agent's prompt flow, potentially causing the agent to perform unintended actions or leak sensitive information.
Affected context
The vulnerability occurs in environments where Hermes-Agent ingests external or user-supplied content (for example, conversation history, retrieved documents, or tool outputs) and passes it through _scan_context_content during prompt construction.
When this content is treated as trusted and embedded directly into prompts or instructions, the agent may interpret attacker-controlled text as authoritative commands or system-level guidance.
The issue is most relevant when the agent is wired to tools, APIs, file systems, or other side-effectful capabilities without strong guardrails on what the model is allowed to request or perform.
Exploit preconditions
- Attack surface: Any Hermes-Agent deployment that accepts remote input or integrates external context sources (e.g., webhooks, HTTP APIs, chat interfaces, retrieval systems).
- Required access: Ability to supply or influence content that flows into
_scan_context_content(such as chat messages, documents, or context metadata). - Trigger point: Prompt construction time, when the agent composes or updates its internal prompt using
_scan_context_contentand sends it to the model backend. - Why exploitation is possible: Untrusted context data is not sufficiently validated, normalized, or constrained before being merged into the prompt, allowing attacker-controlled segments to override or subvert intended instructions and policies.
Why this happens
At its core, this is a CWE-74: Improper Neutralization of Special Elements in Output Used by a Downstream Component, manifested in the domain of large language model prompts.
The _scan_context_content function appears to incorporate context elements directly into a structured prompt without differentiating between data and control instructions, effectively giving external text the same authority as system or developer roles.
This pattern is reinforced by CWE-707: Improper Neutralization, where a generalized failure to sanitize or constrain complex inputs allows adversarial content to alter downstream behavior.
Conceptually, the agent treats all context as benign descriptive data, but the LLM interprets parts of it as executable-style instructions, creating a channel for prompt injection and behavior steering.
Potential impact
- The agent could follow attacker-injected instructions instead of its configured policy or system prompt.
- Sensitive information stored in context (e.g., conversation history, API keys in logs, internal notes) could be exfiltrated via model responses.
- Connected tools or APIs (e.g., HTTP clients, filesystem access, task runners) could be misused to perform unauthorized actions such as arbitrary HTTP requests, file operations, or task scheduling.
- Output integrity may be compromised, causing data poisoning of downstream systems that consume the agent's responses.
- The agent's safety constraints and guardrails can be weakened or bypassed if prompt hierarchy is not enforced.
General mitigation guidance
Effective mitigation focuses on strict separation of instructions from data, context sanitization, and capability scoping:
- Treat all user and external text as untrusted: ensure it is inserted into prompt regions clearly marked as data, not instructions, and avoid giving such text privileged roles.
- Normalize and filter context content before it reaches
_scan_context_content, stripping or escaping patterns commonly used for prompt injection (e.g., meta-instructions that attempt to override or disable policies). - Enforce a layered prompt architecture with immutable system-level instructions that cannot be overridden by lower-priority content, and explicitly define what the model must ignore.
- Restrict and compartmentalize the agent's tool and API capabilities using least privilege, so that even if instructions are partially subverted, the blast radius is limited.
- Introduce policy checks around high-risk actions (e.g., external network calls, file writes) that require explicit confirmation, secondary validation, or rule-based approval before execution.
How teams detect issues like this
Detection typically relies on a combination of code-level and behavior-level analysis:
- Static analysis and code review: Look for functions like
_scan_context_contentthat aggregate external inputs into prompts or command-like structures without filtering, role separation, or explicit tagging as "data only." - Prompt architecture review: Examine prompt-building logic for patterns where user or external content is concatenated into high-privilege sections (system prompts, tool instructions) or used to alter agent policies.
- Runtime monitoring: Log prompts and tool invocations (with sensitive data redacted) and analyze them for signs of injected meta-instructions, policy overrides, or unexpected tool usage.
- Policy enforcement: Introduce linters or CI checks that flag direct concatenation of untrusted data into prompts, and enforce coding standards for prompt construction and tool invocation.
- Automated testing: Create adversarial test inputs designed to attempt prompt injection and verify that the agent maintains its configured behavior and respect for safety rules.

