Summary
MetaGPT contains an OS command injection vulnerability in the RepoParser.rebuild_class_views() method. An attacker who can control the method's path argument may execute arbitrary operating-system commands with the privileges of the affected process.
Affected context
The vulnerability occurs in MetaGPT's repository parsing functionality when the RepoParser.rebuild_class_views() method processes a path argument. Risk is present when attacker-controlled or insufficiently trusted path data reaches command construction or execution without being safely isolated from the operating system shell.
Exploit preconditions
- Attack surface: The repository parsing interface that invokes
RepoParser.rebuild_class_views() - Required access: The ability to supply or influence the method's path argument, directly or through an exposed application workflow
- Trigger point: Processing the path argument during repository class-view rebuilding
- Why exploitation is possible: Untrusted path data may be interpreted as operating-system command syntax rather than treated solely as a filesystem path
Why this happens
The underlying bug is an OS command injection condition mapped to CWE-78. The vulnerable pattern occurs when application-controlled input is incorporated into a system command without strict separation between data and executable command elements. Shell interpretation or unsafe command construction can cause specially formed input to alter the intended operation and execute additional commands.
Potential impact
- An attacker could execute arbitrary commands on the host running MetaGPT.
- The vulnerability may expose application secrets, source code, or local files.
- The affected process could be used to modify repositories or application data.
- An attacker could gain a foothold for lateral movement, depending on runtime permissions and network access.
- Service availability could be disrupted through destructive or resource-intensive commands.
General mitigation guidance
Mitigation generally focuses on preventing user-controlled data from reaching shell interpretation.
Common defensive patterns include:
- Prefer direct library and process APIs that pass arguments as structured values without invoking a shell.
- Treat repository paths as untrusted data and apply canonicalization, allowlisting, and confinement to expected directories.
- Avoid dynamically assembled command strings and reject unexpected path formats before processing.
- Run repository parsing with a dedicated low-privilege account, restricted filesystem access, and minimal network permissions.
- Apply sandboxing and read-only controls where the workflow permits them.
- Separate validation from execution and ensure validation cannot be bypassed by alternate path representations.
How teams detect issues like this
Detection approaches commonly include:
- Static analysis rules for shell invocation, dynamic command construction, and string interpolation involving path or request data.
- Code review checks for subprocess or shell APIs that receive concatenated or formatted user-controlled values.
- Runtime monitoring for unexpected child processes spawned by MetaGPT or its worker services.
- Audit logging and policy enforcement for process creation, filesystem access, and outbound network connections.
- Automated security review tools can help identify command execution paths that lack argument separation or input validation.

