[MEDIUM] eval() in tools.py should use safer math evaluation #52

Closed
opened 2026-03-14 18:47:33 +00:00 by kimi · 0 comments
Collaborator

Problem

src/timmy/tools.py:139 uses eval() for calculator tool:

result = eval(expression, {"__builtins__": {}}, allowed_names)

While sandboxed, eval() is still dangerous.

Impact

  • Potential security risk if sandbox is bypassed
  • Code smell - eval() is generally discouraged

Recommendation

Use a dedicated math parser like numexpr or asteval.

Acceptance Criteria

  • Replace eval() with numexpr or ast.literal_eval
  • Maintain all current math functions
  • Add tests for edge cases
  • Verify no performance regression

Priority: MEDIUM

## Problem `src/timmy/tools.py:139` uses eval() for calculator tool: ```python result = eval(expression, {"__builtins__": {}}, allowed_names) ``` While sandboxed, eval() is still dangerous. ## Impact - Potential security risk if sandbox is bypassed - Code smell - eval() is generally discouraged ## Recommendation Use a dedicated math parser like `numexpr` or `asteval`. ## Acceptance Criteria - [ ] Replace eval() with numexpr or ast.literal_eval - [ ] Maintain all current math functions - [ ] Add tests for edge cases - [ ] Verify no performance regression ## Priority: MEDIUM
Sign in to join this conversation.
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Rockachopa/Timmy-time-dashboard#52