{"id":"XE-0253","kind":"bounty","visibility":"public","source":"web","source_repo":"","source_ref":"","source_url":"","reporter_id":68,"title":"[SECURITY][Minor] SDK - receiveAll aborts on a live lease escrow and strands every pending row behind it","area":"sdk-docs-web","claimed_tier":"minor","assessed_tier":null,"verdict":null,"duplicate_of":null,"tracked":false,"internal_ref":"","internal_url":null,"status":"triaging","closed_reason":null,"github_state":"","disclosed_at":null,"award_xe":null,"award_approved":false,"paid_ref":"","created_at":"2026-11-02T16:39:01.904650+00:00","updated_at":"2026-11-08T20:17:41.885067+00:00","source_created_at":null,"told_at":"2026-11-08T20:18:49.791206+00:00","status_changed_at":"2026-11-08T20:18:33.423031+00:00","url":"https://bounty.xe.network/XE-0253","body":"# [SECURITY][Minor] SDK - receiveAll aborts on a live lease escrow and strands every pending row behind it\r\n\r\n| Field | Value |\r\n|---|---|\r\n| **Severity** | Minor |\r\n| **Area** | SDK — wallet / pending transfers |\r\n| **Component** | `src/xe.ts` (`receiveAll`), `src/client.ts` (`pending`) |\r\n| **Version** | `xeprotocol/sdk` @ `0dbc92ecff709bee79768e4e37788c682a0f4525` (master, 2026-10-23) · `xeprotocol/xe` @ `978785929bc1` |\r\n| **Status** | Reproduced (unit, deterministic) |\r\n| **Date** | 2026-11-02 |\r\n| **Reporter** | Desk web account `xe:64e3ca3f…0cd4` (reporter id 68) — the same person who filed XE-0077 / XE-0078 / XE-0080 under the GitHub login `targammm` (reporter id 30). Please merge the two records so the award history is attributed once. |\r\n\r\n---\r\n\r\n## 1. Summary\r\n\r\n`GET /pending/{address}` returns every pending send addressed to that account. For a **provider** that list\r\nalso contains the **escrow row of any lease it is currently serving**: when a lease is opened, the node escrows\r\nthe consumer's XUSD as a pending send whose destination is the provider (`core/ledger.go:1584-1590`), and that\r\nrow stays in the destination index until the lease is settled or cancelled.\r\n\r\nThe node refuses to let that row be received while the lease is live:\r\n\r\n```go\r\n// core/ledger.go:1072-1099\r\nfunc (l *Ledger) isLiveLeaseEscrow(sendHash string) bool {\r\n    lease, ok, err := l.getLeaseOverlay(sendHash)\r\n    if !ok || err != nil || lease == nil { return false }\r\n    return lease.State == LeaseCreated || lease.State == LeaseAccepted\r\n}\r\n...\r\nif l.isLiveLeaseEscrow(b.Source) {\r\n    return fmt.Errorf(\"cannot receive a live lease escrow: %s\", shortHash(b.Source))\r\n}\r\n```\r\n\r\nThe SDK's `receiveAll()` claims every pending row in order and has no idea that one of them is an escrow:\r\n\r\n```typescript\r\n// src/xe.ts:220-227\r\n/** Claim every pending send, oldest first. Sequential: each commits to the previous frontier. */\r\nasync receiveAll(): Promise<SubmitResult[]> {\r\n  const results: SubmitResult[] = []\r\n  for (const p of await this.pending()) {\r\n    results.push(await this.receive(p))\r\n  }\r\n  return results\r\n}\r\n```\r\n\r\nThe escrow row is appended to the destination index when the lease opens, and the index is **append-ordered**,\r\nso the escrow is normally *earlier* in the list than the transfers that arrived after it. `receiveAll()` builds\r\na `receive` block for the escrow, the node rejects it with HTTP 400, and the exception escapes the loop —\r\n**every pending row behind it is never claimed**.\r\n\r\n## 2. Affected code\r\n\r\n| File | Line | Issue |\r\n|---|---|---|\r\n| `src/xe.ts` | 221–227 | `receiveAll` — no per-row error handling; the first rejected row aborts the whole loop |\r\n| `src/xe.ts` | 199–218 | `receive` — builds the `receive` block without checking whether the source is a live escrow |\r\n| `src/client.ts` | 268–287 | `pending()` — maps every row the node returns, including escrow rows |\r\n| `core/ledger.go` | 1584–1590 | `validateAndAddLease` — `AddPending{ Destination: b.Destination, Asset: \"XUSD\" }` ⇒ the escrow is addressed to the **provider** |\r\n| `core/ledger.go` | 1097–1099 | `validateAndAddReceive` — rejects a live escrow: *\"cannot receive a live lease escrow\"* |\r\n| `core/ledger.go` | 2395–2403 | `GetPendingForAccount` → `store.GetPendingByDest(account)` |\r\n| `store/badger_store.go` | 291 | `GetPendingByDest` returns the destination index in append order (oldest first) |\r\n| `store/badger_store.go` | 778 | `destHashes = append(destHashes, c.AddPending.SendHash)` — the index is append-ordered |\r\n\r\n## 3. Reproduction\r\n\r\nDeterministic — the `XeClient` is stubbed with the exact node error, so no network is needed.\r\n\r\n```javascript\r\n// repro-receiveall-lease-escrow.mjs\r\nconst rows = [\r\n  { hash: 'a1a1a1a1', asset: 'XUSD', amount: 500000n },  // the live lease escrow\r\n  { hash: 'b2b2b2b2', asset: 'XE',   amount: 42n },      // an ordinary transfer behind it\r\n]\r\nconst client = {\r\n  networkId: async () => 'testnet-0005',\r\n  balances: async () => ({ balances: { XUSD: 0n, XE: 0n } }),\r\n  frontier: async () => '00'.repeat(32),\r\n  pending: async () => rows,\r\n  submitBlock: async (b) => {\r\n    if (b.source === 'a1a1a1a1') throw new Error('HTTP 400: cannot receive a live lease escrow')\r\n    return { hash: 'submitted' }\r\n  },\r\n}\r\nconst xe = new Xe({ client, address: ADDR, wallet: WALLET })\r\nawait xe.receiveAll()\r\n```\r\n\r\n**Observed:**\r\n\r\n```\r\nblocks the SDK built and submitted:\r\n  type=receive asset=XUSD source=a1a1a1a1a1a1... balance=500000\r\n\r\nreceiveAll() threw : HTTP 400: cannot receive a live lease escrow\r\nrows claimed        : 1 of 2\r\n\r\nnever claimed:\r\n  b2b2b2b2b2b2b2...  XE 42\r\n```\r\n\r\nFull script: `repro-receiveall-lease-escrow.mjs`.\r\n\r\n## 4. Impact\r\n\r\n- **A provider's ordinary incoming transfers stop being claimable** for as long as it is serving a live lease.\r\n  Provider income arrives as XE emissions and direct transfers; both sit behind the escrow row in the\r\n  destination index, so `receiveAll()` — the one-call \"claim everything\" helper the SDK offers — cannot claim\r\n  them.\r\n- **The failure is loud but the remedy is manual.** The caller gets an exception naming the escrow row, and\r\n  has to call `receive(row)` per remaining row. Nothing is lost — the rows stay pending — but a script that\r\n  calls `receiveAll()` on a timer will keep failing on every tick and keep claiming nothing.\r\n- **The window is the lease's lifetime.** The escrow row is deleted when the lease is settled or cancelled, so\r\n  the next `receiveAll()` after the lease closes works.\r\n- **Renewals do not add rows** (a renewal tops up the existing pending), so one escrow row blocks the list for\r\n  the whole engagement, not one row per renewal.\r\n\r\n> **Honest boundary:** no funds are lost and no consensus rule is bypassed — the node rejects the escrow\r\n> receive exactly as it should. The defect is a missing filter and a missing per-row error path in the client's\r\n> \"claim everything\" helper: the rows remain pending and are recoverable one by one. That is a robustness /\r\n> accounting-hygiene issue, not a loss, hence Minor rather than Medium.\r\n\r\n## 5. Why the test suite misses it\r\n\r\n`test/unit/lease.test.ts` exercises the lease path against a **mocked** `Xe`; `test/unit/client.test.ts`\r\ncovers the wire mapping of `pending()`. Neither drives `receiveAll()` against a list that contains an escrow\r\nrow, and the mock `submitBlock` never rejects one row — so the loop's error path is never taken.\r\n\r\n## 6. Suggested fix\r\n\r\n1. Skip rows the node will not accept. The cleanest signal is the node's own error text, but a better fix is\r\n   to filter before submitting: the escrow row is the one whose `source` is a live lease, and the SDK already\r\n   has the lease state for hashes it has seen.\r\n2. At minimum, make `receiveAll()` **not abort** on one rejected row: catch per-row errors, record them, and\r\n   continue with the remaining rows; return the failures alongside the successes (or expose them on a\r\n   `skipped` field) instead of throwing.\r\n3. Add a regression test that drives `receiveAll()` with a mock that rejects the first row and asserts that\r\n   the second row is still claimed.\r\n\r\n## 7. Duplicate check\r\n\r\n- `xeprotocol/sdk`: **0 issues, 14 PRs** (fetched 2026-11-02). No PR or issue mentions `receiveAll`, the\r\n  escrow, or pending sends. PR #4 (`ci: run the leasing tutorials … claiming its refunds`) exercises refunds\r\n  through `receive`, but it does not touch `receiveAll` and has no escrow row in the list.\r\n- `xeprotocol/xe`: **236 issues + PRs**, all fetched and searched 2026-11-02 — **0 hits for `receiveAll`**.\r\n  The escrow-related entries are node-side and different: **#68** / **#136** (supply auditor does not count\r\n  lease-renewal escrow), **#171** / **#39** (lease cancel must refund renewal escrow), **#155** / **XE-0102**\r\n  (after a renewal the shipped client can never force-settle), **#78** (`/pending` and `/accounts` silently\r\n  truncate to 100 items), **#210** (PR: replace the monolithic pending-by-destination JSON array with indexed\r\n  keys). None is the SDK's `receiveAll` loop.\r\n- XE bounty desk: all **113 published tickets** searched 2026-11-02 — 0 hits for `receiveAll` or \"receive\r\n  all\"; the escrow hits are XE-0012, XE-0101 and XE-0102, all node-side.\r\n\r\n## 8. Submission checklist (per programme \"How to Report\")\r\n\r\n| Step | Requirement | Status |\r\n|---|---|---|\r\n| 1 | Reproduce against testnet; capture tx hashes / block heights | Reproduced locally and deterministically with the node's exact rejection string; the ordering (escrow before later transfers) follows the node's append-ordered destination index (`store/badger_store.go:291,778`). Not exercised live — it needs a provider holding a live lease, which costs a real lease on the testnet. |\r\n| 2 | GitHub issue with suggested severity tier and area | Tier: **Minor** · Area: **SDK — wallet / pending transfers** |\r\n| 3 | Clear PoC + impact analysis (who is affected, worst case) | Included — sections 3 and 4 |\r\n| 4 | Critical/Severe goes to `security@xe.network` first | Not applicable — Minor is below Severe, so a public issue is the correct channel |\r\n| 5 | Triage by the core team | Awaiting |\r\n| 6 | XE address for payout at genesis | `64e3ca3f6e9378cd549032de9f087b5496fd4100516c7bdb46c17b00d4220cd4` — XE native chain (block lattice, ed25519), derived from the reporter's recovery phrase via BIP39 → SLIP-0010 ed25519 `m/44'/1'/account'`; address = `sha256(\"xe/account/v1\" ‖ pubkey)` |\r\n\r\n---\r\n\r\n*Suggested tier: Minor (650 XE) — missing filter and missing per-row error path; pending rows stay pending and are recoverable, no permanent loss*","patch_refs":[],"thread":[{"id":1153,"source":"desk","source_ref":"reply:705","author":"Joseph Denne","team":true,"body":"Thanks for the report. We have confirmed the behaviour you describe in the SDK's claim helper and it is being handled; we will update https://bounty.xe.network/XE-0253 when there is a fix to point at.","created_at":"2026-11-08T20:17:41.885067+00:00"}]}