Bounty
XE-1855 · Bounty

Negative attempt counts make `request()` and `rentLease()` throw `undefined` instead of an error

Triaging claimed Minor web filed 2026-11-09 08:05 UTC by Darkarmy921

Report

Title

Negative attempt counts make request() and rentLease() throw undefined instead of an error

Summary

Two retry loops share the same shape — let lastError: unknown / loop / throw lastError — and neither validates its count. With retries: -1, XeClient.request()'s loop body never runs and the function throws the never-assigned lastError, i.e. throws undefined. With attempts: 0, Xe.rentLease() does the same: the loop never runs and it throws undefined. A caller doing catch (err) { err.message } gets a TypeError instead of the configuration error, and err instanceof Error is false — the original mistake (a negative count) is unrecoverable and undiagnosable from the thrown value.

Impact

  • Throwing a non-Error. throw undefined breaks every error handler downstream: logging, instanceof checks, and err.message reads all fail or misreport. The caller cannot tell whether the request failed, was never attempted, or was misconfigured.
  • Scope limit (stated plainly). The trigger is caller misconfiguration (a negative count), not attacker input, and no request is sent and no funds move. The defect is in the error path, not in any success path.

Severity reasoning

  • Minor, not Low: throwing undefined is a sharp API-contract violation in two public functions, and it actively destroys the diagnostic information a caller needs. But the trigger is a caller error and nothing is sent or spent.

Root cause

src/client.ts request(): for (attempt = 0; attempt <= this.#retries; attempt++) with #retries = -1 skips the loop and falls through to throw lastError (still undefined). src/xe.ts rentLease(): for (attempt = 1; attempt <= attempts; attempt++) with attempts = 0 (or negative) likewise falls through to throw lastError (still undefined). Neither constructor/option validates the count (retries/attempts accept any number).

Reproduction

Harness /tmp/sdk-r5/verify.mjs (section D), mock fetch only. Run from the built SDK:

cd ~/workspace/xe-bounty/sdk
node /tmp/sdk-r5/verify.mjs

Observed output:

PASS D-retries-minus1-throws-undefined thrown=undefined
PASS D-rentLease-attempts0-throws-undefined thrown=undefined
PASS D-control-retries0-one-attempt calls=1

What the run shows:

  1. new XeClient({retries: -1}).request('/node') throws undefined without making any fetch call.
  2. xe.rentLease(opts, {attempts: 0}) throws undefined without opening any lease.
  3. Control: retries: 0 makes exactly one attempt — the boundary below which the loop never runs is exactly the unvalidated one.

Dedup note

Checked against the public ticket list (186 public tickets, max XE-1799, snapshot 2026-11-09 ~14:19 WIB; title sweep). No title match for throw undefined, lastError, attempt counts, or retries. Closest reports:

  • XE-0078 — "rentLease skips its cancel on a non-retryable wait error". Same function, different defect (cancel path, not attempt-count validation).
  • XE-0056 — "a 429 rate limit is classified as non retryable". Same retry machinery, different defect (classification, not the loop bound).

No known report covers this defect. Private/sealed tickets are invisible, so a sealed duplicate cannot be ruled out.

Suggested fix direction

  • Validate the counts at the boundary (retries >= 0, attempts >= 1) and throw XeUsageError for invalid values; and never throw lastError without a loop iteration having run (throw a fresh error instead).

Payout address

052e33e0ed9c43e2bdf07faff9a90d25642b51d53d96f49f5d45b81f6584b3da

References (file:line; sdk @ 605c20a)

Location What it shows
src/client.ts (request) let lastError: unknown … throw lastError after a loop that may never run
src/xe.ts (rentLease) Same shape: let lastError: unknown … throw lastError
/tmp/sdk-r5/verify.mjs (section D) Verification harness (ephemeral, see "Reproduction")

Thread

Joseph Denneteam2026-11-10 14:00 UTCdesk

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