Severity:

HIGH RISK

(7.3)

Prompt / Command Injection into Generated Instructions

CVE-2026-9366

Deferred

Vulnerability type

Category:

Prompt / Command Injection into Generated Instructions

CWE:

CWE-74, CWE-707

Impact:

Remote Prompt/Command Injection Leading to Unintended Agent Actions

Severity:

HIGH RISK

(7.3)

CVSS version:

3.1

Catch this CVE while code is being written

Detect vulnerable code directly in pull requests, so CVEs are fixed before merge.

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_content and 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_content that 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.

Sources

SourceLink
gist.github.comgist.github.com/YLChen-007/581fd92de5548fbaacb2092e848a75cc
vuldb.comvuldb.com/submit/812227
vuldb.comvuldb.com/vuln/365329
vuldb.comvuldb.com/vuln/365329/cti

Frequently asked

questions

Yes. If Hermes-Agent is exposed via a network interface (such as a web API, chatbot, or integration), a remote attacker who can submit or influence inputs that become part of the agent's context can attempt prompt injection.

The attacker does not need local or administrative access; they only need the ability to provide data that ultimately flows into _scan_context_content. This could be as simple as sending crafted messages to a chat endpoint or providing documents that the agent ingests and summarizes.

The safest pattern is to enforce strict separation between instructions and data by confining untrusted content to clearly designated, low-privilege prompt regions, combined with sanitization and normalization of all external inputs. Additionally, ensure that system and developer instructions are immutable and cannot be overridden by user or context text.

Future designs should adopt a secure prompt engineering model from the outset: define explicit roles and trust levels for each prompt segment, treat all external content as untrusted data, enforce least privilege for tools and integrations, and incorporate adversarial testing and automated checks for prompt injection vectors as part of the development lifecycle.

Find out what's already
exploitable in your codebase.