Security: Replace eval() with ast.literal_eval() to prevent code injection (CWE-94)#2033
Open
anxovatomica wants to merge 1 commit into
Open
Security: Replace eval() with ast.literal_eval() to prevent code injection (CWE-94)#2033anxovatomica wants to merge 1 commit into
anxovatomica wants to merge 1 commit into
Conversation
…ction
Replaces unsafe eval() calls with ast.literal_eval() in three files:
- metagpt/actions/action_node.py: list/dict parsing from LLM output
- metagpt/strategy/tot.py: thought parsing from LLM output
- metagpt/utils/serialize.py: type deserialization
eval() on untrusted input (especially LLM-generated content) allows
arbitrary code execution. ast.literal_eval() safely evaluates literals
without executing arbitrary code.
Fixes CWE-94: Improper Control of Generation of Code ('Code Injection')
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Security Fix: Replace eval() with ast.literal_eval() to prevent Code Injection (CWE-94)
Vulnerability Details
Files Affected:
Impact
The codebase uses Python's function to parse data that originates from LLM outputs and serialized configurations. Since executes arbitrary Python code, an attacker who controls the LLM response or manipulates serialized data can achieve Remote Code Execution (RCE) with the privileges of the MetaGPT process.
Attack Scenario
Fix Applied
Replaced all calls with , which safely evaluates literal expressions (lists, dicts, strings, numbers) without executing arbitrary code.
Testing
References