subprocess module call
Medium
- Category
- Dangerous Code Execution
- Content
TEST_CMD = os.getenv('TEST_CMD') or f"pytest {args.tests}" if os.path.isdir(args.tests) else f"pytest {args.tests}" print(f"Running tests: {TEST_CMD}") res = subprocess.run(TEST_CMD, shell=True) if res.returncode != 0: print("Tests failed or missing. Aborting run.") sys.exit(res.returncode or 1)- Confidence
- 98% confidence
- Finding
- The code executes TEST_CMD via subprocess.run(..., shell=True), and TEST_CMD can come directly from the TEST_CMD environment variable. Using a shell with environment-controlled input enables arbitrary command execution, which is broader than simply running a fixed test command and is dangerous in agent or CI contexts where environment values may be influenced externally.
