Summary
A command injection vulnerability in the Bash Tool component of chatgpt-on-wechat up to version 2.0.8 allows attacker-controlled input to be incorporated into shell commands without proper sanitization.
When untrusted data reaches the _get_safety_warning function in agent/tools/bash/bash.py, a remote attacker may be able to execute arbitrary OS commands under the privileges of the running application.
Affected context
This weakness appears in deployments of chatgpt-on-wechat that:
- Enable and expose the Bash Tool functionality
- Allow user-controlled or external input to reach the
_get_safety_warninglogic - Execute shell commands on the host or container environment based on that input
The risk is higher when the bot is reachable from untrusted networks or integrated into workflows where user messages can influence command strings.
Exploit preconditions
- Attack surface: Network-accessible chatgpt-on-wechat instance with Bash Tool enabled.
- Required access: Ability to send crafted input that is processed by the Bash Tool and reaches
_get_safety_warning. - Trigger point: Invocation of functionality that constructs and executes shell commands based on attacker-influenced data.
- Why exploitation is possible: The code builds OS command strings using unvalidated, unsanitized input and passes them to a shell interpreter, allowing injection of additional commands or arguments.
Why this happens
The root cause aligns with CWE-77: Improper Neutralization of Special Elements used in a Command ('Command Injection') and CWE-78: Improper Neutralization of Special Elements used in an OS Command.
In _get_safety_warning, application logic appears to concatenate or interpolate user-influenced data into a shell command line and execute it through a system shell.
By failing to strictly validate or neutralize shell metacharacters and by invoking a general-purpose shell instead of parameterized APIs, the implementation allows crafted input to break out of the intended command structure and execute arbitrary OS commands.
Potential impact
- Remote execution of arbitrary OS commands under the application's OS account
- Access to sensitive configuration, environment variables, or chat logs
- Lateral movement within the host or container environment
- Data exfiltration, modification, or destruction on the affected system
- Use of the compromised instance as a pivot for broader network attacks
General mitigation guidance
Effective mitigation for this vulnerability class generally focuses on avoiding direct shell invocation with untrusted data and reducing the privileges of any components that must run commands.
Recommended defensive patterns include:
- Prefer high-level language APIs or dedicated libraries for system operations instead of building raw shell command strings.
- If command-line tools are unavoidable, use parameterized execution (e.g., passing arguments as lists) and avoid
shell=True-style execution. - Strictly validate and constrain any inputs that can influence commands to a safe, allow-listed set of values (e.g., enumerated options, fixed subcommands).
- Implement robust input normalization and rejection of shell metacharacters where user-provided tokens are necessary.
- Run the Bash Tool and related components under a minimally privileged OS user, and isolate them using containers or sandboxes where feasible.
- Limit access to the Bash Tool feature to trusted users or controlled environments, and disable it when not strictly required.
How teams detect issues like this
Detection typically combines code-centric review with runtime monitoring:
- Static analysis and code review:
- Search for uses of shell execution APIs (e.g.,
subprocesswith shell invocation,os.system, or similar) that accept variables derived from user or network input. - Flag dynamic command construction patterns such as string concatenation, f-strings, or formatting that mix user data into command lines.
- Enforce secure-coding guidelines or linters that prohibit shell-based execution when untrusted data is involved.
- Automated tooling:
- Use application security testing tools and SAST scanners configured with rules for OS command injection (CWE-77/CWE-78).
- Integrate these tools into CI pipelines to block risky patterns before deployment.
- Runtime and operational monitoring:
- Monitor the application host or container for abnormal process creation behavior (unexpected shells, unusual command arguments).
- Log and review invocations of the Bash Tool, especially where user messages or external events influence command execution.

