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
Conversation
…for safer LLM output processing
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
This PR addresses the security vulnerability in
superagi/agent/output_handler.pywhereeval()was being used on LLM output.The Problem
Both
TaskOutputHandler.handle()andReplaceTaskOutputHandler.handle()methods were 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
tasks = eval(assistant_reply)totasks = json.loads(assistant_reply)in bothTaskOutputHandler.handle()andReplaceTaskOutputHandler.handle()methodsTesting
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.