rest: fix getutxos POST body decoding

bitcoin/bitcoin: PR #36385

5 suggestions

Optional improvements

Link

[suggestion] · Malformed-hex tests do not protect TryParseHex

The malformed-hex tests would still pass if TryParseHex were replaced with ParseHex, because the empty-outpoint guard would supply the expected HTTP 400.

Location: test/functional/interface_rest.py:184 (head).

Details and suggested fix

These requests use RetType.OBJ, so the helper checks the status but leaves the response body unread. Reverting to ParseHex would turn either malformed input into an empty decoded body, skip deserialization, and return Error: empty request instead. With valid URI outpoints, the same reversion would also skip the combination guard and return HTTP 200 with the malformed body ignored. Add a hex POST using the existing valid URI outpoints and either malformed body, and require HTTP 400. That case would distinguish explicit malformed-hex rejection from silently discarding the body.


Link

[suggestion] · POST comparisons do not exercise checkmempool selection

The binary and hex POST comparisons query confirmed state, so consuming but overriding checkmempool would leave them passing; the mempool-sensitive fixture exercises URI inputs only.

Location: test/functional/interface_rest.py:167 (head).

Details and suggested fix

The successful bodies always begin with 0x01 and query the first transaction after it has been mined. Its unspent output and spent input give identical results through the chain-only and mempool-backed views. Before mining the later transaction, add binary and hex POST bodies with both 0x00 and 0x01, covering its new output and its confirmed, mempool-spent input. Compare each response with the matching GET, with or without /checkmempool. Those outpoints have opposite hit patterns under the two views, so a body decoder that consumes the flag but forces either value would be caught.


Link

[suggestion] · POST body limits lack 15/16-outpoint boundary coverage

The endpoint tests do not distinguish a body-only limit change or removal of LIMITED_VECTOR, because complete successful bodies contain only two outpoints.

Location: src/rest.cpp:1021 (head).

Details and suggested fix

The existing limit tests put their outpoints in the URI. The malformed binary body declares 34 outpoints, but truncation would still produce HTTP 400 with ordinary vector decoding. Add complete binary and hex bodies with exactly 15 outpoints that succeed, preferably compared with the matching URI response, and 16 outpoints that return HTTP 400 with Parse error. Ordinary decoding would reject the complete 16-outpoint body only at the later max outpoints exceeded check, so status alone would not distinguish removal of the bounded decoder. The message assertion would protect the current endpoint wiring, not directly measure allocation or establish an error-text compatibility promise.


Link

[suggestion] · /rest/getutxos POST changes lack a release note

The PR corrects binary and hex POST results and tightens request validation without a release note; no client relying on the old behavior was identified.

Location: src/rest.cpp:1007 (head).

Details and suggested fix

Add a pending release note under “Updated REST APIs” explaining that .bin and .hex POST bodies now deserialize directly, correcting UTXO results that could disagree with equivalent GET requests. Also list the HTTP 400 rejections for trailing decoded bytes, malformed hex, and bodies containing no outpoints. The current REST documentation lists only URI request forms, so it does not communicate these body-parsing changes. The 28.0 release notes provide a precedent for announcing stricter /rest/getutxos validation.


Link

[suggestion] · 52034e3 couples decoding repair to stricter input rules

Separating the decoding fix from the trailing-byte and malformed-hex rejections would let reviewers and backports select the correctness repair independently.

Location: src/rest.cpp:1006 at 52034e3cfd5d (commit) (commit).

Details and suggested fix

The direct parent, 0cd203bce24a9d62fef96a6d196870933778140c, records the GET/POST mismatch and the two acceptance behaviors as separate TODOs. Split 52034e3cfd5dfca5efc43162f0f7610b3797669a into three steps: direct DataStream construction with MakeByteSpan, the span.h include, and the equality assertions; then the oss.size() rejection with its HTTP 400 expectations; then TryParseHex with its HTTP 400 expectations. The decoding-only step can retain the parent's acceptance expectations for trailing bytes and malformed hex.

Keep 37d35213634d27c3ef4fc528f78755d6a61e1a6e (bounded vector decoding), 7e5ec57d0410b6187a8dfe15109fc82065b06044 (SpanReader), and 37cc0acf65a2bbd2ed5704ad6d0bc3bc1d46295a (empty-outpoint rejection) afterward in their current order. This preserves the final tree while making the decoding repair independently reviewable and backportable.


Coverage details

Background

Ralph's summary of historical context for the behaviour affected by this change. The historical record reviewed here is incomplete.

Documented decisions

There is a historical precedent for tightening getutxos acceptance rather than preserving every previously accepted malformed input: PR #30482 explicitly characterized acceptance of truncated URI txids as brittle and proposed rejecting truncated or overlarge inputs.

This concerns URI txids, not binary or hex bodies, so it does not settle the present compatibility question. It does show that permissive acceptance in this endpoint has previously been treated as behavior to correct, rather than automatically as an intentional API guarantee.

Source 1