/

CVE-2026-33718

Severity:

HIGH RISK

(7.6)

Command Injection in OpenHands Git Diff Handler

CVE-2026-33718

Analyzed

Vulnerability type

Category:

Command Injection

CWE:

CWE-78

Impact:

Arbitrary Command Execution in Sandbox

Severity:

HIGH RISK

(7.6)

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

OpenHands contains a command injection issue in the get_git_diff() method, where the path parameter from the /api/conversations/{conversation_id}/git/diff endpoint is passed directly into a shell command.

An authenticated user can craft a malicious path value to execute arbitrary commands inside the agent sandbox, bypassing the normal, mediated command-execution channel.

Affected context

The vulnerability occurs in OpenHands deployments that expose the /api/conversations/{conversation_id}/git/diff API and rely on the get_git_diff() helper in runtime/utils/git_handler.py.

It manifests when user-supplied path values are interpolated into shell commands used to compute git diffs, without adequate sanitization or escaping.

The issue is limited to the agent sandbox environment but effectively bypasses the intended control layer that normally mediates which commands the agent runs.

Exploit preconditions

  • Attack surface: HTTP API at /api/conversations/{conversation_id}/git/diff
  • Required access: Authenticated ability to invoke conversation APIs and supply a path parameter
  • Trigger point: Calling the git diff endpoint with a crafted path that alters the shell command line
  • Why exploitation is possible: The path value is concatenated or formatted directly into a shell command without strict validation, escaping, or the use of non-shell execution APIs, allowing additional commands or arguments to be injected.

Why this happens

This weakness maps to CWE-78: Improper Neutralization of Special Elements used in an OS Command.

The core problem is treating user-controlled input as trusted when constructing shell commands, typically via string concatenation, interpolation, or shell=True invocation.

Because the shell parses metacharacters (such as separators, redirections, and substitutions), any untrusted string placed into a command context can change the intended behavior, leading to execution of attacker-controlled commands within the agent sandbox.

Potential impact

  • Execution of arbitrary shell commands within the agent sandbox environment
  • Bypassing OpenHands' normal agent command mediation and logging pathways
  • Modification, exfiltration, or deletion of files accessible in the sandbox
  • Use of the sandbox as a pivot point to attempt further attacks against adjacent resources, depending on sandbox isolation strength
  • Evasion of higher-level policy or guardrail logic that assumes all commands come through sanctioned channels

General mitigation guidance

Effective mitigation focuses on eliminating direct shell interpretation of user input and tightening trust boundaries around command execution:

  • Prefer high-level language APIs (e.g., direct Git library calls or subprocess execution without a shell) instead of constructing shell strings.
  • If external commands are necessary, use parameterized process invocation (e.g., argument arrays) and explicitly avoid shell parsing.
  • Validate and normalize user-supplied paths against an allowlist of expected patterns or directories, rejecting or sanitizing unexpected input.
  • Treat all API parameters, even from authenticated users, as untrusted and subject to strict input handling.
  • Enforce sandbox hardening and least-privilege on the process executing git operations, minimizing the blast radius if command execution is abused.

How teams detect issues like this

Detection typically combines code-centric and runtime approaches:

  • Static analysis: Configure rules to flag shell-command construction involving user-controlled variables (e.g., subprocess with shell=True, os.system, or similar APIs), especially where HTTP or API parameters flow into those calls.
  • Code review: Look for patterns where request parameters (e.g., path) are interpolated into command strings, or where git operations are invoked via shell instead of safer library calls.
  • Security testing: Include automated tests and dynamic analysis that fuzz command-related parameters for injection indicators (unexpected output, failures, or extra processes).
  • Policy enforcement: Integrate pre-merge checks that reject new uses of unsafe command execution primitives, and require justification or security review for any remaining shell-based code.

Sources

SourceLink
docs.python.orgdocs.python.org/3/library/shlex.html#shlex.quote
docs.python.orgdocs.python.org/3/library/subprocess.html#security-considerations
github.comgithub.com/OpenHands/OpenHands/pull/13051
github.comgithub.com/OpenHands/OpenHands/security/advisories/GHSA-7h8w-hj9j-8rjw
owasp.orgowasp.org/www-community/attacks/Command_Injection

Frequently asked

questions

Yes, it is exploitable via the exposed HTTP API, but only by authenticated users who can call the /api/conversations/{conversation_id}/git/diff endpoint and control the path parameter.

The attacker needs valid access to the OpenHands API and the ability to initiate or interact with conversations that allow calling the git diff endpoint. They do not need direct shell access; the injection occurs through crafted API requests.

Replace shell-based git invocations with safe, non-shell alternatives (such as Git libraries or subprocess calls with argument lists), and ensure that any user-controlled input is validated and never interpolated into shell command strings.

Establish coding standards that prohibit passing untrusted data to shell interpreters, enforce static analysis rules against unsafe command construction, and require security-focused code review for any feature that executes system commands or interacts with the filesystem based on user input.

Find out what's already
exploitable in your codebase.