Severity:

HIGH RISK

(7.3)

OS Command Injection in MetaGPT get_mime_type Utility

CVE-2026-5973

Analyzed

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

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.

Sources

SourceLink
github.comgithub.com/FoundationAgents/MetaGPT/
github.comgithub.com/FoundationAgents/MetaGPT/issues/1930
github.comgithub.com/FoundationAgents/MetaGPT/pull/1983
vuldb.comvuldb.com/submit/791755
vuldb.comvuldb.com/vuln/356527
vuldb.comvuldb.com/vuln/356527/cti

Frequently asked

questions

Yes. If remote users can influence the inputs passed to get_mime_type—such as file names, paths, or MIME-related parameters—the vulnerability can be exploited over the network without local access.

An attacker needs the ability to supply or control data that flows into get_mime_type. This often means being able to upload files, send crafted API requests, or otherwise control fields that the application uses when calling this function.

The most robust fix is to remove shell-based MIME detection entirely and replace it with library-based MIME resolution that treats input as data only. If external utilities remain necessary, they should be invoked via non-shell APIs with strict argument handling and strong input validation.

Adopt secure coding guidelines that prohibit constructing OS command strings from untrusted input, mandate the use of parameterized command execution or high-level libraries, and enforce these rules via static analysis and code review gates. Regularly assessing utility/helper functions that wrap system calls can also prevent these patterns from spreading across the codebase.

Find out what's already
exploitable in your codebase.