{"id":"XE-0704","kind":"bounty","visibility":"public","source":"github","source_repo":"xeprotocol/xe","source_ref":"275","source_url":"https://github.com/xeprotocol/xe/issues/275","reporter_id":7,"title":"GET /chat/messages and GET /providers return entire collections with no pagination or limit","area":"node-api","claimed_tier":null,"assessed_tier":null,"verdict":"duplicate","duplicate_of":"XE-0610","tracked":false,"internal_ref":"","internal_url":"","status":"closed","closed_reason":"duplicate","github_state":"closed","disclosed_at":null,"award_xe":null,"award_approved":false,"paid_ref":"","created_at":"2026-11-05T12:55:07.009979+00:00","updated_at":"2026-11-14T22:55:19.804389+00:00","source_created_at":"2026-11-05T12:54:53+00:00","told_at":"2026-11-14T22:53:49+00:00","status_changed_at":"2026-11-08T20:32:08.810298+00:00","url":"https://bounty.xe.network/XE-0704","body":"## Summary\n\nTwo GET endpoints return their full collection on every request, with no\nlimit or offset parameter. `GET /chat/messages` returns up to 1,000 envelopes\nper account, measured at 8,574,002 bytes for maximum-size messages.\n`GET /providers` ranges the whole provider advertisement map, measured at\n271,002 bytes for 1,000 entries and 2,710,002 bytes for 10,000 entries.\nThe codebase already has a pagination pattern (`parsePagination` /\n`paginateSlice`, used by `GET /directory` and ten other collection\nendpoints). These two endpoints skip it.\n\n## Affected endpoints\n\n- `GET /chat/messages`, handler `api/chat.go:49-60`\n- `GET /providers`, handler `api/vm.go:10-11`\n\n## Root cause\n\n`handleChatMessages` calls `h.node.GetChatMessages(account, since)` and\nwrites the result straight to the response. It reads a `since` filter from\nthe query string and nothing else. There is no `limit` or `offset`\nparameter. The store behind it holds up to 1,000 messages per account\n(`chat.NewChatStore(1000)`, `node/node.go:314`) and each message can be up\nto 8,192 bytes (`MaxMessageBytes`, `chat/envelope.go:15`).\n\n`handleGetProviders` calls `h.node.GetProviders()` and writes the result\nstraight to the response. `GetProviders` (`node/node.go:1071-1099`) ranges\nthe entire `providerAds` map, which has no cap and is never pruned. It also\nscans the full lease list once per advertisement, so the work grows with\nboth collections.\n\nNo layer in between caps the response. `writeJSON`\n(`api/handler.go:402-406`) encodes whatever it is given. The HTTP server\nwrite timeout is 60 seconds (`cmd/xe/main.go:1458`), far above the observed\nhandler times. Both endpoints are GET requests on the read rate bucket:\n200 requests per second sustained, burst 1,000 per IP\n(`api/handler.go:296,314-322`).\n\n## Measured evidence\n\nMeasured locally against the real handler code with the Go test harness,\nusing a filled `chat.ChatStore` and a built provider list of the stated\nsize. The ownership proof for `/chat/messages` was a real one: a challenge\nissued by the handler itself, signed with an ed25519 keypair that derives\nthe account.\n\nChat, 1,000 messages of 8,192 bytes each:\n\n- Full fetch: HTTP 200, 1,000 envelopes, 8,574,002 bytes, handler time\n  60 to 215 ms across runs.\n- With `?limit=10`: HTTP 200, 1,000 envelopes, 8,574,002 bytes. The\n  parameter is ignored; the response is byte-identical.\n- With `?since=` set near the newest timestamp: 1 envelope. The `since`\n  filter works, and it is the only filter. It does not bound the count:\n  1,000 messages inside one `since` window still return all 1,000.\n\nProviders, one entry about 263 to 271 bytes of JSON:\n\n- 1 entry: 273 bytes.\n- 1,000 entries: 271,002 bytes, handler time under 2.2 ms.\n- 10,000 entries: 2,710,002 bytes, handler time under 15 ms.\n- With `?limit=10`: 1,000 entries, 271,002 bytes. The parameter is\n  ignored.\n\nThe per-entry figure depends on address length. The test used 72-character\naccount strings while real addresses are 64 hex characters, so a real\n10,000-entry response is about 2.63 MB rather than 2.71 MB.\n\n## Impact\n\n`GET /chat/messages` needs an ownership proof, so an attacker can only\ninflate their own account: send 1,000 messages to themselves (each message\nneeds a proof of work, roughly 8 minutes of CPU for 1,000 messages at the\ndefault difficulty on a 4-vCPU machine) and then request the 8.5 MB\nresponse repeatedly. That is a bandwidth and CPU cost on the node operator,\nnot on another user. No funds move and no other account data leaks.\n\n`GET /providers` needs no authentication at all. On its own the response\nis small on a quiet network, so the standalone impact is low. The response\ngrows with the advertisement map, and that map grows without cap through\nunauthenticated sybil advertisements (`handleMarketplace`, case\n\"advertisement\", `node/node.go:1399`), so this endpoint is the read side\nof an unbounded collection. The advertisement growth itself is a separate\nmatter already reported under the freshness issue (#18); this report is\nabout the missing pagination on the read side.\n\nSeverity: Low. No funds at risk, no cross-account data exposure, no\npermanent state change. The failure clears as soon as requests stop.\n\n## Related issues\n\nThis is the same pattern as #70 (`GET /accounts`), #215\n(`GET /frontiers`), and #78 (`GET /pending`, `GET /accounts`), on\nendpoints those reports do not cover. Each endpoint is a separate\nlocation with a separate fix, so this is filed as a distinct report for\nthese two endpoints.\n\n## Reproduction\n\nNo live node is needed. The read side can be reproduced in a test in\npackage `api`:\n\n1. Implement the `nodeBackend` interface with a stub. Point\n   `GetChatMessages` at a real `chat.ChatStore` and `GetProviders` at a\n   slice of `node.ProviderInfo` of the size under test.\n2. Fill the store with 1,000 envelopes of 8,192-byte messages for one\n   account.\n3. Build a handler with that backend. Issue a challenge through the\n   handler, sign it with a keypair that derives the account, and call\n   `handleChatMessages` with the proof query parameters through\n   `httptest`. Read the response body length.\n4. Call `handleGetProviders` through `httptest` with provider slices of\n   1,000 and 10,000 entries. Read the response body length.\n5. Repeat both calls with `?limit=10` and confirm the response is\n   unchanged.\n\nThe arithmetic alone also shows the chat bound: 1,000 messages times\n8,192 bytes is 8,192,000 bytes of message content, plus JSON framing,\nwhich matches the measured 8,574,002 bytes.\n\n## Suggested fix\n\nApply the existing pagination helpers to both handlers: read\n`parsePagination(r)` and return `paginateSlice(...)`, the same as\n`handleDirectoryList` does. For `GET /providers`, consider also bounding\nthe work inside `GetProviders` when the lease list is large, since the\nper-advertisement lease scan runs before pagination.\n\n## Method limits\n\n- The measurement ran the real handler in-process through `httptest`,\n  not over a socket to a running node. Response bytes are identical to\n  what `writeJSON` sends; handler times are in-process CPU cost, not\n  wire latency.\n- The chat store was filled directly through `ChatStore.Store`, not\n  through `POST /chat/send` or gossip delivery, which verify signatures\n  and proof of work. The read side under test is identical either way,\n  since the handler reads the same store, but the end-to-end fill cost\n  was not re-executed here.\n- The provider list was built directly at the stated sizes rather than\n  grown through gossip advertisements. The serialization measured is\n  exactly what `GetProviders` returns after ranging the map. The\n  per-advertisement lease scan cost was read from code, not measured.\n- The per-IP bandwidth figures implied by the read bucket (200 requests\n  per second times the response size) are arithmetic, not wire\n  measurements.","patch_refs":[{"id":313,"repo":"xeprotocol/xe","kind":"pr","ref":"286","title":"fix(cli,client,chat,node,api): harden CLI flag parsing, provider errors, chat PoW bounds, marketplace rate-limit, and API pagination","url":"https://github.com/xeprotocol/xe/pull/286","note":"","state":"open","author":"Khanhtnq","added_by":"desk","created_at":"2026-11-06T12:42:47.419656+00:00"}],"thread":[{"id":1543,"source":"github","source_ref":"6730868373","author":"rusdiwireng","team":false,"body":"Hi, thanks for triaging. I am asking for a re-check of the duplicate closure on this issue. The nearest public reports in the pagination family describe different defects on different endpoints, and this report's fix is a separate change.\n\nConcrete differences from #70, #78, and #215:\n\n1. **Different endpoints and code paths.** #275 is about `GET /chat/messages` (`api/chat.go:49-60`) and `GET /providers` (`api/vm.go:10-11`). #70 and #78 are about `GET /accounts` and `GET /pending`; #215 is about `GET /frontiers`. No public report before #275 mentions `/chat/messages` or `/providers` pagination at all.\n2. **Different defect — in #78's case, the opposite defect.** #70 and #215: pagination exists but is applied after full-lattice work, so a `limit=1` request still costs the full scan. #78: pagination exists (default 100, max 1000) but is undeclared, so responses are silently truncated. #275: there is no pagination at all — both handlers write the entire collection straight to the response (`/chat/messages` measured at 8,574,002 bytes for maximum-size messages; `/providers` ranges the whole uncapped `providerAds` map). Unbounded response is not the same defect as silent truncation, and neither is the same as late pagination.\n3. **Different fix.** #70/#78 were fixed by PR #124 (accounts/pending only); #215 by PR #216 (frontiers only). #275 is fixed by a separate change, PR #286 §5, which wires `parsePagination`/`paginateSlice` into `handleChatMessages` and `handleGetProviders` — a different hunk in different files, listed by the fix author as \"Fixes #275\".\n\nI understand these reports sit in the same family (list endpoints and pagination), and if this was closed as a duplicate of a desk entry that already covered `/chat/messages` and `/providers` specifically, please point me to it and I will withdraw this appeal. If it was closed as a duplicate of #70/#78/#215, I ask that it be reconsidered on the three points above: different endpoints, a defect that runs in the opposite direction from #78, and a separate fix.\n\nThank you for re-checking.","created_at":"2026-11-09T02:34:43+00:00"},{"id":3789,"source":"github","source_ref":"6885487814","author":"XE desk","team":true,"body":"Thanks. This is the same finding as https://bounty.xe.network/XE-0610, 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-0704 and says what differs; it is read like any other.","created_at":"2026-11-14T22:53:49+00:00"}]}