Skip to main content

SKY-D212 · Security in code

Command injection

CriticalCWE-78

Python, PHP, Java, Kotlin, C#, Ruby and TypeScript request-flow findings are CRITICAL. Some are HIGH: in TypeScript and JavaScript, any X.exec() call in a file that loads child_process, shelljs, ssh2, node-ssh or dockerode, even with no proven outside data; in Go, a sh -c command built from a non-constant value with no proven outside source; and every Rust and Dart finding. In shell scripts the severity drops one step when only the script's own arguments reach the command behind a root-only check, or when the command runs as a non-root user. A shell finding whose only source is the script's own command-line arguments is a review signal that is not listed by default and does not fail a gate: whoever runs the script chooses them. The same holds for a Rust finding whose only inputs are environment variables, command-line arguments or a function's parameters.

Command injection happens when outside text becomes part of a command that a shell runs. Skylos reports SKY-D212 when data from a request, a function parameter or input() reaches shell command text, such as subprocess.run(..., shell=True) or os.system(), or chooses which program runs.

Languages
Python, TypeScript/JavaScript, Go, Java, Kotlin, C#, PHP, Rust, Ruby, Dart, Shell
Quality gate
counted toward the gate limits; a CRITICAL finding fails the gate on its own (full and diff scans)
Finding type
review
Go engine ID
SKY-G212, reported as SKY-D212
Wrong result? Report itA false positive, a missed case or a confusing message: it goes privately to the founder.

Why it matters

A visitor who sends example.com; cat /etc/passwd as a host name runs a second command on your server, with the server's files, keys and network access. One such endpoint is enough to take over the machine.

What Skylos flags

app/tools.py · PythonReported on line 11
import subprocess from flask import Flask, request app = Flask(__name__)  @app.post("/ping")def ping():    host = request.form.get("host", "")    out = subprocess.run(f"ping -c 1 {host}", shell=True, capture_output=True)    return {"output": out.stdout.decode()}

What Skylos leaves alone

app/tools.py · Python
import shleximport subprocess from flask import Flask, request app = Flask(__name__)  @app.post("/ping")def ping():    host = request.form.get("host", "")    command = f"ping -c 1 {shlex.quote(host)}"    out = subprocess.run(command, shell=True, capture_output=True)    return {"output": out.stdout.decode()}

Why Skylos leaves it alone

shlex.quote() wraps the host in single quotes and escapes any quote inside it, so the shell sees one word. Skylos checks where the quoted value lands: after a fixed program name, outside other quotes, with no $(, backtick, comment or unknown text before it. The line still gets SKY-D209, because it uses shell=True.

More languages

TypeScript

Flagged

src/server.ts · TypeScriptReported on line 8
import express from "express";import { exec } from "child_process"; const app = express(); app.get("/ping", (req, res) => {  const host = String(req.query.host ?? "");  exec(`ping -c 1 ${host}`, (err, stdout) => {    res.json({ ok: !err, output: stdout });  });}); app.listen(3000);

Not flagged

src/server.ts · TypeScript
import express from "express";import { execFile } from "child_process"; const app = express(); app.get("/ping", (req, res) => {  const host = String(req.query.host ?? "");  execFile("ping", ["-c", "1", host], (err, stdout) => {    res.json({ ok: !err, output: stdout });  });}); app.listen(3000);

Why Skylos leaves it alone

execFile() starts ping directly with an argument array and no shell, so the host is one argument and cannot start a new command.

Go

Flagged

main.go · GoReported on line 10
package main import (	"net/http"	"os/exec") func ping(w http.ResponseWriter, r *http.Request) {	host := r.URL.Query().Get("host")	err := exec.Command("sh", "-c", "ping -c 1 "+host).Run()	if err != nil {		http.Error(w, "host unreachable", http.StatusBadGateway)		return	}	w.WriteHeader(http.StatusNoContent)} func main() {	http.HandleFunc("/ping", ping)	http.ListenAndServe(":8080", nil)}

Not flagged

main.go · Go
package main import (	"net/http"	"os/exec") func ping(w http.ResponseWriter, r *http.Request) {	host := r.URL.Query().Get("host")	err := exec.Command("ping", "-c", "1", host).Run()	if err != nil {		http.Error(w, "host unreachable", http.StatusBadGateway)		return	}	w.WriteHeader(http.StatusNoContent)} func main() {	http.HandleFunc("/ping", ping)	http.ListenAndServe(":8080", nil)}

Why Skylos leaves it alone

The program is the fixed literal ping and the host is a separate argument. Go's exec.Command does not use a shell, so Skylos only checks the program, or the -c script of a shell such as sh.

How Skylos decides

  1. In Python, finds shell-string calls (os.system, os.popen, subprocess.getoutput, subprocess.getstatusoutput, asyncio.create_subprocess_shell), subprocess.* calls with shell=True or a shell= value that is not a literal False, None or 0, an SSH client's exec_command(), the program argument of os.exec*, os.spawn*, os.posix_spawn* and pty.spawn, and the script after -c when the program is a shell (["bash", "-c", script]). Import aliases such as import subprocess as sp are resolved; a local function with the same name is not a sink.
  2. Treats a value as tainted when it comes from request.*, input() or a function parameter (except self and cls), directly or through assignments, f-strings, +, % and .format(). sys.argv and environment variables are not sources for this rule.
  3. Leaves an argument list for a fixed program alone (subprocess.run(["git", "fetch", ref])): an outside argument to a fixed program is not a shell command.
  4. Accepts shlex.quote() and shlex.join() only where the quoted value stays one shell word: after a program name made of plain characters that is not a shell or code runner (sh, python, eval, xargs and others), outside quotes, and with no $(, backtick, here-document, comment or unknown text before it. "echo '" + shlex.quote(x) + "'" is still reported.
  5. Does not recognise allowlist checks: a value tested with if host not in ALLOWED: abort(400) is still tainted afterwards.
  6. TypeScript and JavaScript: request data from an Express, Fastify, Koa, NestJS or Next.js handler that reaches child_process.exec() or execSync() command text is CRITICAL. Separately, any X.exec() call in a file that loads a command module is HIGH, unless X is a proven RegExp or comes from a database package (const { R } = require("redbean-node"), pg, knex, ...). A command that is one string literal is kept but not listed by default.
  7. Go (reported by the Go engine as SKY-G212): exec.Command, exec.CommandContext, os.StartProcess and syscall.Exec whose program comes from request or network input, and sh -c / bash -c scripts built from a variable. os.Args, flags and environment variables are not sources there either. Java, Kotlin, C#, PHP, Ruby, Dart and shell scripts have their own checks for outside data reaching a process call.
  8. Rust: Command::new() with a non-literal program, or the code of sh -c/cmd /C/powershell -Command, is listed only when request data is an actix-web or axum extractor (Path, Query, Json, Form, ...), a Rocket Json/Form/Data guard or text route parameter (#[get("/x/<name>")] with name: &str), or the data methods of an HttpRequest/Request (uri(), query_string(), headers(), ...). A program chosen by an environment variable, std::env::args or a function's parameter stays in the report as a review item that is not listed and does not fail a gate. A request value passed to a helper in the same file is reported at that call.

How to fix it

Run a fixed program with an argument list and no shell. Each value is then one argument and can never start another command. Check the value too (for example that it is a host name), so it cannot pass an option such as -f to the program.

app/tools.py · Python · the fix, against the flagged file
import subprocess from flask import Flask, request app = Flask(__name__)  @app.post("/ping")def ping():    host = request.form.get("host", "")Removed:     out = subprocess.run(f"ping -c 1 {host}", shell=True, capture_output=True)Added:     out = subprocess.run(["ping", "-c", "1", "--", host], capture_output=True)    return {"output": out.stdout.decode()}

When it can be wrong

  • A helper that receives the command as a parameter, such as def run(cmd): subprocess.run(cmd, shell=True), is reported even when every caller passes a constant. Parameters count as untrusted.
  • A value checked against an allowlist before the call is still reported: the check is not recognised.
  • The same line usually also gets SKY-D209 (shell=True) or SKY-D203 (os.system), which report the call itself whatever its input.

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

  • Silence one line and say why. Only the listed rule is hidden. A bare # noqa does not hide HIGH or CRITICAL security findings.

    Python
    subprocess.run(cmd, shell=True)  # skylos: ignore[SKY-D212] cmd is from COMMANDS
  • Accept the findings you already have with skylos baseline ., then scan with --baseline so only new ones are listed.

  • [tool.skylos] ignore = ["SKY-D212"] turns the rule off for the whole project, real injections included.

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