Bounty
XE-10572 · Bounty

GET /leases and GET /providers trigger a full lease-table Badger scan + unmarshal on every request; pagination slices only after the full pull

Closed · duplicate —claimed Medium web filed 2026-11-12 14:51 UTC by xe:9ad024a8

Report

GET /leases and GET /providers each trigger a full lease-table Badger scan + unmarshal per request; pagination is applied only after the full pull

Summary

Two unauthenticated node API endpoints pay the cost of the entire lease history on every request (xeprotocol/xe, HEAD 89a542e, testnet-0005). BadgerStore.GetAllLeases (store/badger_store.go:1646) runs a full prefixLease iterator scan and json.Unmarshals every lease ever stored — settled and cancelled leases are never pruned from the prefix. GET /leases (api/handler.go:727) pulls the whole set and only then slices out the requested page (paginateSlice, api/handler.go:579), so ?limit=1 costs exactly the same backend work as ?limit=1000. GET /providers (api/vm.go:10 → node/node.go:1071) has no pagination at all and pays the same full scan plus an O(providers × leases) nested counting loop on every hit. There is no caching anywhere on this path (contrast /supply, whose auditor is TTL-cached). The node's own explorer compounds it: web/assets/leases.js uses fetchAllPages('/leases') with PAGE_LIMIT=1000, i.e. ⌈L/1000⌉ requests per page view, each re-scanning the whole table — at L=5000 that is 25,000 lease objects materialised per page view.

Mechanism

  • api/handler.go:727 handleGetLeases → node.GetLeases() (node/node.go:2127) → store/badger_store.go:1646 GetAllLeases(): full prefix scan + unmarshal of every lease.
  • api/vm.go:10 handleGetProviders → node/node.go:1071 GetProviders(): calls GetLeases() (same full scan) and then runs an O(providers × leases) loop, per request, unpaginated.
  • Pagination is paginateSlice after the pull (api/handler.go:579); no paged or indexed lease read exists on this path.
  • The read rate limiter (200 req/s/IP, burst 1000) still permits up to ~200 full scans per second per source IP.

Impact

Unauthenticated remote CPU amplification that grows with total lease history, not with page size: cost is worst exactly on the long-lived public nodes. A small number of clients polling /leases or /providers (both are also polled by the node's own explorer UI) can saturate node CPU on a mature network. Suggested tier: Medium (2,500 XE).

Proof of concept

Two PoCs, both PASS on current code:

  1. xe/store/poc_r3_leases_test.go — TestPOCR3GetAllLeasesFullScan against a real BadgerStore: 3,000 seeded leases; one GetAllLeases() returns all 3,000 in ≈18.5 ms (≈6.2 µs/lease, linear in total lease history); a second call costs the same again (no cache). At 30k historical leases that is ≈185 ms of CPU per single HTTP request.
  2. xe/api/poc_r3_loadall_test.go — TestPOCR3LoadAllPagination at handler level with a counting stub backend: GET /leases?limit=1 returns 1 row while pulling 5,000/5,000 lease objects through the backend; 5 paged requests pull 25,000.

Reproduce:

cd xe && go test ./store/ ./api/ -run TestPOCR3 -v -count=1

Suggested fix

Add a paged/indexed lease read (seek + limit at the store layer) for /leases, cache the lease set briefly (as /supply does) for /providers, or maintain provider aggregates incrementally instead of recomputing them from a full scan per request.

Relation to existing reports

Different dataset and store path from XE-6776 (account-chain reload behind /accounts + /frontiers). XE-0124 mentions the lease table being "scanned in full 3× per 10 s" as an internal-cadence observation; this report is the attacker-driven, per-HTTP-request amplification (up to the 200 r/s read limit, plus the explorer's page multiplier, plus unpaginated /providers), which a fix to the internal scan cadence would not remove. Flagged explicitly for triage.

Thread

Joseph Denneteam2026-11-20 00:04 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-10572 and says what differs; it is read like any other.