/

CVE-2026-30307

Severity:

CRITICAL RISK

(9.8)

OS Command Injection in Roo Code Command Auto-Approval

CVE-2026-30307

Analyzed

Vulnerability type

Category:

OS Command Injection

CWE:

CWE-94

Impact:

Remote Code Execution (RCE) without user interaction

Severity:

CRITICAL RISK

(9.8)

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

Roo Code's command auto-approval module is vulnerable to OS command injection when parsing shell commands using fragile regular expressions and an ineffective whitelist.

By embedding malicious payloads in shell substitutions ($(...) or backticks) within seemingly benign commands (for example, git operations), an attacker can achieve remote code execution without additional user interaction.

Affected context

This vulnerability affects environments where Roo Code's command auto-approval module:

  • Automatically approves commands based on regex-derived whitelists (e.g., recognizing "safe" git commands)
  • Passes those commands to an underlying shell for execution
  • Does not robustly parse or neutralize shell metacharacters such as $(...) and backticks

The issue is most relevant when Roo Code is configured to run shell commands on behalf of users or automations and when that approval logic is treated as a security boundary.

Exploit preconditions

  • Attack surface: The command auto-approval interface in Roo Code (e.g., chat/assistant actions, automation scripts, or integrations that submit commands for approval and execution).
  • Required access: Ability to influence or submit commands that Roo Code evaluates (for instance, via a user request, plugin call, or upstream automation that the assistant trusts).
  • Trigger point: The moment Roo Code's auto-approval module inspects the command, classifies it as a whitelisted pattern (such as a git operation), and forwards it to the shell.
  • Why exploitation is possible: The approval logic relies on brittle regex matching that only looks at superficial command structure, failing to treat shell substitution syntax as dangerous. As a result, arguments containing $(...) or backticks are misclassified as safe, but the underlying shell evaluates them first, executing attacker-controlled code.

Why this happens

The root cause is a design that attempts to enforce security through pattern-based filtering of shell commands, combined with incomplete parsing of shell semantics.

Instead of constructing command invocations via structured APIs (for example, argument arrays or direct library calls), Roo Code assembles and passes text commands through a shell. The auto-approval module uses regular expressions and a whitelist to recognize commands like git log as safe but does not properly account for shell metacharacters inside arguments. Shell substitution constructs ($(...), backticks) are therefore treated as harmless text.

This aligns with CWE-94 (Improper Control of Generation of Code), because user-controllable input is embedded into a context that the shell interprets as executable code, without correct neutralization or structural separation. The system incorrectly assumes that superficial command classification is sufficient to prevent dangerous behavior.

Potential impact

  • Remote execution of arbitrary OS commands under the permissions of the Roo Code runtime.
  • Exfiltration of sensitive data such as source code, API keys, SSH keys, and configuration files.
  • Modification or destruction of application code, repositories, or build artifacts.
  • Installation of backdoors, cryptominers, or other persistent malware on the host.
  • Lateral movement into other systems reachable from the compromised environment.
  • Tampering with CI/CD pipelines or developer tooling to introduce supply-chain compromises.

General mitigation guidance

Effective mitigation focuses on eliminating text-based shell evaluation as a security boundary and adopting structured, least-privilege execution patterns:

  • Avoid shell parsing for "safe" commands: Replace free-form shell command construction with structured invocation APIs (for example, passing arguments as arrays to process execution libraries) so shell metacharacters are not interpreted.
  • Remove regex-only whitelisting as a primary defense: Do not rely on regular expressions over untrusted command strings as a way to separate "safe" from "unsafe" operations. Security logic should be based on structured parameters and explicit capabilities, not raw command text.
  • Implement capability-based execution: Represent actions (e.g., "search Git history for this text") as high-level operations that map to fixed, parameterized command templates without allowing arbitrary shell syntax in user-controlled fields.
  • Constrain execution environment: Run the Roo Code runtime with least privileges, restricted filesystem access, and minimal network exposure so that impact is reduced even if injection occurs.
  • Normalize and reject dangerous syntax: If shell usage is unavoidable, explicitly reject or escape shell metacharacters ($, backticks, ;, &&, |, etc.) in any user-controlled input that could reach a command context, and treat any presence of such syntax as untrusted and non-auto-approvable.
  • Secure defaults: Configure auto-approval to err on the side of denial; commands that cannot be structurally verified as safe should require explicit, informed user approval.

How teams detect issues like this

Detection approaches can combine code-level analysis with runtime monitoring:

  • Static analysis and code review:
  • Search for code paths where user-controlled input is concatenated into shell command strings.
  • Flag uses of general-purpose shells (/bin/sh, bash, cmd.exe, powershell) combined with pattern-based whitelisting or regex parsing of commands.
  • Review any "safe command" or whitelist logic to confirm that it does not rely solely on text patterns and that it properly handles shell metacharacters.
  • Policy enforcement:
  • Introduce secure coding policies that prohibit constructing shell commands from untrusted input without strict argument separation.
  • Use pre-commit hooks or CI jobs with linters or SAST tools configured to detect shell injection patterns in the Roo Code codebase and related automation.
  • Runtime monitoring:
  • Monitor process execution and command logs for anomalous patterns such as unexpected subshells, reverse shells, or commands appearing inside $(...) or backticks.
  • Correlate assistant/automation requests with spawned processes to identify when "safe" operations are leading to unexpected system-level activity.

Sources

SourceLink
github.comgithub.com/Secsys-FDU/LLM-Tool-Calling-CVEs/issues/7
roocode.comroocode.com/

Frequently asked

questions

Yes. If an attacker can influence or submit commands that Roo Code evaluates (for example, via a UI, API, or integration), they can potentially trigger command injection remotely, because the underlying shell will execute injected substitutions without further user interaction.

The attacker needs the ability to control or significantly influence the text of a command that passes through Roo Code's auto-approval pipeline. They do not need direct shell access; they only need access to the interface that causes Roo Code to generate and run shell commands on their behalf.

The safest pattern is to stop building commands as shell-interpreted strings and instead use structured execution: define high-level operations, map them to fixed binaries with explicit argument lists, and eliminate the shell wherever possible. Any remaining shell use should treat user input as data only, not as part of the command structure.

Future designs should treat command execution as a capability with well-defined operations and parameters, avoid regex-based security controls over raw command text, and incorporate security reviews for any feature that constructs shell commands. Enforcing secure coding guidelines, using static analysis, and testing with adversarial inputs (including shell metacharacters and substitutions) help catch similar vulnerabilities before release.

Find out what's already
exploitable in your codebase.