{"id":"XE-10572","kind":"bounty","visibility":"public","source":"web","source_repo":"","source_ref":"","source_url":"","reporter_id":1587,"title":"GET /leases and GET /providers trigger a full lease-table Badger scan + unmarshal on every request; pagination slices only after the full pull","area":"node-api","claimed_tier":"medium","assessed_tier":null,"verdict":"duplicate","duplicate_of":null,"tracked":true,"internal_ref":"#1030","internal_url":"https://github.com/xeprotocol/core/issues/1030","status":"closed","closed_reason":"duplicate","github_state":"","disclosed_at":null,"award_xe":null,"award_approved":false,"paid_ref":"","created_at":"2026-11-12T14:51:56.885883+00:00","updated_at":"2026-11-20T00:04:40.372670+00:00","source_created_at":null,"told_at":"2026-11-20T00:04:40.404822+00:00","status_changed_at":"2026-11-20T00:04:40.385687+00:00","url":"https://bounty.xe.network/XE-10572","body":"# GET /leases and GET /providers each trigger a full lease-table Badger scan + unmarshal per request; pagination is applied only after the full pull\n\n## Summary\n\nTwo 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.Unmarshal`s 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.\n\n## Mechanism\n\n- `api/handler.go:727` `handleGetLeases` → `node.GetLeases()` (`node/node.go:2127`) → `store/badger_store.go:1646` `GetAllLeases()`: full prefix scan + unmarshal of every lease.\n- `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.\n- Pagination is `paginateSlice` after the pull (`api/handler.go:579`); no paged or indexed lease read exists on this path.\n- The read rate limiter (200 req/s/IP, burst 1000) still permits up to ~200 full scans per second per source IP.\n\n## Impact\n\nUnauthenticated 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)**.\n\n## Proof of concept\n\nTwo PoCs, both PASS on current code:\n\n1. `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.\n2. `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.\n\nReproduce:\n\n```\ncd xe && go test ./store/ ./api/ -run TestPOCR3 -v -count=1\n```\n\n## Suggested fix\n\nAdd 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.\n\n## Relation to existing reports\n\nDifferent 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.","patch_refs":[],"thread":[{"id":12835,"source":"desk","source_ref":"reply:10857","author":"Joseph Denne","team":true,"body":"Thanks. This is the same finding as an earlier report that is not public, 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-10572 and says what differs; it is read like any other.","created_at":"2026-11-20T00:04:40.372670+00:00"}]}