Skip to content

fix(security): Replace eval() with json.loads() in output_handler.py for safer LLM output processing#1492

Open
liangzhang-keepmoving wants to merge 1 commit into
TransformerOptimus:mainfrom
liangzhang-keepmoving:fix-security-eval-output-handler
Open

fix(security): Replace eval() with json.loads() in output_handler.py for safer LLM output processing#1492
liangzhang-keepmoving wants to merge 1 commit into
TransformerOptimus:mainfrom
liangzhang-keepmoving:fix-security-eval-output-handler

Conversation

@liangzhang-keepmoving
Copy link
Copy Markdown

Security Fix

This PR addresses the security vulnerability in superagi/agent/output_handler.py where eval() was being used on LLM output.

The Problem

Both TaskOutputHandler.handle() and ReplaceTaskOutputHandler.handle() methods were using eval() 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() with json.loads() which safely parses JSON data without executing arbitrary code.

Changes Made

  1. Changed tasks = eval(assistant_reply) to tasks = json.loads(assistant_reply) in both TaskOutputHandler.handle() and ReplaceTaskOutputHandler.handle() methods

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant