Skip to content

fix: prevent command injection in project script execution#17

Open
iamarsenibragimov wants to merge 1 commit into
mikeleppane:mainfrom
iamarsenibragimov:fix/command-injection-run-script
Open

fix: prevent command injection in project script execution#17
iamarsenibragimov wants to merge 1 commit into
mikeleppane:mainfrom
iamarsenibragimov:fix/command-injection-run-script

Conversation

@iamarsenibragimov
Copy link
Copy Markdown

Summary

  • Security fix: run_script() previously executed arbitrary shell commands from .envx/config.yaml without validation or user confirmation, allowing RCE via malicious config files
  • Added command validation against ~30 dangerous patterns (curl, wget, sudo, eval, rm -rf, ssh, nc, etc.), null bytes, and excessively long commands
  • Changed run_script() to a two-phase API: returns ScriptInfo for review before execution
  • CLI now displays the full command, config source, and env vars, then prompts [y/N] before running

Test plan

  • All 238 existing tests pass
  • New tests verify dangerous commands are blocked (test_run_script_blocks_dangerous_commands)
  • New tests verify safe commands are allowed (test_run_script_allows_safe_commands)
  • New tests verify null byte injection is blocked (test_run_script_blocks_null_bytes)
  • New tests verify the two-phase execution flow (test_run_script_success)
  • New unit tests for validate_script_command directly
  • Manual test: envx project run <script> shows confirmation prompt

run_script() previously executed arbitrary shell commands from
.envx/config.yaml without any validation or user confirmation.
A malicious config (e.g. via a crafted PR) could achieve RCE.

Three layers of defense added:

- Command validation: block ~30 dangerous patterns (curl, wget, sudo,
  eval, rm -rf /, ssh, nc, etc.), null bytes, and excessively long
  commands (>4096 bytes)
- Two-phase execution: run_script() now takes a `confirmed` parameter;
  when false it returns ScriptInfo without executing, allowing callers
  to display the command first
- Interactive confirmation: CLI shows the full command, source config
  path, and env vars before prompting [y/N]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant