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
- The Windows code path builds a command string and invokes it with shell=True, while including user-influenced values such as filepath, theme, and highlight. Although some cmd.exe metacharacters are escaped, shell-based invocation remains fragile and can still lead to argument confusion or command injection on Windows, especially with edge-case quoting behavior.
