Bounty
XE-8592 · Bounty

`xe ssh` treats a 404 lease as present: `client.getJSON` ignores HTTP status, so a missing lease still invokes OpenSSH against the public gateway

Closed · duplicate —claimed Medium web filed 2026-11-11 23:53 UTC by away7000

Report

Summary

client.getJSON always decodes the response body and returns (map, nil), even when the node answers 404 / 4xx / 5xx. GetLease is a thin wrapper around it:

func (c *Client) GetLease(hash string) (map[string]interface{}, error) {
	return c.getJSON(fmt.Sprintf("%s/leases/%s", c.BaseURL, hash))
}

Against a missing lease the live node returns 404 {"error":"lease not found"}. GetLease therefore returns map[error:lease not found], err=nil — a non-nil map.

cmdSSH only treats a nil lease as missing:

lease, _ := c.GetLease(leaseHash)
if lease == nil {
    fatal("lease not found: %s", leaseHash)
}
if settled, _ := lease["settled"].(bool); settled { ... }
// then builds ProxyCommand and exec.Command("ssh", ...)

So xe ssh <any-64-hex-that-is-not-a-lease> never prints "lease not found". It proceeds to exec the system ssh with ProxyCommand=… <hash>@ldn.test.network (or XE_SSH_HOST). Contrast xe lease status, which correctly checks lease["error"] and fatals.

Steps to reproduce

Build xe at 89a542e. Use any wallet path that has (or create) a PEM at <wallet-without-.seed>.lease_key_openssh so the "no SSH key" path is not hit — a dummy PEM is enough because we only need to prove ssh is invoked:

XE_WALLET=/path/to/w.seed
printf '%s\n' '-----BEGIN OPENSSH PRIVATE KEY-----' 'x' '-----END OPENSSH PRIVATE KEY-----' \
  > "$(dirname "$XE_WALLET")/$(basename "$XE_WALLET" .seed).lease_key_openssh"

# Prove OpenSSH is reached for a lease that does not exist:
cat > /tmp/binfake/ssh <<'SH'
#!/bin/bash
echo "FAKE_SSH_INVOKED args=$*" >&2
exit 42
SH
chmod +x /tmp/binfake/ssh
PATH=/tmp/binfake:$PATH XE_WALLET=$XE_WALLET ./xe ssh aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
# → prints FAKE_SSH_INVOKED … aaaa…@ldn.test.network … root@vm ; exit 42

# Control: the sibling command correctly rejects the same hash
./xe lease status aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
# → error: lease not found: aaaa…

Read-only confirmation that GetLease itself is status-blind (no SSH):

c := client.New("https://ldn.core.test.network")
m, err := c.GetLease("0000000000000000000000000000000000000000000000000000000000000000")
// err == nil, m == map[error:lease not found]

Evidence

Observed 12 Nov 2026 06:50 WIB against https://ldn.core.test.network with a throwaway wallet and a PATH-shadowed ssh:

FAKE_SSH_INVOKED args=-o ProxyCommand=ssh -p 2222 -i …/w1.lease_key_openssh -W %h:%p
  -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o LogLevel=ERROR
  aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa@ldn.test.network
  -i …/w1.lease_key_openssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null
  -o LogLevel=ERROR root@vm
exit:42

GetLease on a zero hash contemporaneously returned err=<nil> map=map[error:lease not found]. xe lease status on the same hash exited 1 with lease not found.

No real SSH session to a VM was opened; the fake binary exited immediately. No lease was created, no funds moved.

Expected vs actual

  • Expected: a missing lease → clear lease not found (as lease status already does); no ssh process; HTTP non-2xx from GetLease/getJSON returned as an error.
  • Actual: 404 is decoded as a successful map; xe ssh skips the nil check and execs OpenSSH toward the public gateway with the caller-supplied hash as the gateway username.

Impact

  • Operators get no "lease not found" signal and instead open outbound SSH to XE_SSH_HOST (default ldn.test.network:2222) with a fabricated lease identity.
  • Composes with the already-reported ProxyCommand injection class (XE-2814): the hash reaches the shell-interpolated ProxyCommand without an existence check.
  • Same getJSON blindness also makes GetCertificate return map[error:…] with err=nil (cmdLease currently papers over that by testing hash == nil).

Suggested fix

Make getJSON (and every status-blind getter) return an error on non-2xx, matching GetReputation / GetVM. In cmdSSH, also reject maps that carry an error field or lack expected lease fields before building ProxyCommand.

Dedup

Searched all 1,458 public tickets (refreshed 12 Nov 2026 06:42 WIB). Nearby but not the same impact:

  • XE-8572 — Go client ignores HTTP status in GetPending / GetProviders / GetBalances (false empty results). Does not mention getJSON, GetLease, or xe ssh.
  • XE-0121 / XE-0625 / XE-0744 — GetChain / other getters status-blindness and nil handling; closed or scoped to send/prev=0.
  • XE-2814 — shell injection via lease hash in ProxyCommand (assumes the command runs); this report is that the command runs at all for a non-existent lease.
  • XE-0076 / XE-2351 — StrictHostKeyChecking=no (host-key MITM), not existence checks.

Caveat: private tickets cannot be searched.

Thread

Joseph Denneteam2026-11-17 09:42 UTCdesk

Thanks. This is the same finding as an earlier report that is not public, which was filed first; the programme pays the first verifiable submission, so this one closes as a duplicate. If you believe it is a different bug, file a new report that links https://bounty.xe.network/XE-8592 and says what differs; it is read like any other.