<!-- XE-12545 · [Minor] desk: _unwrap raises raw JSONDecodeError on 200 + garbage JSON instead of the documented XeError (XE-1774 residual) · testnet -->
*Markdown view of <https://bounty.xe.network/XE-12545>. The page is the record; this is the same page for reading.*

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

Verdict
:   Duplicate

Tier
:   —

Claimed
:   Minor

Area
:   Other

Duplicate of
:   —

Tracked
:   —

Updated
:   2026-11-20 19:45 UTC

Told
:   2026-11-20 19:45 UTC

### Patches

None linked.

### History

- [626274](https://bounty.xe.network/log/626274) 2026-11-20 19:45 UTC proposal.adopted
- [626273](https://bounty.xe.network/log/626273) 2026-11-20 19:45 UTC reply.sent
- [626272](https://bounty.xe.network/log/626272) 2026-11-20 19:45 UTC ticket.status new → closed
- [622261](https://bounty.xe.network/log/622261) 2026-11-20 19:44 UTC proposal.adopted
- [622260](https://bounty.xe.network/log/622260) 2026-11-20 19:44 UTC ticket.facts area
- [622257](https://bounty.xe.network/log/622257) 2026-11-20 19:44 UTC proposal.adopted
- [622256](https://bounty.xe.network/log/622256) 2026-11-20 19:44 UTC ticket.facts
- [622254](https://bounty.xe.network/log/622254) 2026-11-20 19:44 UTC proposal.adopted
- [622253](https://bounty.xe.network/log/622253) 2026-11-20 19:44 UTC ticket.facts
- [612567](https://bounty.xe.network/log/612567) 2026-11-20 15:26 UTC note.added
- [612566](https://bounty.xe.network/log/612566) 2026-11-20 15:26 UTC proposal.created
- [612565](https://bounty.xe.network/log/612565) 2026-11-20 15:26 UTC proposal.created

[Full history](https://bounty.xe.network/log?ref=XE-12545) · [JSON](https://bounty.xe.network/v1/tickets/XE-12545) · [markdown](https://bounty.xe.network/XE-12545.md)

### 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 Denne**team2026-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.
