Fix arbitrary code execution via eval() in calculator - #1
Open
devin-ai-integration[bot] wants to merge 1 commit into
Open
Fix arbitrary code execution via eval() in calculator#1devin-ai-integration[bot] wants to merge 1 commit into
devin-ai-integration[bot] wants to merge 1 commit into
Conversation
Author
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
Author
Test results — eval() → safe_eval() RCE fixTested by launching the tkinter calculator locally and driving it via on-screen buttons (arithmetic still works after the swap), plus a shell test proving
RCE fix evidence (shell)Old Caveat: unrelated pre-existing bug — No CI is configured on this repo. Session: https://app.devin.ai/sessions/26d1dbca8aab45edb08a50dc5852bbd4 |
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 calculator evaluated user-controlled expressions with Python's built-in
eval()in four places (square,sqrt,perc,evaluate). Because the display expression is built from typed/pasted characters (and keyboard bindings feed straight into it), this is an arbitrary-code-execution sink — e.g. entering__import__("os").system(...)would run shell commands.This PR replaces
eval()with a newsafe_eval()that parses the expression withast.parse(..., mode="eval")and walks the tree, permitting only numeric literals and arithmetic operators (+ - * / // % **and unary+/-). Anything else (names, calls, attribute access, subscripts) raisesValueError.Call sites changed from
eval(...)tosafe_eval(...);evaluate()still wraps the call in try/except so invalid input showsErroras before.Verified:
2+3*4→14,9**0.5→3.0,50*20/100→10.0 still compute;__import__("os").system("id"),open("x"), bare names, and multi-statement input are all rejected.Scan notes
Other requested categories are not applicable to this repo — it's a standalone tkinter desktop app with no web server, database, network I/O, dependencies beyond the stdlib, or secrets. No SQL injection, CORS, debug endpoints, auth, or hardcoded credentials exist. The
eval()RCE was the only critical finding.Link to Devin session: https://app.devin.ai/sessions/26d1dbca8aab45edb08a50dc5852bbd4
Requested by: @martlyma