rpc: handle malformed jsonrpc 2.0 requests correctly

bitcoin/bitcoin: PR #36758

3 suggestions

Earlier concerns neither republished nor resolved: 1 suggestion. See the Run archive for their assessments.

Optional improvements

Link

[suggestion] · The HTTP-status row omits the -rpcwhitelist batch exception

The narrowed HTTP-error exception omits pre-existing behavior: an authenticated user with an -rpcwhitelist entry can still receive one legacy HTTP 400/500 error for a valid-JSON batch containing a malformed element.

Location: doc/JSON-RPC-interface.md:92 (head).

Details and suggested fix

For example, [{"jsonrpc":"2.0","id":1}] reaches the whitelist pre-check before per-element parsing. Reading the missing method with get_str() throws, and the outer catch calls JSONErrorReply() with the unparsed, legacy-versioned top-level jreq. The response is HTTP 500 with one legacy error object, not HTTP 200 with per-element errors. A non-object element takes the same outer path with HTTP 400. Qualify this row to describe the whitelist exception and add a malformed JSON-RPC 2.0 batch case to rpc_whitelist.py so the documented exception remains explicit.


Link

[suggestion] · All-notification batches lose HTTP 204 coverage

The revised no-ID batch expects an error reply for its malformed element, leaving interface_rpc.py without coverage of the batch branch that returns HTTP 204 with no body.

Location: test/functional/interface_rpc.py:158 (head).

Details and suggested fix

Every remaining nonempty batch case expects at least one response. The empty-batch case expects HTTP 200 with [], while singleton notifications exercise a separate return branch. Consequently, changing only the all-notification batch branch to return HTTP 200 with [] would leave these assertions passing. Keep the new malformed-element case and add self.test_batch_request(lambda idx: BatchOptions(version=2, notification=True) if idx < 4 else None). This retains the three structurally valid notifications, including invalidmethod whose execution error must be suppressed, and reaches the helper's existing HTTP 204/no-body assertions.


Link

[suggestion] · JSON-RPC 2.0 response changes lack a release note

Authenticated clients sending malformed JSON-RPC 2.0 requests see changed release-build responses, but the documentation update describes current behavior without announcing the compatibility change in a release note.

Location: doc/JSON-RPC-interface.md:93 (head).

Details and suggested fix

Malformed singleton requests with missing or non-string methods, or malformed params, now receive HTTP 200 rather than 400 in release builds. JSON-RPC 2.0 error replies without a request ID acquire "id": null, and malformed no-ID batch elements now produce replies instead of being suppressed. A batch consisting only of those malformed elements consequently changes from HTTP 204 to HTTP 200 with errors. Add a short RPC entry in doc/release-notes-<PR>.md covering these differences for clients or proxies that depended on the previous responses. Although this is a specification-compliance bug fix, the release-build changes are externally visible; whether they warrant a note remains a maintainer decision.


Coverage details

Earlier concerns

Earlier reports raised these, with the titles and severities shown there. This review neither republished nor resolved them.