Summary
MetaGPT versions up to 0.8.1 contain an OS command injection vulnerability in the get_mime_type function within metagpt/utils/common.py.
When untrusted input is passed into this utility, it may be concatenated into an operating system command, allowing a remote attacker to execute arbitrary commands under the application's privileges.
Affected context
This vulnerability affects applications and services built on MetaGPT up to version 0.8.1 that invoke get_mime_type with input that can be influenced, directly or indirectly, by external users or upstream data.
It is particularly relevant when:
- File paths, filenames, or MIME-related values are derived from HTTP requests, API calls, or other untrusted channels.
- The deployment environment allows the MetaGPT process to spawn shell commands.
- There is no strict validation or sanitization enforcing safe character sets for the values passed into get_mime_type.
Exploit preconditions
- Attack surface: Any code path that calls get_mime_type with values influenced by users, client applications, or external data feeds.
- Required access: Ability to provide or control the input that ultimately flows into get_mime_type (e.g., uploading files, specifying filenames, or controlling metadata fields).
- Trigger point: The vulnerable function constructs or forwards a shell command that incorporates the untrusted input and executes it in the OS environment.
- Why exploitation is possible: The implementation likely builds command strings or arguments using user-controlled data without proper escaping, quoting, or safe API usage, enabling an attacker to inject additional shell syntax or commands.
Why this happens
The underlying issue is improper construction and execution of operating system commands using untrusted input.
Instead of using safe, parameterized APIs or dedicated libraries to determine a file's MIME type, the vulnerable code path appears to concatenate or interpolate user-derived values directly into shell command strings and then executes them.
This pattern maps to CWE-78: Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection') and is closely related to CWE-77: Improper Neutralization of Special Elements used in a Command ('Command Injection').
The core abstraction is that user-controlled data is treated as command syntax rather than pure data, allowing attackers to break out of the intended command structure.
Potential impact
- Execution of arbitrary OS commands with the privileges of the MetaGPT application process.
- Access to sensitive environment information, configuration secrets, or local files.
- Modification or deletion of local data accessible to the MetaGPT runtime.
- Use of the compromised process as a pivot for lateral movement within the host or network.
- Deployment of additional malicious tooling, backdoors, or cryptominers on the host system.
General mitigation guidance
Effective mitigation centers on eliminating direct shell command construction from untrusted input and preferring safer abstractions:
- Replace shell-based MIME identification with trusted library calls (e.g., language-native MIME detection or file-type libraries) that do not spawn a shell.
- If external utilities must be invoked, use APIs that accept argument arrays (e.g., execv-style / subprocess with list arguments) and avoid passing through a shell interpreter.
- Enforce strict input validation on any data flowing into get_mime_type: constrain allowed characters, reject shell metacharacters, and limit to expected formats (e.g., sanitized filenames only).
- Apply least privilege to the MetaGPT process and associated service accounts so that, if command execution occurs, its ability to harm the system is reduced.
- Isolate MetaGPT components that process untrusted input using containers, sandboxes, or separate OS users to reduce blast radius.
How teams detect issues like this
Teams can detect and monitor for this vulnerability using a mix of code-centric and runtime techniques:
- Static analysis: Configure rules to flag uses of shell invocation APIs (e.g., popen, system, subprocess with shell=True, or similar) where arguments include variables derived from external input; specifically review metagpt/utils/common.py and callers of get_mime_type.
- Code review: During manual review, treat any string concatenation before command execution as a security smell and verify that utility functions like get_mime_type do not build shells around user-controlled values.
- Dependency scanning: Incorporate software composition analysis (SCA) to highlight use of vulnerable MetaGPT versions and surface OS command injection advisories.
- Runtime monitoring: Use audit logs, process monitoring, and EDR/IDS solutions to detect unusual child processes or command patterns launched by MetaGPT services.

