Bounty
XE-0113 · Bounty

[Security] Tunnel access control bypass: any peer can open a tunnel to any active lease's VM SSH backend (missing consumer authorization)

Closed · duplicate — xe#154 filed 2026-10-29 01:16 UTC by pixxowl

Report

Summary

Node.ValidateTunnelLease (node/node.go:2176) is the only authorization gate on the provider-side tunnel handler (/xe/tunnel/2.0.0, net/tunnel.go:83). It receives the connecting peer's ID as a parameter but never uses it. The gate only checks that (1) the lease exists, (2) the lease is in accepted state, and (3) the local node is the lease's provider.

There is no check that the connecting peer is the lease's consumer. Any peer on the network that knows an accepted lease hash can open a tunnel to that lease's SSH backend on the provider. Lease hashes are public: they are ordinary block hashes on the consumer's account chain, and the node HTTP API exposes every lease (hash, state, consumer, provider) unauthenticated at GET /leases.

  • Class: Broken Access Control / Missing Authorization (CWE-862)
  • Component: compute marketplace — provider tunnel (node/node.go, net/tunnel.go)
  • Introduced: commit a47b973 (testnet-0003); still present at HEAD 9787859. The peerID parameter has been accepted-and-ignored since introduction — not a regression, the check was never implemented.
  • Affected versions: all releases from testnet-0003 onward, including the currently deployed xe/16fc1f9 (see reachability note below).

Vulnerable code

// node/node.go:2176
func (n *Node) ValidateTunnelLease(leaseHash string, peerID peer.ID) error {
	lease := n.GetLease(leaseHash)
	if lease == nil {
		return fmt.Errorf("lease not found")
	}
	if lease.State != core.LeaseAccepted {
		return fmt.Errorf("lease not active")
	}
	if lease.Provider != n.KeyPair.Address() {
		return fmt.Errorf("not the provider for this lease")
	}
	return nil            // <-- peerID never checked against lease.Consumer
}

Called from the tunnel stream handler with the remote peer:

// net/tunnel.go:83
if err := validator.ValidateTunnelLease(leaseHash, s.Conn().RemotePeer()); err != nil { ... }
// on success: validator.DialSSH(leaseHash) -> raw TCP to the lease VM's SSH port

Proof of concept (deterministic, local)

The following test (run against HEAD 9787859) constructs a provider node with one accepted lease whose consumer is keypair B, then calls the exact gate the tunnel handler calls with an unrelated attacker peer ID. It passes the attacker through:

func TestTunnelLeaseAuthBypass(t *testing.T) {
	st := store.NewMemStore()
	providerKP, _ := core.GenerateKeyPair()
	consumerKP, _ := core.GenerateKeyPair()

	leaseHash := "a1b2c3d4e5f60718293a4b5c6d7e8f90a1b2c3d4e5f60718293a4b5c6d7e8f90"
	lease := &core.Lease{
		LeaseHash: leaseHash,
		State:     core.LeaseAccepted,
		Consumer:  consumerKP.Address(),   // the legitimate consumer
		Provider:  providerKP.Address(),
	}
	st.PutLease(lease)

	n := &Node{store: st, KeyPair: providerKP}

	// attacker: valid libp2p peer ID, unrelated to the consumer
	attackerPeer, _ := peer.Decode("12D3KooWGzcTnjXMgNKRVUKvGDHqjZAQSCZ3KdpRqZQFrgn2nvXb")

	err := n.ValidateTunnelLease(leaseHash, attackerPeer)
	// err == nil  -> VULNERABLE: attacker passes the gate
}

Result:

=== RUN   TestTunnelLeaseAuthBypass
    VULNERABILITY CONFIRMED: ValidateTunnelLease let a NON-CONSUMER peer
    (12D3KooWGzcTnjXMgNKRVUKvGDHqjZAQSCZ3KdpRqZQFrgn2nvXb) through for accepted
    lease a1b2c3d4e5f60718 — the peerID parameter is ignored, so any peer can
    reach the provider's SSH backend for any active lease
--- FAIL: TestTunnelLeaseAuthBypass (the test asserts the secure behavior)

Live deployment confirmation (testnet-0005)

The vulnerable handler is deployed and reachable on the live testnet. Probing the peers advertised by https://ldn.core.test.network/node with the tunnel protocol (/xe/tunnel/2.0.0, random 32-byte lease hash, read-only):

12D3KooWSrnK... (189.1.171.51:9000, xe/16fc1f9): *** TUNNEL HANDLER DEPLOYED *** err="lease not found"
12D3KooWM5Um... (67.213.117.123:9000, xe/16fc1f9): handler present (protocol negotiated)

GET https://ldn.core.test.network/leases (unauthenticated) currently returns 100 leases with full metadata (hash, state, consumer, provider). At the time of testing all were settled/cancelled (0 accepted), so no live bypass against a third party's active lease was exercised; the attack applies to any lease while it is accepted.

Attack scenario

  1. Attacker queries GET /leases (or reads any consumer's account chain via GET /accounts/<addr>/chain) and selects a lease with state: accepted.
  2. Attacker connects to the provider's libp2p node and opens a stream on /xe/tunnel/2.0.0, writing the 32-byte lease hash.
  3. ValidateTunnelLease passes (lease exists, accepted, provider is the dialed node) — the attacker's peer ID is never compared to lease.Consumer.
  4. The provider dials the VM's SSH port and pipes the stream: the attacker now has a raw TCP connection to the leased VM's sshd.

Impact

Honest assessment — what is proven vs. what is gated by another control:

Proven (this issue):

  • The consumer-authorization check on the tunnel gate does not exist. The SSH port of every accepted lease VM is reachable by every peer on the network for the full lease duration. Intended exposure was the consumer only.
  • Denial of service against a paying consumer: the tunnel handler has no rate limit and no cap on concurrent streams per lease; each accepted stream forces the provider to open a new SSH connection to the VM (DialSSH). An attacker opening repeated tunnels can exhaust the VM's sshd MaxStartups (default 10:30:100) and lock the legitimate consumer out of the machine they are paying for. Provider-side resources (goroutines, streams, SSH dials) are consumed per tunnel.
  • Enumeration oracle: the gate's distinct error messages ("lease not found" / "lease not active" / pass-through) let any peer test lease hashes and states; combined with the public /leases endpoint, active-lease targeting is trivial.

Gated by a second control (not claimed as direct impact):

  • VMs are provisioned with key-only SSH (vm/lima_template.go: consumer AccessPubKey appended to authorized_keys, PasswordAuthentication no; vm/qemu_template.go: ssh_authorized_keys). An attacker without the consumer's private key cannot authenticate to sshd, so this issue alone is not a VM takeover.

Escalation arguments (for triage's consideration, not claimed):

  • vm/credentials.go generates a per-VM password (randomAlphanumeric(24)) and provisionVM (node/vm.go:83-101) transmits VM credentials to the consumer over the p2p vm_credentials message; any provider deployment that enables password authentication (or any future auth weakening) turns this issue into full unauthenticated VM access.
  • The tunnel is a raw pipe to sshd: protocol-level attacks, credential brute-force surface, and client-side exploits against the consumer's SSH session become available to any peer, not just the lease consumer.
  • The missing check is total (parameter ignored), so the bug also defeats any future per-lease network policy layered on the same gate.

Severity claimed: Medium. Broken access control on a network service with a concrete availability impact against paying users, gated from full compromise by key-only SSH auth. I am deliberately not claiming High/Critical; if triage assesses the DoS-on-paying-consumer path or the password-auth escalation as in-scope impact, I would accept a raise.

Suggested fix

Either (preferred) cryptographically bind the connecting peer to the lease consumer, or bind by identity:

  1. Challenge–response with the lease access key (preferred): after reading the lease hash, the provider sends a nonce; the peer must sign it with the private key corresponding to lease.AccessPubKey (already stored on the lease and validated at block level). No directory dependency, works for any consumer key type.
  2. Peer-to-account binding: resolve peerID to an account (every node self-registers in the directory; PeerForAccount already maps account→peer, build the reverse) and require account == lease.Consumer. Simpler, but depends on the consumer being registered and online.
  3. Defense in depth: rate-limit tunnel streams per (peer, lease) and cap concurrent tunnels per lease to close the DoS regardless of the authorization fix.

Reachability note

The live network runs xe/16fc1f9, which is 5 commits ahead of public HEAD 9787859 and not present in the public repository; I could not diff those commits. The vulnerable function was last modified in e5e65ba (an ancestor of HEAD) and the handler is confirmed deployed on live provider nodes (above), so the bug is present in the deployed build with high confidence. If any of the unreleased commits touches ValidateTunnelLease, please re-verify against 16fc1f9.

Environment / method notes

  • Audited at HEAD 9787859 (GPL-3.0, Go). All testing was read-only or against local keypairs; no third-party lease was touched (0 accepted leases existed at probe time), no load was generated against live nodes, and no state was modified on the testnet beyond the faucet-funded audit wallet.
  • PoC test file: node/tunnel_auth_poc_test.go (asserts the secure behavior; fails on vulnerable code, as shown above).

xe-tunnel-poc.zip

Thread

fangjian-bit2026-10-29 10:49 UTCgithub

Fix submitted in PR #190.

Overview of Fix

  1. Consumer Identity Authorization ( ode/node.go, ode/vm.go):
    • ValidateTunnelLease(leaseHash, peerID) now resolves the registered peer for the lease's consumer ( .PeerForAccount(lease.Consumer)), matching against the authenticated connecting peerID.
    • Rejects unauthenticated/mismatched peer IDs, non-registered consumer identities, and empty peer IDs.
    • Added nil-check guard in .PeerForAccount to prevent panics when Directory is uninitialized.
  2. Tunnel Stream Concurrency Capping & DoS Mitigation ( et/tunnel.go):
    • Upgraded TunnelRegistry to enforce a default maximum of 8 concurrent tunnels per lease (DefaultMaxTunnelsPerLease) and 256 globally (DefaultMaxGlobalTunnels).
    • Stream reservation occurs before dialing the SSH backend, protecting the VM from connection exhaustion and sshd MaxStartups dropouts.
    • Atomic decrement and clean resource release on connection termination or lease close.
  3. Comprehensive Regression Tests:

et/tunnel_test.go: Validates per-lease and global capacity enforcement, graceful teardown via CloseTunnelsForLease, and multi-goroutine -race stress resistance.

ode/tunnel_auth_test.go: Validates strict rejection of unauthorized peers, acceptance of legitimate consumer peers, missing peer ID rejection, and unregistered consumer handling.

All tests passed with -race enabled on Go 1.27.3.

Joseph Denneteam2026-11-05 16:05 UTCgithub

Thanks. This is the same finding as https://bounty.xe.network/XE-0015, 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, reply with what differs and we will look again.