Severity:

HIGH RISK

(7.3)

OS Command Injection in hermes-agent terminal_tool

CVE-2026-9367

Deferred

Vulnerability type

Category:

OS Command Injection

CWE:

CWE-77, CWE-78

Impact:

Remote Code Execution via OS Command Injection

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 contains an OS command injection vulnerability in the terminal_tool component, specifically within the detect_dangerous_command function in tools/approval.py.

When untrusted input is incorporated into shell commands without proper sanitization, a remote attacker can craft input that executes arbitrary operating system commands on the host where the agent runs.

Affected context

The vulnerability arises in environments where hermes-agent is deployed with the terminal_tool enabled and allowed to execute shell commands on behalf of users or upstream systems.

It becomes risky when:

  • External or user-controlled text is passed into terminal commands,
  • The agent runs with network exposure (e.g., serving requests over HTTP, websockets, or through a broker),
  • And command strings are constructed or filtered by detect_dangerous_command before execution.

Under these conditions, crafted input can bypass or subvert the detection logic and reach an underlying shell with attacker-controlled content.

Exploit preconditions

  • Attack surface: Remote, via any interface that routes user-supplied text into the terminal_tool (API endpoints, chat interfaces, workflows, or orchestration layers).
  • Required access: Ability to submit or influence command strings or parameters processed by detect_dangerous_command in tools/approval.py.
  • Trigger point: Execution of a shell command formed using the attacker-controlled input, often through wrappers that rely on the detection logic for safety.
  • Why exploitation is possible: The function responsible for detecting or filtering dangerous commands does not fully neutralize shell metacharacters or prevent command concatenation, allowing attacker-controlled segments to be interpreted by the shell as additional commands.

Why this happens

This issue stems from constructing and executing shell commands using untrusted input without robust neutralization or isolation, while relying on incomplete "dangerous command" detection heuristics.

Instead of using parameterized or non-shell-based execution APIs, the implementation allows user-controlled strings to influence the command line that a shell interprets, making it vulnerable to injected operators (such as chaining, redirection, or subshell syntax).

Conceptually, this maps to:

  • CWE-78: Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection'), where special characters and structures are not fully handled.
  • And is related to CWE-77: Improper Neutralization of Special Elements used in a Command ('Command Injection'), reflecting the broader pattern of embedding untrusted data into executable commands.

The core design flaw is treating user input as text to be "checked" rather than strictly treated as data separated from command execution semantics.

Potential impact

  • Remote execution of arbitrary operating system commands with the privileges of the hermes-agent process.
  • Reading, modifying, or deleting files accessible to the agent's runtime user.
  • Pivoting to other internal services or networks reachable from the compromised host.
  • Installing backdoors, miners, or other persistent malware on the host.
  • Exfiltration of configuration secrets, API keys, or environment variables used by the agent.
  • Disruption of normal agent operation, including denial of service through resource exhaustion.

General mitigation guidance

Effective mitigation focuses on removing shell interpretation from the path of untrusted input and hardening command execution patterns:

  • Prefer high-level, parameterized APIs (e.g., direct library calls, subprocess invocation with argument lists and shell=False) instead of passing strings to a shell.
  • Treat all user-supplied or remote data as untrusted; avoid building command strings through concatenation or formatting.
  • Where shell usage cannot be eliminated, strictly whitelist allowed commands and arguments, rejecting any input that does not match a narrow, validated pattern.
  • Implement robust input validation that focuses on what is allowed rather than trying to enumerate "dangerous" tokens, and perform validation before any command construction.
  • Reduce process privileges for the agent so that, if compromise occurs, the scope of damage is limited (least-privilege user accounts, restricted file and network access).
  • Isolate the command execution environment via containers, sandboxes, or separate worker processes with tightly controlled interfaces.

How teams detect issues like this

Detection typically combines code-level analysis with runtime monitoring:

  • Static analysis: Configure rules to flag use of shell execution APIs (os.system, subprocess with shell=True, or similar) where arguments include variables or data derived from external input.
  • Code review signals: Look for functions that:
  • Attempt to "detect dangerous commands" via string matching,
  • Concatenate user input into commands,
  • Or rely on blacklists of tokens instead of strict whitelists or argument lists.
  • Policy enforcement: Define secure coding policies prohibiting shell execution with unsanitized input, enforced in CI via linters or security scanners.
  • Runtime monitoring: Use logging and security monitoring to detect anomalous command patterns, unexpected utilities being invoked, or spikes in process creation originating from the agent.
  • Automated SAST/IAST tools can assist in identifying injection sinks and untrusted data flows into command execution points.

Sources

SourceLink
gist.github.comgist.github.com/YLChen-007/75fb10319693e86106ced2ef3a472c80
vuldb.comvuldb.com/submit/812228
vuldb.comvuldb.com/vuln/365330
vuldb.comvuldb.com/vuln/365330/cti

Frequently asked

questions

Yes. If hermes-agent is exposed over the network and accepts input that flows into terminal_tool, an attacker can exploit the vulnerability remotely by submitting crafted command strings.

The attacker must be able to supply or influence the text that is processed by detect_dangerous_command and ultimately passed to the command execution path—this could be through an authenticated session, an upstream integration, or any interface that allows issuing commands.

The safest pattern is to eliminate shell-based command construction with untrusted input: use parameterized, non-shell APIs and strictly control what operations the agent can perform. Where shell use is unavoidable, enforce strong allowlists for commands and arguments and avoid interpolating raw user input into command strings.

Adopt secure coding practices around command execution, including mandatory use of argument-based subprocess calls, centralized wrappers that enforce validation and whitelisting, and security reviews for any code that interacts with the system shell. Integrate automated security scanning into CI to flag new instances of command construction from untrusted data.

Find out what's already
exploitable in your codebase.