Summary
MetaGPT up to version 0.8.1 contains a code injection flaw in the XML Handler's ActionNode.xml_fill function, where XML-driven directives are insufficiently sanitized before being dynamically evaluated.
When an attacker can influence XML content processed by this component, they may execute arbitrary code remotely in the context of the MetaGPT process.
Affected context
This vulnerability occurs in MetaGPT deployments that process XML-based action definitions through the ActionNode.xml_fill function within metagpt/actions/action_node.py.
It is relevant in scenarios where:
- XML content is accepted from external or semi-trusted sources (e.g., user input, integrations, or remote workflows), and
- That XML can influence code-like directives or expressions that are dynamically interpreted or evaluated.
The risk is elevated when MetaGPT runs with broad system permissions or has access to sensitive data or downstream systems.
Exploit preconditions
- Attack surface: Remote, via any interface or integration that allows attackers to supply or alter XML consumed by
ActionNode.xml_fill. - Required access: Capability to submit, inject, or modify XML payloads that are processed by the XML Handler (e.g., via API endpoints, plugins, or message channels).
- Trigger point: XML-driven directives are parsed and used as input to dynamic code evaluation logic without sufficient neutralization of dangerous constructs.
- Why exploitation is possible: Untrusted XML data is treated as trusted code or code-like directives, allowing attacker-controlled content to be executed in the interpreter, mapping to CWE-94/CWE-95.
Why this happens
The root cause is the use of dynamic code evaluation mechanisms (such as eval, exec, or equivalent meta-programming features) on values derived from XML content without rigorous sanitization, whitelisting, or structural validation.
ActionNode.xml_fill appears to interpret XML-sourced directives as executable logic, failing to neutralize or restrict dangerous characters, operators, or language constructs.
Conceptually, this matches CWE-94: Improper Control of Generation of Code ('Code Injection') and CWE-95: Improper Neutralization of Directives in Dynamically Evaluated Code, where attacker-controlled text is turned into executable code, breaking the boundary between data and code.
Potential impact
- Execution of arbitrary code with the privileges of the MetaGPT service.
- Access to and exfiltration of sensitive data, prompts, and outputs handled by MetaGPT.
- Manipulation of MetaGPT workflows, responses, or downstream automated actions (e.g., task automation, integrations).
- Pivoting to other systems reachable from the host, including lateral movement within the environment.
- Service disruption, data corruption, or deployment of malware via the compromised runtime.
General mitigation guidance
Effective mitigation focuses on treating XML content strictly as data and eliminating direct dynamic evaluation of XML-derived directives:
- Replace general-purpose dynamic evaluation (
eval,exec, template engines with arbitrary expressions) with explicit, declarative command sets or configuration schemas. - Introduce strict whitelisting of allowable operations and arguments; map XML tags/attributes to predefined, non-interpreted handlers.
- Apply robust input validation and canonicalization on XML fields before they influence any execution path, rejecting unexpected tokens, operators, or embedded code.
- Use safe parsing and binding patterns (e.g., mapping to typed data structures) rather than code construction or interpretation.
- Run MetaGPT with least privilege, isolating it via containers, sandboxing, or restricted OS-level permissions to limit damage if code execution occurs.
How teams detect issues like this
Organizations can look for this class of vulnerability and its abuse using:
- Static analysis: Rules that flag use of
eval,exec, or similar dynamic evaluation APIs where arguments originate from XML parsing or other external input sources. - Code review: Focused reviews of XML handling components and utility functions that transform parsed XML into executable logic, templates, or scripting constructs.
- Logging and runtime monitoring: Enhanced logging around XML ingestion and directive processing, with alerts for anomalous or unexpectedly complex directive content.
- Policy enforcement: Development policies and CI checks that forbid unreviewed introduction of dynamic evaluation mechanisms, requiring documented justification and guards when they are used.

