subprocess module call
Medium
- Category
- Dangerous Code Execution
- Content
cmd = f"mcporter call 'xiaohongshu.publish_content(title: \"{title}\", content: \"{safe_content}\", images: {json.dumps(images)})'" try: result = subprocess.run(cmd, shell=True, capture_output=True, text=True, timeout=90) if result.stdout and ('成功' in result.stdout or 'Success' in result.stdout): print(f"✅ 发布成功:{result.stdout}") return {"status": "success", "message": result.stdout}- Confidence
- 98% confidence
- Finding
- The code builds a shell command by interpolating untrusted `title` and `content` into a single string and executes it with `subprocess.run(..., shell=True)`. Although it escapes double quotes and newlines in `content`, it does not safely handle shell metacharacters or single quotes, so attacker-controlled topic text can break out of the intended argument and trigger command injection.
