Skip to main content

SKY-D203 · Security in code

OS command run through a shell

CriticalCWE-78

Python os.system() and os.popen() are CRITICAL, or LOW when the command is written directly as fixed text with no $ or backtick expansion and no risky command in it. Java and Kotlin Runtime.exec() and PHP command functions are HIGH, or LOW for a fixed command. LOW findings are hidden from the default list.

os.system() and os.popen() hand one string to the system shell, which splits it into words and also obeys ;, |, $( ) and other shell syntax. SKY-D203 reports these calls, and their equivalents in Java, Kotlin and PHP, so that each one is reviewed.

Languages
Python, Java, Kotlin, PHP
Quality gate
counted toward the gate limits; a CRITICAL finding fails the gate on its own (full and diff scans). LOW findings for fixed commands are hidden from the default list but still counted.
Finding type
review
Catalog name
OS command execution
Wrong result? Report itA false positive, a missed case or a confusing message: it goes privately to the founder.

Why it matters

If any part of the string comes from a file name, form field or API value, a name such as a.png; rm -rf ~ runs a second command. Even when today's input is safe, a shell string is easy to break with one later change.

What Skylos flags

app/thumbs.py · PythonReported on line 5
import os  def make_thumbnail(upload_path: str) -> None:    os.system(f"convert {upload_path} -resize 200x200 thumbs/out.png")

What Skylos leaves alone

app/thumbs.py · Python
import subprocess  def make_thumbnail(upload_path: str) -> None:    subprocess.run(        ["convert", upload_path, "-resize", "200x200", "thumbs/out.png"],        check=True,    )

Why Skylos leaves it alone

The command is a list and no shell is involved: upload_path reaches convert as one argument, whatever characters it contains. Skylos only reports subprocess calls that start a shell (that is SKY-D209).

More languages

Java

Flagged

src/main/java/com/example/media/Thumbnails.java · JavaReported on line 8
package com.example.media; import java.io.IOException; public class Thumbnails {    public void make(String uploadPath) throws IOException, InterruptedException {        String command = "convert " + uploadPath + " out.png";        Process process = Runtime.getRuntime().exec(command);        process.waitFor();    }}

Not flagged

src/main/java/com/example/media/Thumbnails.java · Java
package com.example.media; import java.io.IOException; public class Thumbnails {    public void make(String uploadPath) throws IOException, InterruptedException {        ProcessBuilder builder = new ProcessBuilder("convert", uploadPath, "out.png");        builder.start().waitFor();    }}

Why Skylos leaves it alone

ProcessBuilder gets the program and each argument separately, so the path cannot add words or commands. Only Runtime.exec() is reported under this rule.

How Skylos decides

  1. Python: resolves call names through imports and assignments (from os import system, run = os.system) and matches os.system and os.popen.
  2. Keeps CRITICAL 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: it deletes broadly, sends secrets out, pipes a download into a shell or reads credential stores.
  3. Lowers to LOW a command written directly as fixed text without any of that, such as os.system("clear"). LOW findings are hidden from the default list, stay in JSON output and are counted by the gate.
  4. For os.system(), a variable that every path fills with fixed text is also marked low-risk and hidden, but it keeps CRITICAL.
  5. Java and Kotlin: reports exec() on Runtime.getRuntime() or a Runtime variable as HIGH, or LOW when the only argument is a string literal or an array of string literals.
  6. PHP: exec, system, shell_exec, passthru, popen, proc_open, backticks and pcntl_exec are HIGH when the command is not constant and LOW when it is fixed (any inserted value a number or an escapeshellarg() argument). Request data reaching the command is reported as SKY-D212 instead.

How to fix it

Run the program directly with a list of arguments and no shell. If you truly need shell features, quote every inserted value with shlex.quote().

app/thumbs.py · Python · the fix, against the flagged file
Removed: import osAdded: import subprocess  def make_thumbnail(upload_path: str) -> None:Removed:     os.system(f"convert {upload_path} -resize 200x200 thumbs/out.png")Added:     subprocess.run(Added:         ["convert", upload_path, "-resize", "200x200", "thumbs/out.png"],Added:         check=True,Added:     )

When it can be wrong

  • The flagged example is also reported as SKY-D212 (command injection), because function parameters count as untrusted. Both findings go away with the fix.
  • cmd = "clear" followed by os.system(cmd) is hidden from the default list as fixed text but is still CRITICAL, so it fails the gate on its own. Writing os.system("clear") directly gives a LOW finding instead.
  • In PHP, a fixed command is still reported as LOW, even when it is harmless.

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 or CRITICAL security finding.

    Python
    os.system(command)  # skylos: ignore[SKY-D203] command is from MAINTENANCE_TASKS
  • Accept existing findings with skylos baseline ., then scan with --baseline.

  • [tool.skylos] ignore = ["SKY-D203"] 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.