fix: replace eval() with safe type lookup in UserInputField to prevent code injection#207
Open
Joshua-Medvinsky wants to merge 1 commit into
Conversation
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.
Problem
UserInputField.from_dict()inagents/tools/base.pycallseval(data["field_type"])without sanitization. The same pattern exists inagents/models/base.py:1162. Sincefield_typeoriginates from LLM tool call arguments (which can be influenced by user prompts via prompt injection), this enables arbitrary Python code execution within the agent process.An attacker who can influence the LLM's tool call output (via prompt injection) can set
field_typeto__import__('os').system('id')to execute arbitrary commands.Severity: High (CVSS 8.8) — LLM tool call context → host Python process execution
Fix
Replace
eval()with a static allowlist lookup (_SAFE_TYPESdict) that maps type name strings to their Python type objects. Unknown type names default tostr. This preserves the intended functionality (converting type name strings to type objects) while eliminating the code injection vector.Test Plan
UserInputField.from_dict({"name": "x", "field_type": "int", ...})→ field_type isintUserInputField.from_dict({"name": "x", "field_type": "__import__('os').system('id')", ...})→ field_type isstr(no code execution)UserInputField.from_dict({"name": "x", "field_type": "unknown", ...})→ field_type isstr(safe default)Security Note
This is a high-severity code injection vulnerability exploitable via prompt injection. The fix replaces
eval()with a safe allowlist lookup.