Replace eval with ast.literal_eval for safety - #1375
Open
VamsiSudhakaran1 wants to merge 1 commit into
Open
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.
Summary
The UI-TARS grounding agent parses coordinate boxes out of the model's own
action output and evaluates them with
eval().evalon model-derived data isa code-execution anti-pattern;
ast.literal_evalparses the same list/tupleliterals but cannot execute code, so this is a safe, behavior-preserving swap.
Where
src/khoj/processor/operator/grounding_agent_uitars.py— 8 call sites(lines 682, 685, 695, 720, 879, 882, 891, 918). For example:
action_inputsis populated byparse_action_to_structure_output(text=...)from the model's generated text, so the value reaching
eval()is model-derived.For a computer-use agent that acts on screenshots, that output is influenceable
by on-screen content (a page the agent views can carry injected instructions),
so in any path where a raw box value reaches
evalunnormalized, a steeredmodel could emit something other than
[x1, y1, x2, y2]. Even where the valueis numeric-normalized first,
evalis the wrong tool here.Fix
Replace
eval(...)withast.literal_eval(...)at these sites (astisalready imported in this file). Verified parse-equivalent on the real inputs
(
[0.1, 0.2, 0.3, 0.4],(0.12, 0.34)), and that a non-literal string nowraises
ValueErrorinstead of executing.