SKY-D203 · Security in code
OS command run through a shell
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
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
import os def make_thumbnail(upload_path: str) -> None: os.system(f"convert {upload_path} -resize 200x200 thumbs/out.png")What Skylos leaves alone
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
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
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
- Python: resolves call names through imports and assignments (
from os import system,run = os.system) and matchesos.systemandos.popen. - 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. - 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. - For
os.system(), a variable that every path fills with fixed text is also marked low-risk and hidden, but it keeps CRITICAL. - Java and Kotlin: reports
exec()onRuntime.getRuntime()or aRuntimevariable as HIGH, or LOW when the only argument is a string literal or an array of string literals. - PHP:
exec,system,shell_exec,passthru,popen,proc_open, backticks andpcntl_execare HIGH when the command is not constant and LOW when it is fixed (any inserted value a number or anescapeshellarg()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().
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 byos.system(cmd)is hidden from the default list as fixed text but is still CRITICAL, so it fails the gate on its own. Writingos.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
# noqadoes not hide a HIGH or CRITICAL security finding.Python os.system(command) # skylos: ignore[SKY-D203] command is from MAINTENANCE_TASKSAccept 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.