Skip to content

fix: replace insecure eval() with safe parsing in reflection.py - #167

Open
dajiaohuang wants to merge 1 commit into
OpenBMB:mainfrom
dajiaohuang:fix/eval-in-security-reflection
Open

dajiaohuang wants to merge 1 commit into
OpenBMB:mainfrom
dajiaohuang:fix/eval-in-security-reflection

Conversation

@dajiaohuang

Copy link
Copy Markdown

What

Replaces the command execution vulnerability in ReflectionAgent where LLM-generated output was directly evaluated using eval().

Why

Issue #147 reported a security vulnerability: the code used eval("self._" + output) to process LLM responses, which could allow command execution if the LLM output was manipulated by an attacker.

How

The fix replaces eval() with:

  1. Regex-based function name detection (say(, act(, do_nothing()
  2. ast.literal_eval() for safe argument parsing
  3. getattr() to call the appropriate internal method (_say or _act)

This ensures only the expected method calls can be made with safely-parsed arguments.

Testing

  • Syntax check passed
  • The fix maintains backward compatibility with the existing output format
  • No changes to the method signatures of _say() or _act()

Related Issue

Fixes #147

Security Note

This is a security fix. The original code allowed arbitrary code execution through LLM prompt injection. The new code restricts execution to only the _say, _act, and do_nothing methods with safely parsed arguments.

Replaces the command execution vulnerability in ReflectionAgent where
LLM-generated output was directly evaluated. The fix uses regex
parsing and ast.literal_eval for safe argument extraction, then
getattr() to call the appropriate method.

Fixes security issue reported in OpenBMB#147
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.

[!] Security Risk 瀹夊叏婕忔礊

1 participant