{"id":"XE-0015","kind":"bounty","visibility":"public","source":"github","source_repo":"xeprotocol/xe","source_ref":"4","source_url":"https://github.com/xeprotocol/xe/issues/4","reporter_id":2,"title":"security(node,api,core): Unauthenticated VM Credential/Tunnel Access, Post-Expiry Lease Tunneling & Renewed Lease / Multi-Asset Accounting Flaws","area":"node-api","claimed_tier":"severe","assessed_tier":null,"verdict":null,"duplicate_of":null,"tracked":true,"internal_ref":"","internal_url":null,"status":"fixing","closed_reason":null,"github_state":"open","disclosed_at":null,"award_xe":null,"award_approved":false,"paid_ref":"","created_at":"2026-10-29T13:57:14.967892+00:00","updated_at":"2026-11-05T16:08:31.459586+00:00","source_created_at":"2026-10-18T05:26:55+00:00","told_at":null,"status_changed_at":"2026-10-29T14:22:10.245170+00:00","url":"https://bounty.xe.network/XE-0015","body":"> **Disclosure Note**: We attempted to report these findings privately to `security@xe.network` per the [XE Bug Bounty Program](https://test.network/bounty) guidelines, but the address bounced (no MX/recipient configured), and GitHub Private Vulnerability Reporting is not enabled on `xeprotocol/xe`. We are opening this report along with a companion Fix PR containing surgical patches and regression tests.\n\n---\n\n## Summary\n\nDuring a security audit of the `xeprotocol/xe` Track 1 modules (`node/`, `api/`, `core/`), we identified four High/Severe vulnerabilities affecting leased VM authentication/isolation, P2P/HTTP tunnel access control, renewed lease escrow/supply conservation, and multi-asset (`XE` / `XUSD`) ledger accounting:\n\n| # | Severity | Component | Vulnerability |\n|---|---|---|---|\n| **1** | **Severe** | `node/vm.go`, `api/handler.go` | Unauthenticated VM plaintext credential & status disclosure via P2P `vm_status` RPC and HTTP `GET /vms`, `GET /vms/{lease}` |\n| **2** | **Severe** | `node/node.go`, `api/tunnel.go`, `node/ssh_gateway.go` | Unauthenticated P2P `/xe/tunnel/2.0.0` hijacking (`ValidateTunnelLease` ignores `peerID`) and post-expiry VM tunnel/SSH access |\n| **3** | **High** | `node/node.go`, `core/supply.go`, `core/ledger.go`, `core/types.go` | Broken `BlockLeaseRenew` accounting: unrecoverable consumer escrow on `forceSettleLease`, permanent `XUSD` supply conservation failure, missing per-lease lock & conflict staging failure |\n| **4** | **High** | `core/ledger.go`, `core/spendable.go`, `node/node.go` | Multi-asset (`XE` vs `XUSD`) balance corruption in `Ledger.GetBalance`, `Node.GetAllAccounts`, `SpendableBalances`, and conflict `parentBalance` calculation |\n\n---\n\n## Finding 1: Unauthenticated VM Plaintext Credential & Status Disclosure (`node/vm.go`, `api/handler.go`)\n\n### Root Cause\n1. **Unauthenticated P2P `vm_status` RPC (`node/vm.go:40-55`)**:\n   When a lease is provisioned without an `AccessPubKey` (credential mode), `VMManager.Provision` generates plaintext SSH credentials (`vm.Credentials{Username, Password}`) and stores them on `vm.Info.Credentials`. Unlike `vm_credentials` (`node/vm.go:27-30`, which verifies `providerPeer == from`), the `vm_status` P2P handler (`n.Msg.Handle(\"vm_status\", ...)`) performs **no peer authorization** and serializes the entire `vm.Info` struct—including plaintext `Credentials`—to any requesting libp2p peer:\n   ```go\n   n.Msg.Handle(\"vm_status\", func(from peer.ID, payload json.RawMessage) (json.RawMessage, error) {\n       ...\n       info, err := n.VMManager.Get(req.LeaseHash)\n       if err != nil {\n           return nil, err\n       }\n       return json.Marshal(info) // leaks info.Credentials to any peer 'from'\n   })\n   ```\n2. **Unauthenticated HTTP `GET /vms` & `GET /vms/{lease}` (`api/handler.go:200-201`, `node/vm.go:136-167`)**:\n   `GET /vms` and `GET /vms/{lease}` are registered without `h.requireAdmin(...)`, exposing all local `vm.Info` structs (including plaintext `Credentials`) to any unauthenticated HTTP client. Furthermore, when `GET /vms/{lease}` is called for a lease not in `consumerVMs`, `Node.GetVM(leaseHash)` (`node/vm.go:156`) queries the remote provider's `vm_status` P2P RPC even if the local node is not the lease consumer.\n\n### Impact\nBecause `leaseHash` values are public on the DAG ledger, any libp2p peer or unauthenticated HTTP client can query any active credential-mode lease and obtain its plaintext SSH `username` and `password`.\n\n---\n\n## Finding 2: Unauthenticated P2P `/xe/tunnel/2.0.0` Hijacking & Post-Expiry VM Tunnel/SSH Access (`node/node.go`, `api/tunnel.go`, `node/ssh_gateway.go`)\n\n### Root Cause\n1. **`ValidateTunnelLease` Ignores `peerID` (`node/node.go:2176-2189`)**:\n   When a remote peer opens a `/xe/tunnel/2.0.0` stream (`net/tunnel.go:70-128`) and sends a 32-byte `leaseHash`, the provider invokes `Node.ValidateTunnelLease(leaseHash string, peerID peer.ID)`. However, `ValidateTunnelLease` completely ignores `peerID` and never checks whether `peerID` matches `n.PeerForAccount(lease.Consumer)`:\n   ```go\n   func (n *Node) ValidateTunnelLease(leaseHash string, peerID peer.ID) error {\n       lease := n.GetLease(leaseHash)\n       if lease == nil { return fmt.Errorf(\"lease not found\") }\n       if lease.State != core.LeaseAccepted { return fmt.Errorf(\"lease not active\") }\n       if lease.Provider != n.KeyPair.Address() { return fmt.Errorf(\"not the provider for this lease\") }\n       return nil\n   }\n   ```\n   Any libp2p peer on the network can send the public 32-byte `leaseHash` to `/xe/tunnel/2.0.0` and receive a raw TCP stream bridged directly to the VM's internal SSH port (`DialSSH`). Combined with Finding 1, any peer on the P2P network can take over any credential-mode VM.\n2. **Post-Expiry Tunnel & SSH Gateway Access (`node/node.go:2182, 2208`, `api/tunnel.go:25`, `node/ssh_gateway.go:121`)**:\n   A lease remains in `lease.State == core.LeaseAccepted` after `lease.EffectiveExpiry()` during `LeaseSettleGrace` (1 hour) and `LeaseForceSettleGap` (+25 minutes), or up to 8 days (`LeaseEscrowExpiry + LeaseArchiveGap`) before archival. None of `ValidateTunnelLease`, `OpenTunnelForLease`, `handleTunnelTCP`, or `SSHGateway.handleConnection` checks `lease.StartTime > 0 && core.Now().UnixNano() >= lease.EffectiveExpiry()`, allowing continued SSH and TCP tunnel access after lease expiration.\n\n---\n\n## Finding 3: Broken `BlockLeaseRenew` Accounting in Force-Settlement, Supply Conservation & Conflict Staging (`node/node.go`, `core/supply.go`, `core/ledger.go`, `core/types.go`)\n\n### Root Cause\n1. **Consumer Cannot Force-Settle Renewed Leases (`node/node.go:1928-1940` vs `core/ledger.go:1969-1976`)**:\n   Each `BlockLeaseRenew` block tops up the lease's pending escrow (`commit.TopUpPendingID = b.Source`, `commit.TopUpPendingAmount = b.Amount`), so `pending.Amount` equals `lease.Cost + sum(renewals.Cost)`. In `core/ledger.go:1970`, `validateAndAddLeaseForceSettle` requires `b.Balance == oldBal + pending.Amount`. However, `Node.forceSettleLease` (`node/node.go:1934, 1938`) sets `b.Balance = oldXUSD + lease.Cost` and `b.Amount = lease.Cost` (ignoring `lease.Renewals`). Consequently, `n.Ledger.AddBlock(b)` rejects every `forceSettleLease` attempt on a renewed lease with `balance mismatch`, trapping the consumer's initial + renewal XUSD in escrow until `LeaseEscrowExpiry` burns it. Additionally, `validateAndAddLeaseForceSettle` does not validate `b.Amount == pending.Amount`.\n2. **Permanent XUSD Supply Conservation Failure on Renewed Lease Settle/Expiry (`core/supply.go:95-96, 213-215, 280-284`)**:\n   `termsFromChain` ignores `BlockLeaseRenew` blocks and `walk()` only adds `l.Cost` (omitting `l.Renewals[i].Cost`) to `EscrowBurned` when a lease settles or expires. Because `BlockLeaseSettle` / `archiveExpiredLease` deletes the entire topped-up `PendingSend`, settling or expiring any renewed lease causes `SupplyAuditor.Report()` (`GET /supply`) to permanently report `Conserved: false` with a negative `XUSD` discrepancy equal to the sum of all renewal costs.\n3. **Missing Per-Lease Lock & Conflict Staging Support for `BlockLeaseRenew` (`core/ledger.go:492-498, 2779-2785`)**:\n   `isLeaseStateTransition` omits `BlockLeaseRenew`, so `addBlock` (`line 788`) does not acquire `l.acquireLeaseLock(b.Source)` during `BlockLeaseRenew`. Additionally, `ValidateStagedBlock` (`line 2779`) omits `case BlockLeaseRenew:`, rejecting conflicting `lease_renew` blocks with `staged block: unknown type: lease_renew`.\n\n---\n\n## Finding 4: Multi-Asset (`XE` vs `XUSD`) Balance Corruption in `GetBalance`, `GetAllAccounts`, `SpendableBalances`, and Conflict Staging (`core/ledger.go`, `core/spendable.go`, `node/node.go`)\n\n### Root Cause\n1. **`Ledger.GetBalance` & `Node.GetAllAccounts` Return `XUSD` Balance as `XE` Balance (`core/ledger.go:2361-2372`, `node/node.go:998-1001`)**:\n   An `AccountChain` interleaves both `\"XE\"` and `\"XUSD\"` blocks where `b.Balance` stores the post-block balance of `b.Asset`. However, `Ledger.GetBalance(account)` returns `chain.LatestBalance()` (`chain.Blocks[len-1].Balance`) and `Node.GetAllAccounts()` sets `Balance: chain[len(chain)-1].Balance`. Whenever an account's latest block is an `\"XUSD\"` block (`mint`, `lease`, `lease_accept`, `lease_renew`, `lease_cancel`, `lease_force_settle`, or `XUSD` `send`/`receive`), both methods return the account's `XUSD` balance as its `XE` balance.\n2. **Conflict Staging `parentBalance` Omits `BlockLeaseSettle` Stake Return & Default `\"XE\"` Asset (`core/ledger.go:832-842`)**:\n   When staging a conflict block in `addBlock`, `parentBalance` is computed via an inline loop (`if cb.Asset == b.Asset { parentBalance = cb.Balance }`) instead of `l.GetAssetBalanceAtBlock(b.Account, b.Asset, b.Previous)`. This misses the `lease.Stake` credited to `\"XUSD\"` by `BlockLeaseSettle` blocks (`commit.AssetCredit`), causing `ValidateStagedBlock` to reject valid `\"XUSD\"` conflict blocks on provider chains after a lease settlement with a false `balance mismatch`.\n3. **`SpendableBalances` Omits `BlockLeaseSettle` Stake Credit (`core/spendable.go:30-50`)**:\n   When `BlockLeaseSettle` (`b.Asset == \"XE\"`) executes on a provider's chain, `lease.Stake` is returned to the provider's `\"XUSD\"` balance. While `rebuildAssetBalances` and `GetAssetBalanceAtBlock` credit `lease.Stake` to `\"XUSD\"` on `BlockLeaseSettle`, `SpendableBalances` (`core/spendable.go`) ignores it, under-reporting the provider's finalized spendable `XUSD` balance by `lease.Stake` and miscomputing unfinalized `XUSD` outflows after an unfinalized `BlockLeaseSettle`.\n","patch_refs":[{"id":109,"repo":"xeprotocol/xe","kind":"pr","ref":"5","title":"fix(node,api,core): enforce VM/tunnel auth & lease expiry, fix renewed lease & multi-asset accounting","url":"https://github.com/xeprotocol/xe/pull/5","note":"","state":"open","author":"Khanhtnq","added_by":"desk","created_at":"2026-10-29T13:57:30.091343+00:00"}],"thread":[{"id":7,"source":"github","source_ref":"6385434156","author":"kenmungeneskar","team":false,"body":"**Independent reproduction of Finding 3 (XUSD supply conservation), with the exact identity**\n\nNot a new report — just confirming from the outside, with numbers, that this still reproduces on `testnet-0005`.\n\nMeasured on `GET /supply` (6 samples over ~30 s, identical every time):\n\n| field | value |\n|---|---|\n| `XUSD.created` | 213000000 |\n| `XUSD.accounted` | 212967682 |\n| `XUSD.discrepancy` | **−32318** |\n| `XUSD.conserved` | **false** |\n\nAnd the gap is **exactly** the renewal escrow that `termsFromChain` drops:\n\n```\nΣ renewals[].cost over all 101 leases (46 renewals) = 32318\nXUSD.created − XUSD.accounted                       = 32318   ← exact match\n```\n\nReproduce in three commands:\n\n```bash\nNODE=https://ldn.core.test.network\ncurl -s $NODE/supply | jq '(.assets.XUSD.created - .assets.XUSD.accounted)'   # 32318\ncurl -s \"$NODE/leases?limit=1000\" | jq '[.[].renewals[]?.cost] | add'        # 32318\ncurl -s $NODE/supply | jq '.assets.XUSD | {escrow_burned, conserved}'        # 67738, false\n```\n\nTwo data points that may help when fixing:\n\n1. `escrow_burned` currently equals the sum of **settled leases' initial cost only** (67738) — which confirms renewals are the only missing term. Cancelled leases are correctly excluded (they are refunded, not burned; their 1551 is absent from `escrow_burned`).\n2. The discrepancy **drifts monotonically with renewals**: a few hours earlier the same node reported `−27665` with `escrow_burned=58432`. That makes `conserved` a usable **post-fix regression check**: after the fix it should flip to `true` on the existing ledger (no wipe needed), and any future renewal must not move it.\n\nHappy to leave this as evidence under this issue rather than filing a separate report.","created_at":"2026-10-24T14:31:53+00:00"},{"id":1899,"source":"github","source_ref":"6764967693","author":"Reyzz95","team":false,"body":"Still reproduces at HEAD `89a542e` (testnet-0005, 2026-11-10).\n\n`ValidateTunnelLease` (`node/node.go:2176-2190`) still ignores `peerID` and performs no expiry check. A stranger libp2p peer that knows only the public lease hash reaches the VM SSH via `SetupTunnelHandler` (`net/tunnel.go`), and a lease expired ~47h ago is still accepted. Same ticket, same code: unauthenticated `vm_status` (`node/vm.go:40-55`) still returns full `vm.Info` including plaintext credentials to any peer.\n\nNote the HTTP API path is fixed (XE-0026, X-Signature vs `AccessPubKey`) — the libp2p path has no auth at all.","created_at":"2026-11-10T10:27:13+00:00"}]}