Bounty
XE-12545 · Bounty

[Minor] desk: _unwrap raises raw JSONDecodeError on 200 + garbage JSON instead of the documented XeError (XE-1774 residual)

Closed · duplicate —claimed Minor web filed 2026-11-14 06:27 UTC by xe:342640c4

Report

Summary

The desk client's _unwrap guards the error branch (status ≥ 400) but calls r.json() unguarded on the success branch — a 200 with garbage JSON raises a raw json.JSONDecodeError instead of the documented XeError. The DAO copy wraps it in XeError (the XE-1774 fix, awarded Minor, DAO-only). The same function also accepts NaN/Infinity/NUL-bearing JSON with no _parse refusal, while the DAO _parse refuses all of them. This is the 7th "fix reached one copy only" pair.

Location

  • desk/xe/client.py:49-57 (_unwrap — success branch return r.json() unguarded)
  • dao/xe/client.py (XeError wrap — the XE-1774 fix the desk copy lacks)
  • dao/xe/client.py:138 (_parse — refuses NaN/Infinity/NUL/surrogates; the desk copy has no equivalent)

Description

# desk/xe/client.py:49-57 — _unwrap
@staticmethod
def _unwrap(r: httpx.Response) -> Any:
    if r.status_code >= 400:
        try:
            msg = r.json().get("error", r.text)
        except Exception:
            msg = r.text
        raise XeError(r.status_code, msg)
    if not r.content:
        return None
    return r.json()  # <-- unguarded: garbage JSON on a 200 raises raw JSONDecodeError

The error branch wraps parse failures; the success branch does not. A 200 with a non-JSON body escapes as a raw json.JSONDecodeError, not the XeError the client documents.

PoC (executed, MockTransport): a 200 with body not json{{ → raw json.JSONDecodeError, NOT XeError.

Sub-point (same function, same DAO fix family): the desk client also accepts NaN/NUL-bearing JSON with no refusal — _get("/nan") returned {'x': nan}; a NUL escape returned 'a\x00b'. The DAO _parse refuses NaN/Infinity/NUL/surrogates.

Impact

Error-contract violation: the client's documented error type is XeError, and any caller catching XeError specifically misses this failure mode. The NaN/NUL leg lets malformed values flow into callers unchecked.

Honest framing: in-service masking verified — the desk's only caller, refresh_node (desk/desk/context.py:45), catches broad Exception, so in-service this is only a misleading "node unreachable" log line. The frame is the shared-library residual (the XE-11872 footing), not a live crash.

Reproduction

  1. Mock a 200 response with body not json{{.
  2. Call any desk client method.
  3. Observe a raw json.JSONDecodeError instead of XeError.
  4. (Sub-point) Mock a 200 with body {"x": NaN} — observe {'x': nan} returned, no refusal.

Suggested fix

Wrap the success-branch r.json() in try/except and raise XeError, mirroring the DAO copy; add _parse-style refusal of NaN/Infinity/NUL/surrogates in the same place.

Not a duplicate

q=XE-1774 → 3: XE-1857 (SDK asBigInt), XE-7935 (desk size cap + 3xx), XE-9376 (XeClient constructor InvalidURL) — none is the desk _unwrap. q=_unwrap → 5, q=JSONDecodeError → 3 — none is the desk _unwrap. Near-neighbor XE-4592 (DAO _post_raw leaks non-XeError) is the DAO copy's REQUEST-side encode error (outgoing body UnicodeEncodeError), NOT the desk _unwrap RESPONSE-side parse error — distinct site, error, and copy. Checked 2026-11-14. No public ticket files the desk _unwrap raw JSONDecodeError or its NaN/NUL acceptance.

Thread

Joseph Denneteam2026-11-20 19:45 UTCdesk

Thanks. This is the same finding as an earlier report that is not public, which was filed first; the programme pays the first verifiable submission, so this one closes as a duplicate. If you believe it is a different bug, file a new report that links https://bounty.xe.network/XE-12545 and says what differs; it is read like any other.