{"id":"XE-1857","kind":"bounty","visibility":"public","source":"web","source_repo":"","source_ref":"","source_url":"","reporter_id":451,"title":"`asBigInt` lets plain `Error`s escape the typed client accessors on malformed numeric fields","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:09:24.337202+00:00","updated_at":"2026-11-14T22:57:04.296924+00:00","source_created_at":null,"told_at":"2026-11-10T14:00:35.050672+00:00","status_changed_at":"2026-11-10T14:00:33.337874+00:00","url":"https://bounty.xe.network/XE-1857","body":"## Title\r\n\r\n`asBigInt` lets plain `Error`s escape the typed client accessors on malformed numeric fields\r\n\r\n## Summary\r\n\r\nEvery typed client accessor funnels node-supplied numerics through\r\n`asBigInt` (`src/json.ts`), which throws a bare `Error` (\"`field:\r\nexpected an integer, got …`\") on a non-integer value. That plain\r\n`Error` propagates unchanged out of `balances()`, `pending()`,\r\n`certificate()`, `lease()`, and — by code-reading, same helper —\r\n`toProvider`, `toEpoch`, `timekeepers()`, `requestAttestation()` and\r\n`latestEpoch()`'s index read. The SDK's error taxonomy (`XeError` →\r\n`XeApiError` / `XeTransportError` / `XeUsageError`) is the contract\r\ncallers code against: `isRetryable()` only recognises `XeApiError`\r\nand `XeTransportError`, `Xe.rentLease` and `holdLease`'s retry logic\r\nbranch on `instanceof XeApiError`, and `XeClient.request()` only\r\nretries `isRetryable` errors. A malformed numeric field therefore\r\nproduces an error that is invisible to every one of those handlers —\r\nit is neither retryable-classified nor usage-classified, it is just a\r\nraw `Error` with no status, no retryable flag, and no body.\r\n\r\n## Impact\r\n\r\n- **Typed-error contract broken on the malformed-response path.**\r\nA node (or a proxy/malicious node — the SDK already has to assume\r\nnode responses may be hostile, cf. SDK-2) returning e.g.\r\n`{\"balances\":{\"XE\":\"abc\"}}` makes `balances()` throw a plain\r\n`Error`; the same for a non-integer `pending.Amount`, certificate\r\n`price_multiplier_milli`, or lease `cost`. Callers that catch\r\n`XeError` — as the SDK's own `rentLease`/`waitForLease`/\r\n`holdLease` code does — miss it, and retry logic cannot classify\r\nit.\r\n- **Scope limit (stated plainly).** The failure is fail-closed (the\r\ncall throws; nothing is signed on a garbage value) and the trigger\r\nneeds a malformed response. No funds move and no wrong value is\r\nused.\r\n\r\n## Severity reasoning\r\n\r\n- **Minor, not Low:** the defect is in the error taxonomy itself —\r\nthe same class as DAO-12 (`_unwrap` raises raw `JSONDecodeError`)\r\nand DAO-13 (`Signer.load` lets raw errors escape), both filed as\r\nMinor — and it affects at least four public accessors plus the\r\nshared record mappers. But it is fail-closed and needs malformed\r\ninput.\r\n\r\n## Root cause\r\n\r\n`src/json.ts` `asBigInt` throws a bare `Error` instead of an\r\n`XeError` subclass, and none of its call sites (`toMap` in\r\n`balances()`, `pending()`, `toCertificate`'s `big()`,\r\n`toLeaseRecord`'s `big()`, `toProvider`, `toEpoch`,\r\n`requestAttestation`, `timekeepers`, `latestEpoch`) wraps it.\r\n\r\n## Reproduction\r\n\r\nHarness `/tmp/sdk-r5/verify.mjs` (section F), 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 F-balances-plain-error PLAIN:Error\r\nPASS F-pending-plain-error PLAIN:Error\r\nPASS F-certificate-plain-error PLAIN:Error\r\nPASS F-lease-plain-error PLAIN:Error\r\nPASS F-control-good-balances XE=5\r\n```\r\n\r\nWhat the run shows: a non-integer numeric in each of the four\r\nresponses makes the accessor throw a plain `Error` (not an\r\n`XeError`); well-formed responses still parse normally.\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 `asBigInt`, plain errors escaping, or malformed numeric fields in\r\nthe SDK. Closest reports:\r\n\r\n- **XE-1774 (DAO-12)** — `XeClient._unwrap` raises a raw\r\n`JSONDecodeError` on garbage JSON. Same *class* (raw error escaping\r\na typed taxonomy), different codebase (DAO Python client) and\r\ntrigger (unparsable body vs non-integer field).\r\n- **XE-1779 (DAO-13)** — `Signer.load` lets corrupt-keyfile errors\r\nescape as raw exceptions. Same class, different codebase.\r\n- **XE-0057** — node errors are `{\"error\": string}` but response\r\nschemas are the object `Error` shape. About the node's error\r\n*shape*, not the SDK throwing plain `Error`s on bad numerics.\r\n\r\nNo known report covers this SDK 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- Make `asBigInt` throw `XeApiError` (status 200, non-retryable,\r\nbody attached) or a dedicated `XeError` subclass, so every\r\naccessor's malformed-response failure is classifiable by\r\n`isRetryable` and catchable as `XeError`. Alternatively wrap the\r\ncalls at each accessor — fixing it in `asBigInt` closes the whole\r\nclass at once.\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/json.ts` (`asBigInt`) | `throw new Error(...)` — bare `Error`, no `XeError` |\r\n| `src/client.ts` (`balances`/`toMap`, `pending`, `toCertificate`/`big`, `toLeaseRecord`/`big`, `toProvider`, `toEpoch`, `requestAttestation`, `timekeepers`, `latestEpoch`) | All call sites that let it escape |\r\n| `src/errors.ts` (`isRetryable`) | Only recognises `XeApiError`/`XeTransportError` — a plain `Error` is unclassifiable |\r\n| `/tmp/sdk-r5/verify.mjs` (section F) | Verification harness (ephemeral, see \"Reproduction\") |","patch_refs":[],"thread":[{"id":2131,"source":"desk","source_ref":"reply:1498","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-1857","created_at":"2026-11-10T14:00:19.792775+00:00"}]}