Summary
NousResearch hermes-agent up to version 0.12.0 contains an injection vulnerability in the _compress_context function of run_agent.py, where untrusted data is combined into a context string without adequate sanitization.
In deployments where remote input can influence the compressed context, an attacker may inject crafted content that alters downstream processing or execution, potentially leading to unauthorized actions in high-privilege environments.
Affected context
This issue affects deployments of hermes-agent (up to 0.12.0) that:
- Accept remote or otherwise untrusted input that is incorporated into the agent's context
- Use the _compress_context function in run_agent.py to condense or transform conversation/context data
- Pass the resulting compressed context into downstream components (e.g., command runners, template engines, interpreters, or external tools) without strict separation between data and control
The risk is heightened where the agent has access to sensitive systems or automation hooks that act on its generated outputs.
Exploit preconditions
- Attack surface: Remote, via interfaces (API endpoints, chat connectors, webhooks, or integrations) that feed user-controlled data into hermes-agent.
- Required access: Ability to submit or influence content that will be processed by _compress_context, such as messages, prompts, or external event payloads.
- Trigger point: Invocation of _compress_context during context building or truncation, after which the compressed context is used by downstream logic or tools.
- Why exploitation is possible: The implementation does not sufficiently neutralize or encode control syntax when merging user-controlled content into a composite context string, allowing attacker-supplied fragments to be interpreted as commands, directives, or structured control tokens by subsequent consumers.
Why this happens
The core issue is an injection flaw consistent with CWE-74: Improper Neutralization of Special Elements in Output Used by a Downstream Component.
The _compress_context function combines multiple pieces of data into a unified context representation but fails to robustly escape, encode, or separate user-controlled content from control or structural syntax.
As a result, when this compressed context is later consumed by a parser, interpreter, tool framework, or automation layer, embedded special characters or control sequences can change behavior instead of remaining inert data.
This pattern also relates to CWE-707: Improper Neutralization, as it reflects a broader failure to consistently handle dangerous characters across the data transformation pipeline.
Potential impact
- An attacker may inject specially crafted content that alters the behavior of downstream tools or automation wired to the agent.
- Injected payloads could cause unintended commands to be executed by integrated systems (e.g., shell commands, API calls, or administrative actions), depending on the environment.
- The agent's decision-making or response generation can be steered toward attacker-controlled objectives, potentially leading to data exposure or integrity violations.
- In tightly integrated environments, the issue may contribute to a broader compromise of connected services or workflows.
General mitigation guidance
Effective mitigation focuses on treating all context fragments derived from untrusted sources as data, never control, and enforcing strict neutralization at the boundaries where context is constructed:
- Robust encoding and escaping: Normalize and escape special characters in user-controlled values before they are merged into the compressed context, especially characters that are meaningful to downstream parsers, interpreters, or template engines.
- Structured representations: Prefer structured data (e.g., JSON objects, typed records) rather than ad-hoc string concatenation when representing context; let downstream components consume well-defined fields instead of parsing free-form text for control semantics.
- Layered trust boundaries: Clearly separate trusted system metadata from untrusted user content; avoid mixing them in the same field or format where control tokens and data interleave.
- Least-privilege integrations: Configure any tools, connectors, or automation that act on agent outputs with minimal required permissions, limiting the blast radius of any injected behavior.
- Input validation policies: Apply conservative size limits and content validation (e.g., allowed character sets, disallowed control sequences) on input that will be fed into context compression.
How teams detect issues like this
Detection efforts can focus on identifying risky string handling patterns and validating how compressed context is consumed:
- Static analysis: Flag locations in run_agent.py and related modules where user-controlled data is concatenated, interpolated, or formatted into context strings without escaping or encoding, especially before passing to downstream interpreters or tools.
- Code review signals: During review, pay attention to helper functions like _compress_context that aggregate large amounts of user-driven content; ensure they apply a consistent neutralization strategy and treat all untrusted input as opaque data.
- Policy enforcement: Introduce guidelines that prohibit direct string-based command construction or protocol framing from agent context, enforcing the use of structured APIs or parameterized interfaces for all external actions.
- Runtime monitoring: Instrument logging for anomalous or unusually structured context segments and for unexpected downstream operations originating from agent-driven workflows; use these traces to refine validation rules.

