How to fix: os.exec / os.system / os.popen usage
Python's os.system, os.exec*, and os.popen pass their string argument to the shell. Any user-controlled portion executes as a shell command.
Why it matters
Attacker can chain arbitrary shell commands and read or destroy server files.
The `code-cmdi-os-exec` check verifies that the server does not expose the `cmdi-os-exec` weakness in the code category. The detection runs against the response headers, body, or auxiliary probes (DNS, TLS, async fetch) as appropriate.
How to fix it
- 1Use subprocess.run([...], shell=False) with argument arrays.
- 2Validate inputs against an allowlist of permitted values.
- 3Avoid shlex.join on attacker-controlled strings; allowlist first.
Code examples
Use subprocess.run with list args (no shell=True)
import subprocess
# BAD: shell=True with user input, shell injection possible
subprocess.run(f"convert {user_input} output.png", shell=True)
# GOOD: list of args, shell=False (default)
subprocess.run(
["convert", "-resize", "100x100", validated_input, "output.png"],
shell=False,
timeout=10,
check=True,
)References
Detected automatically by VulnRadar. The check id is code-cmdi-os-exec, stable across every scan so you can filter or diff on it.
More code checks
- CriticalForm Submits Data Over Insecure HTTP
- MediumPotential Prototype Pollution Sinks Detected
- HighPotential Command Injection Vectors
- HighJWT Decoded Without Signature Verification
- HighPotential Path Traversal Vulnerability
- HighInsecure Authentication Mechanisms Detected
- HighPotential Insecure Deserialization
- Mediumeval() Usage in Inline Scripts
Questions
- How severe is os.exec / os.system / os.popen usage?
- VulnRadar rates this critical severity in the code category. The severity is fixed per check, not scored per site, so the same finding is the same severity on every scan.
- Does VulnRadar check for this automatically?
- Yes. It runs as part of every scan under the check id code-cmdi-os-exec, which stays the same between runs so you can filter, diff, or gate CI on it.
- Which standards does os.exec / os.system / os.popen usage map to?
- It maps to CWE-78. In the OWASP Top 10 it falls under A03:2021.
Missing a check?
The detection set is open. If you know a misconfiguration this does not catch, propose it: the issue template asks for the threat model, how to detect it, the false-positive risk, and a test fixture, which is the same thing a maintainer would have to work out anyway.