fix(security): Replace eval() with json.loads() in queue_step_handler.py for safer LLM output processing#1493
Conversation
….py for safer LLM output processing
|
@TransformerOptimus/maintainers Could you please review this security fix PR when you have a chance? This PR fixes a security issue by replacing The fix is simple and focused: it changes the code to use This is an important security fix that should be reviewed promptly to protect users from potential attacks. Thank you for your time! |
|
@TransformerOptimus/maintainers This PR has been approved and is ready for merge. Please help merge this security fix. |
Security Fix
This PR addresses the security vulnerability in
superagi/agent/queue_step_handler.pywhereeval()was being used on LLM output.The Problem
The
_process_replymethod was usingeval()to parse LLM responses that were expected to be JSON arrays. This could allow an indirect prompt injection to cause the LLM to generate malicious Python code that gets executed.The Solution
Replaced
eval()withjson.loads()which safely parses JSON data without executing arbitrary code.Changes Made
import jsoninside the_process_replymethodtask_array = np.array(eval(assistant_reply)).flatten().tolist()totask_array = np.array(json.loads(assistant_reply)).flatten().tolist()Testing
The fix maintains the same functionality while providing a safe alternative to
eval()for parsing JSON responses from the LLM.This is part of a series of PRs to fix all
eval()usage vulnerabilities in the codebase.