{"id":"XE-1855","kind":"bounty","visibility":"public","source":"web","source_repo":"","source_ref":"","source_url":"","reporter_id":451,"title":"Negative attempt counts make `request()` and `rentLease()` throw `undefined` instead of an error","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-09T08:05:55.924800+00:00","updated_at":"2026-11-14T22:57:04.296924+00:00","source_created_at":null,"told_at":"2026-11-10T14:00:35.067936+00:00","status_changed_at":"2026-11-10T14:00:33.357590+00:00","url":"https://bounty.xe.network/XE-1855","body":"## Title\r\n\r\nNegative attempt counts make `request()` and `rentLease()` throw `undefined` instead of an error\r\n\r\n## Summary\r\n\r\nTwo retry loops share the same shape — `let lastError: unknown` /\r\nloop / `throw lastError` — and neither validates its count. With\r\n`retries: -1`, `XeClient.request()`'s loop body never runs and the\r\nfunction throws the never-assigned `lastError`, i.e. throws\r\n`undefined`. With `attempts: 0`, `Xe.rentLease()` does the same:\r\nthe loop never runs and it throws `undefined`. A caller doing\r\n`catch (err) { err.message }` gets a `TypeError` instead of the\r\nconfiguration error, and `err instanceof Error` is `false` — the\r\noriginal mistake (a negative count) is unrecoverable and\r\nundiagnosable from the thrown value.\r\n\r\n## Impact\r\n\r\n- **Throwing a non-Error.** `throw undefined` breaks every error\r\nhandler downstream: logging, `instanceof` checks, and\r\n`err.message` reads all fail or misreport. The caller cannot tell\r\nwhether the request failed, was never attempted, or was\r\nmisconfigured.\r\n- **Scope limit (stated plainly).** The trigger is caller\r\nmisconfiguration (a negative count), not attacker input, and no\r\nrequest is sent and no funds move. The defect is in the error\r\npath, not in any success path.\r\n\r\n## Severity reasoning\r\n\r\n- **Minor, not Low:** throwing `undefined` is a sharp API-contract\r\nviolation in two public functions, and it actively destroys the\r\ndiagnostic information a caller needs. But the trigger is a\r\ncaller error and nothing is sent or spent.\r\n\r\n## Root cause\r\n\r\n`src/client.ts` `request()`: `for (attempt = 0; attempt <=\r\nthis.#retries; attempt++)` with `#retries = -1` skips the loop and\r\nfalls through to `throw lastError` (still `undefined`).\r\n`src/xe.ts` `rentLease()`: `for (attempt = 1; attempt <= attempts;\r\nattempt++)` with `attempts = 0` (or negative) likewise falls through\r\nto `throw lastError` (still `undefined`). Neither constructor/option\r\nvalidates the count (`retries`/`attempts` accept any number).\r\n\r\n## Reproduction\r\n\r\nHarness `/tmp/sdk-r5/verify.mjs` (section D), mock fetch only. Run\r\nfrom the built SDK:\r\n\r\n```sh\r\ncd ~/workspace/xe-bounty/sdk\r\nnode /tmp/sdk-r5/verify.mjs\r\n```\r\n\r\nObserved output:\r\n\r\n```\r\nPASS D-retries-minus1-throws-undefined thrown=undefined\r\nPASS D-rentLease-attempts0-throws-undefined thrown=undefined\r\nPASS D-control-retries0-one-attempt calls=1\r\n```\r\n\r\nWhat the run shows:\r\n\r\n1. `new XeClient({retries: -1}).request('/node')` throws `undefined`\r\nwithout making any fetch call.\r\n2. `xe.rentLease(opts, {attempts: 0})` throws `undefined` without\r\nopening any lease.\r\n3. Control: `retries: 0` makes exactly one attempt — the boundary\r\nbelow which the loop never runs is exactly the unvalidated one.\r\n\r\n## Dedup note\r\n\r\nChecked against the public ticket list (186 public tickets, max\r\nXE-1799, snapshot 2026-11-09 ~14:19 WIB; title sweep). No title match\r\nfor `throw undefined`, `lastError`, attempt counts, or retries.\r\nClosest reports:\r\n\r\n- **XE-0078** — \"`rentLease` skips its cancel on a non-retryable\r\nwait error\". Same function, different defect (cancel path, not\r\nattempt-count validation).\r\n- **XE-0056** — \"a 429 rate limit is classified as non retryable\".\r\nSame retry machinery, different defect (classification, not the\r\nloop bound).\r\n\r\nNo known report covers this defect. Private/sealed tickets are\r\ninvisible, so a sealed duplicate cannot be ruled out.\r\n\r\n## Suggested fix direction\r\n\r\n- Validate the counts at the boundary (`retries >= 0`,\r\n`attempts >= 1`) and throw `XeUsageError` for invalid values; and\r\nnever `throw lastError` without a loop iteration having run (throw\r\na fresh error instead).\r\n\r\n## Payout address\r\n\r\n```\r\n052e33e0ed9c43e2bdf07faff9a90d25642b51d53d96f49f5d45b81f6584b3da\r\n```\r\n\r\n## References (file:line; sdk @ 605c20a)\r\n\r\n| Location | What it shows |\r\n|---|---|\r\n| `src/client.ts` (`request`) | `let lastError: unknown` … `throw lastError` after a loop that may never run |\r\n| `src/xe.ts` (`rentLease`) | Same shape: `let lastError: unknown` … `throw lastError` |\r\n| `/tmp/sdk-r5/verify.mjs` (section D) | Verification harness (ephemeral, see \"Reproduction\") |","patch_refs":[],"thread":[{"id":2132,"source":"desk","source_ref":"reply:1499","author":"Joseph Denne","team":true,"body":"Thank you for this report. We have read it against the code and it is being handled. The assessment and any award follow the fix. https://bounty.xe.network/XE-1855","created_at":"2026-11-10T14:00:19.792775+00:00"}]}