Skip to content

security: fix code/command injection in calculators, WP downloader, and KV store - #591

Open
devin-ai-integration[bot] wants to merge 1 commit into
masterfrom
devin/1784905623-security-fixes
Open

security: fix code/command injection in calculators, WP downloader, and KV store#591
devin-ai-integration[bot] wants to merge 1 commit into
masterfrom
devin/1784905623-security-fixes

Conversation

@devin-ai-integration

Copy link
Copy Markdown

Summary

Fixes the critical code-/command-injection findings from a security scan of the repo. Each fix preserves the original intended behavior; only the unsafe evaluation/execution path is replaced.

1. ai-terminal-assistant/main.py — arbitrary code execution (RCE)
The calc command ran eval(value) on raw user input, so e.g. calc __import__("os").system("...") executed arbitrary code. Replaced with an ast-based safe_eval() that only allows numeric literals and arithmetic operators (+ - * / // % **, unary +/-); anything else raises ValueError.

2. gui-calculator/Calculator.py — arbitrary code execution
equate() ran eval(display.get()). Replaced with the same safe_eval() and wrapped in a try/except that shows Error instead of crashing on bad input.

3. wordpress_plugin_downloader/downloader.py — OS command injection

- os.system("axel -a -n 16 %s && unzip %s" % (link, filename))
+ subprocess.run(["axel", "-a", "-n", "16", link], check=True)
+ subprocess.run(["unzip", filename], check=True)

link/filename came from scraped page HTML and were interpolated into a shell string. Now passed as argument lists with no shell, so metacharacters can't inject commands.

4. KeyValueStore/db.sh — arbitrary command execution + regex injection
The script ended in $@, which executed any function or command name passed as the first argument (e.g. db.sh 'x; touch INJECTED'). It also used unquoted grep -e $1 / sed "s/$1.../", allowing regex/argument injection. Rewritten to:

  • Dispatch via an explicit case allow-list (create|read|update|delete) instead of $@.
  • Quote all variable expansions.
  • Match keys exactly with awk '$1 == key' (passing the key via -v) instead of grep/sed regexes.

Notes / not fixed

  • BasicCalculator/script.js uses client-side eval() on the user's own input (self-contained, no server/other-user exposure) — flagged as low risk, left as-is.
  • No real hardcoded secrets were found in first-party code — matches were placeholders (YOUR_API_KEY, <your consumer secret>) or env-var lookups. The only real token is in a committed third-party node_modules file (todolist/node_modules/debug/.coveralls.yml).
  • Committed node_modules (Make-Text-Uppercase, todolist) are outdated and a supply-chain concern, but out of scope for this focused fix.

Verification

  • python3 -m py_compile passes for all changed Python files.
  • safe_eval("2+3*4")14; injection payload raises ValueError.
  • db.sh create/read/update/delete round-trips correctly; injection payload is rejected with a usage error.

Link to Devin session: https://app.devin.ai/sessions/53e420bb2b644c55bffeeb860fd69155
Requested by: @josharsh

…nd KV store

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@josharsh josharsh self-assigned this Jul 24, 2026
@devin-ai-integration

Copy link
Copy Markdown
Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment, CI, and merge conflict monitoring

@github-actions github-actions Bot added python Pull requests that update Python code bash labels Jul 24, 2026

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Message that will be displayed on users first pull request

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bash python Pull requests that update Python code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant