Skip to content

fix: prevent command injection in check_command_exists (CWE-78)#559

Merged
DoganK01 merged 1 commit intoUpsonic:masterfrom
spidershield-contrib:fix/cwe-78-command-injection
Mar 30, 2026
Merged

fix: prevent command injection in check_command_exists (CWE-78)#559
DoganK01 merged 1 commit intoUpsonic:masterfrom
spidershield-contrib:fix/cwe-78-command-injection

Conversation

@spidershield-contrib
Copy link
Copy Markdown
Contributor

Summary

Fixes #558check_command_exists used subprocess.run(f"which {command}", shell=True) which allowed arbitrary command execution via shell metacharacters.

Changes

  • Replaced subprocess.run(f"which {command}", shell=True, ...) with shutil.which(command)
  • Added import shutil at the top of the file
  • The shutil.which() function is a pure Python implementation that searches PATH without invoking a shell, making it immune to command injection

CWE Reference

  • CWE-78: Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection')
  • Severity: High

Testing

  • Verify that check_command_exists("python3") still correctly reports the command as available
  • Verify that check_command_exists("foo; echo pwned") reports the command as unavailable (not executing the injected command)
  • Verify that check_command_exists("nonexistent") reports the command as unavailable

Found by SpiderShield security scanner

@DoganK01
Copy link
Copy Markdown
Member

Hey, thanks for the contribution!

@DoganK01 DoganK01 merged commit 520418c into Upsonic:master Mar 30, 2026
4 of 5 checks passed
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.

Security: Command Injection in check_command_exists (CWE-78)

2 participants