{"id":"XE-13374","kind":"bounty","visibility":"public","source":"github","source_repo":"xeprotocol/xe","source_ref":"528","source_url":"https://github.com/xeprotocol/xe/issues/528","reporter_id":2252,"title":"Unauthenticated cross-tenant libp2p tunnel: any peer can open a raw TCP tunnel to any accepted lease's VM, bypassing the HTTP tunnel's signature check","area":"node-api","claimed_tier":"medium","assessed_tier":null,"verdict":"duplicate","duplicate_of":"XE-0015","tracked":true,"internal_ref":"#1083","internal_url":"https://github.com/xeprotocol/core/issues/1083","status":"closed","closed_reason":"duplicate","github_state":"closed","disclosed_at":null,"award_xe":null,"award_approved":false,"paid_ref":"","created_at":"2026-11-14T20:42:12.949886+00:00","updated_at":"2026-11-20T00:52:01.063356+00:00","source_created_at":"2026-11-13T03:20:04+00:00","told_at":"2026-11-20T00:50:57+00:00","status_changed_at":"2026-11-20T00:50:02.292050+00:00","url":"https://bounty.xe.network/XE-13374","body":"**Suggested tier:** Medium\n\n**XE address (reward destination):** 9b663fdac108be34a3b715ef78a9f9bd878af6ef8142f388c6514918e6852dd7\n\n## Summary\n\n`net/tunnel.go`, `SetupTunnelHandler` (the `/xe/tunnel/2.0.0` stream handler, registered for every node at `node/node.go:549`) + `node/node.go:2176`, `ValidateTunnelLease`.\n\nThe tunnel handler's ONLY gate is `ValidateTunnelLease(leaseHash, peerID)`, and that function never inspects `peerID` — it checks only that the lease exists, is `LeaseAccepted`, and that *this node is the provider*. There is no check that the dialing peer is the lease's consumer (`PeerForAccount(lease.Consumer)`), no signature over the lease hash, and no comparison against `AccessPubKey`. The `peerID` parameter is dead.\n\nContrast with the two intended gates on the same VM: the HTTP endpoint `POST /tunnel/{leaseHash}/tcp` (`api/tunnel.go`) requires header `X-Signature` verified by `core.VerifyHexSignature(lease.AccessPubKey, …)` over the lease hash, and the SSH gateway (`node/ssh_gateway.go`) compares the presented Ed25519 key byte-for-byte with `AccessPubKey`. The libp2p tunnel skips both.\n\nReachability: any peer can connect to a provider's libp2p host (no allowlist; `NetworkGater` only bans wrong-network/wrong-version peers, and a stock `xe` node passes netcheck trivially). Lease hashes are public (`GET /leases`, `GET /leases/{hash}`). The attacker needs no account, no key, no signature — only the 32-byte lease hash, sent as the first tunnel message. No per-peer rate limiter is applied to the tunnel protocol (unlike `net/msg.go`, `net/sync.go`, `net/netcheck.go`, which all use `peerRateLimiter`); only the libp2p resource manager's per-IP connection cap (8 conns/IP, `net/host.go`) bounds it.\n\n## Impact\n\nCapped, honestly stated: the tunnel hands the attacker a raw TCP pipe to the victim VM's SSH port (`vm/qemu_manager.go:298` / `vm/lima_manager.go:182`, `DialSSH` dials `127.0.0.1:<vm ssh port>`). **The VM itself still requires the lease SSH key**: QEMU cloud-init installs ONLY the `AccessPubKey` (`vm/qemu_template.go`, `ssh_pwauth: false`) and Lima sets `PermitRootLogin prohibit-password` + `PasswordAuthentication no` (`vm/lima_template.go`). **So this is NOT a direct shell — the attacker cannot log in without the consumer's private key.** What it does give a complete stranger, for ANY tenant's VM on ANY provider: unauthenticated network reachability to the VM's sshd (banner/version fingerprinting, sshd exploit surface, SSH-auth probing), cross-tenant isolation failure at the tunnel layer, and an unthrottled channel for connection-exhaustion against the provider (each tunnel holds a backend TCP conn + 2 goroutines, registry unbounded, no per-lease/per-peer tunnel cap). Hence Medium, not High: no shell, no data, no funds without the lease key.\n\n## Steps to reproduce\n\nUnit test against the real node code (`github.com/xeprotocol/xe`, testnet-0005, commit `89a542e`):\n\n```\ngit clone https://github.com/xeprotocol/xe\ncd xe\ncp trackc_tunnel_test.go node/\ngo test ./node -run TestTrackC_TunnelAnyPeer -v\n```\n\nNote: `trackc_tunnel_test.go` is NOT in the public repository — the PoC test file is attached to this issue; without it, the XE team cannot run this reproduction.\n\n`TestTrackC_TunnelAnyPeer`: an arbitrary unrelated peer (not the lease consumer, not the provider) calls `ValidateTunnelLease` for an accepted lease.\n\n**Expected:** the unrelated peer is rejected; only the lease consumer's peer passes.\n**Actual (reproduced 2026-11-13, PASS as a bug-demonstrating test):**\n```\n=== RUN   TestTrackC_TunnelAnyPeer\n    trackc_tunnel_test.go:56: consumer peer allowed (expected)\n    trackc_tunnel_test.go:63: BUG CONFIRMED: arbitrary unrelated peer \"2dLTETvbnJuVtSUUsA3XG8dr8DHCyM6vsZT1bcv9rHB4cVgTtehi6CXjbA\" passes ValidateTunnelLease for lease abababababab (provider 8d6944d627cd, consumer 90c1f2c13523)\n    trackc_tunnel_test.go:70: control: unknown lease rejected (expected)\n    trackc_tunnel_test.go:80: control: settled lease rejected (expected)\n--- PASS: TestTrackC_TunnelAnyPeer (0.00s)\n```\n\n## Root cause\n\n`node/node.go:2176`, `ValidateTunnelLease`: the `peerID` argument is never compared against anything — no `peerID == n.PeerForAccount(lease.Consumer)` check, no signature over the lease hash by `AccessPubKey`. The libp2p tunnel handler (`net/tunnel.go`, `SetupTunnelHandler`) relies solely on this function, unlike the HTTP tunnel endpoint and the SSH gateway, which both authenticate the caller.\n\n## Suggested fix\n\nIn `ValidateTunnelLease`, require `peerID == n.PeerForAccount(lease.Consumer)` (directory lookup, as `provisionVM`/`GetVM` already do for the consumer), or better, require the dialing peer to present a signature over the lease hash by the `AccessPubKey` in the tunnel handshake (same check as the HTTP endpoint). Also cap concurrent tunnels per lease/per peer and apply the existing `peerRateLimiter` to the tunnel protocol.\n\n## Controls verified (same track, all PASS / NOT VULNERABLE)\n\n- VM access with the wrong key is blocked at the SSH gateway and at the HTTP tunnel endpoint (Round 1, still holds) — the libp2p tunnel is the exception: it checks NO key at all.\n- SSH session reuse after lease expiry / cancel / settle: a new `direct-tcpip` channel re-enters through `ValidateTunnelLease`, which re-checks state — settled/cancelled/expired leases are rejected; the provider closes registered tunnels in `finishSettle` and tears the VM down within 10 s via `cleanupOrphanedVMs` for any terminal lease.\n- No unauthenticated state change was found on any other API endpoint (full route enumeration in `api/handler.go`).\n- VM/tunnel key confusion: SSH gateway and HTTP tunnel both require exactly `AccessPubKey`; QEMU/Lima install exactly that key. No confusion path found.\n\n[trackc_tunnel.txt](https://github.com/user-attachments/files/34781598/trackc_tunnel.txt)","patch_refs":[{"id":578,"repo":"xeprotocol/xe","kind":"pr","ref":"554","title":"node,net: authenticate tunnel consumer peer and cap concurrent tunnel streams (Fixes #528)","url":"https://github.com/xeprotocol/xe/pull/554","note":"","state":"open","author":"Khanhtnq","added_by":"desk","created_at":"2026-11-14T20:42:20.311243+00:00"},{"id":742,"repo":"xeprotocol/xe","kind":"pr","ref":"914","title":"fix(xe): unauthenticated-cross-tenant-l (fixes #528)","url":"https://github.com/xeprotocol/xe/pull/914","note":"","state":"open","author":"tipprb","added_by":"desk","created_at":"2026-11-20T00:27:48.430960+00:00"}],"thread":[{"id":13486,"source":"github","source_ref":"7026822977","author":"Joseph Denne","team":true,"body":"Thanks. This is the same finding as https://bounty.xe.network/XE-0015, which was filed first; the programme pays the\nfirst verifiable submission, so this one closes as a duplicate. If you believe it is a different\nbug, file a new report that links https://bounty.xe.network/XE-13374 and says what differs; it is read like any other.","created_at":"2026-11-20T00:50:57+00:00"}]}