subprocess module call
Medium
- Category
- Dangerous Code Execution
- Content
def cmd_escape(s): return str(s).replace("^", "^^").replace("&", "^&").replace("%", "^%").replace("<", "^<").replace(">", "^>").replace("|", "^|").replace('"', '""') cmd_str = " ".join(f'"{cmd_escape(p)}"' for p in cmd_parts) result = subprocess.run(cmd_str, check=False, env=env, shell=True) else: # Unix: use list form without shell result = subprocess.run(cmd_parts, check=False, env=env)- Confidence
- 95% confidence
- Finding
- On Windows, the script builds a command string and invokes it with shell=True using user-influenced arguments such as filepath, theme, and highlight. Although it attempts escaping, cmd.exe quoting is brittle and can still enable command injection or unintended command execution in edge cases, especially with attacker-controlled file paths or arguments.
