rpc: handle malformed jsonrpc 2.0 requests correctly #36758

Manually merged
pinheadmz merged 3 commits from jsonrpc-assume-2.0 into master 2026-12-02 22:42:49 +00:00 AGit
pinheadmz commented 2026-11-04 15:20:30 +00:00 (Migrated from github.com)

While reviewing #36642 I found something else we missed in JSON-RPC 2.0:

If we receive a malformed request we would assume that we couldn't parse it's jsonrpc version and send an HTTP error. This is how the legacy jsonrpc server worked (despite that behavior not ever being part of any ratified jsonrpc spec) and we maintain it as Bitcoin "legacy" jsonrpc protocol. However it's possible to form a request that does properly indicate jsonrpc 2.0 but is still malformed. In that case, we should not send an HTTP error: the correct protocol is to respond with HTTP 200 OK and include the jsonrpc error message in the response.

The solution is to check if we know the request's jsonrpc version before responding with an error.

We already correctly handle such malformed requests in batches and this is already tested in test_batch_requests() in interface_rpc.py

On master, the functional test in this PR actually crashes the node because the assumption is codified. Note that this crash requires:

  1. RPC Authentication
  2. A debug build

So this is not an urgent security fix, but a bug that might disrupt testing.

node0 stderr httprpc.cpp:46
    UniValue JSONErrorReply(UniValue, const JSONRPCRequest &, HTTPStatusCode &):
        'jreq.m_json_version != JSONRPCVersion::V2' check failed.

In release builds the node doesn't crash, but it returns HTTP 400 with a JSON-RPC 2.0 error body instead of HTTP 200.

While reviewing #36642 I found something else we missed in JSON-RPC 2.0: If we receive a malformed request we would assume that we couldn't parse it's jsonrpc version and send an HTTP error. This is how the legacy jsonrpc server worked (despite that behavior not ever being part of any ratified jsonrpc spec) and we maintain it as Bitcoin "legacy" jsonrpc protocol. However it's possible to form a request that does properly indicate jsonrpc 2.0 but is still malformed. In that case, we should not send an HTTP error: the correct protocol is to respond with `HTTP 200 OK` and include the jsonrpc error message in the response. The solution is to check if we know the request's jsonrpc version before responding with an error. We already correctly handle such malformed requests in batches and this is already tested in `test_batch_requests()` in `interface_rpc.py` On master, the functional test in this PR actually crashes the node because the assumption is codified. Note that this crash requires: 1. RPC Authentication 2. A debug build So this is not an urgent security fix, but a bug that might disrupt testing. ``` node0 stderr httprpc.cpp:46 UniValue JSONErrorReply(UniValue, const JSONRPCRequest &, HTTPStatusCode &): 'jreq.m_json_version != JSONRPCVersion::V2' check failed. ``` In release builds the node doesn't crash, but it returns HTTP 400 with a JSON-RPC 2.0 error body instead of HTTP 200.
First-time contributor

Earlier concerns remain unresolved; see the Run archive linked from the Review report.

🔵 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).

🔵 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).

🔵 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).

Review coverage was incomplete.


Reviewed: 7611c965535c · Review report · Previous reports

permalink

<!-- forgejo-review-bot:bitcoin/bitcoin --> <!-- ralph-engine:current:2b20819f882b885f79f242c01722f54f2a55e27dcfa7d5e13701b4a0b5214248:c39fdacfa3b84799844a5e841c04997e3cd1142653dfad8e36dbb07c4b1e684b --> <!-- ralph-base:e211dd0186e9646167d063a16f0da88e5f72e05f --> <!-- ralph-head:7611c965535c41dfd09085bf1c571ef778b913e0 --> <!-- ralph-case:2b72498a01e8b11efd40d815d721ba6f0024ca0e26d4ac3d9c039837d9fd9469 --> Earlier concerns remain unresolved; see the Run archive linked from the Review report. **🔵 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`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/7611c965535c41dfd09085bf1c571ef778b913e0/doc/JSON-RPC-interface.md#L92>) (head). **🔵 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`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/7611c965535c41dfd09085bf1c571ef778b913e0/test/functional/interface_rpc.py#L158>) (head). **🔵 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`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/7611c965535c41dfd09085bf1c571ef778b913e0/doc/JSON-RPC-interface.md#L93>) (head). Review coverage was incomplete. <!-- Review tier: sensitive --> --- Reviewed: [`7611c965535c`](<https://git.fish.foo/bitcoin/bitcoin/commit/7611c965535c41dfd09085bf1c571ef778b913e0>) · [Review report](<https://review.fish.foo/report/36758-7611c965535c41dfd09085bf1c571ef778b913e0-2767-6.html>) · [Previous reports](<https://review.fish.foo/traces/36758/>) [permalink](<https://review.fish.foo/report/36758-7611c965535c41dfd09085bf1c571ef778b913e0-2767-6.html>)
ryanofsky (Migrated from github.com) approved these changes 2026-11-04 20:36:21 +00:00
ryanofsky (Migrated from github.com) left a comment

Code review ACK 02380237dd. Thanks for finding and fixing this!

It makes sense to merge this before #36753, which moves the -rpcwhitelistdefault check after parsing, so more users can reach this code. I'll rebase that PR on this one.

The suggestions below are all optional. The main one is to fix this in JSONErrorReply() instead of adding another try/catch, so it covers every error thrown after the version is known, and #36753 could use it as well.

Code review ACK 02380237ddd2ed6878d7a3b0ae2807cfcf2cd9ff. Thanks for finding and fixing this! It makes sense to merge this before #36753, which moves the `-rpcwhitelistdefault` check after parsing, so more users can reach this code. I'll rebase that PR on this one. The suggestions below are all optional. The main one is to fix this in `JSONErrorReply()` instead of adding another try/catch, so it covers every error thrown after the version is known, and #36753 could use it as well.
Lines 127-139
ryanofsky (Migrated from github.com) commented 2026-11-04 20:02:54 +00:00

In commit "rpc: handle malformed jsonrpc 2.0 requests correctly" (02380237dd)

Instead of adding a third place that converts a caught error into a reply (with the batch loop and the outer catch), it could be simpler to make JSONErrorReply() do the right thing for 2.0 requests, replacing the Assume with the behavior it asserts. Then this parse() call can stay as it was, and any error thrown after the version is known gets the 2.0 treatment, not just parse errors. Suggested diff from master:

--- a/src/httprpc.cpp
+++ b/src/httprpc.cpp
@@ -40,10 +40,17 @@ static bool g_rpc_whitelist_default = false;

 static UniValue JSONErrorReply(UniValue objError, const JSONRPCRequest& jreq, HTTPStatusCode& nStatus)
 {
-    // HTTP errors should never be returned if JSON-RPC v2 was requested. This
-    // function should only be called when a v1 request fails or when a request
-    // cannot be parsed, so the version is unknown.
-    Assume(jreq.m_json_version != JSONRPCVersion::V2);
+    // A request known to be JSON-RPC 2.0 gets the error in the reply with HTTP
+    // success, or no reply if it is a notification. HTTP error statuses are
+    // only returned for 1.x requests and requests whose version is unknown.
+    if (jreq.m_json_version == JSONRPCVersion::V2) {
+        if (jreq.IsNotification()) {
+            nStatus = HTTP_NO_CONTENT;
+            return {};
+        }
+        nStatus = HTTP_OK;
+        return JSONRPCReplyObj(NullUniValue, std::move(objError), jreq.id, jreq.m_json_version);
+    }

     // Send error reply from json-rpc error object
     nStatus = HTTP_INTERNAL_SERVER_ERROR;

This would also help #36753, which currently builds the 2.0 reply for a whitelist denial itself and could just throw the error for both versions.

I tested this diff together with the PR's test changes: interface_rpc.py, including the new tests, and rpc_whitelist.py pass in a debug build.

In commit "rpc: handle malformed jsonrpc 2.0 requests correctly" (02380237ddd2ed6878d7a3b0ae2807cfcf2cd9ff) Instead of adding a third place that converts a caught error into a reply (with the [batch loop](https://github.com/bitcoin/bitcoin/blob/02380237ddd2ed6878d7a3b0ae2807cfcf2cd9ff/src/httprpc.cpp#L172-L179) and the outer catch), it could be simpler to make [`JSONErrorReply()`](https://github.com/bitcoin/bitcoin/blob/02380237ddd2ed6878d7a3b0ae2807cfcf2cd9ff/src/httprpc.cpp#L41-L46) do the right thing for 2.0 requests, replacing the `Assume` with the behavior it asserts. Then this `parse()` call can stay as it was, and any error thrown after the version is known gets the 2.0 treatment, not just parse errors. Suggested diff from master: ```diff --- a/src/httprpc.cpp +++ b/src/httprpc.cpp @@ -40,10 +40,17 @@ static bool g_rpc_whitelist_default = false; static UniValue JSONErrorReply(UniValue objError, const JSONRPCRequest& jreq, HTTPStatusCode& nStatus) { - // HTTP errors should never be returned if JSON-RPC v2 was requested. This - // function should only be called when a v1 request fails or when a request - // cannot be parsed, so the version is unknown. - Assume(jreq.m_json_version != JSONRPCVersion::V2); + // A request known to be JSON-RPC 2.0 gets the error in the reply with HTTP + // success, or no reply if it is a notification. HTTP error statuses are + // only returned for 1.x requests and requests whose version is unknown. + if (jreq.m_json_version == JSONRPCVersion::V2) { + if (jreq.IsNotification()) { + nStatus = HTTP_NO_CONTENT; + return {}; + } + nStatus = HTTP_OK; + return JSONRPCReplyObj(NullUniValue, std::move(objError), jreq.id, jreq.m_json_version); + } // Send error reply from json-rpc error object nStatus = HTTP_INTERNAL_SERVER_ERROR; ``` This would also help #36753, which currently builds the 2.0 reply for a whitelist denial itself and could just throw the error for both versions. I tested this diff together with the PR's test changes: `interface_rpc.py`, including the new tests, and `rpc_whitelist.py` pass in a debug build.
ryanofsky (Migrated from github.com) commented 2026-11-04 20:02:56 +00:00

In commit "rpc: handle malformed jsonrpc 2.0 requests correctly" (02380237dd)

nit: The JSON-RPC 1.1 vs 2.0 table says 2.0 requests get HTTP 200 "unless there is an actual HTTP server error (request parsing error, endpoint not found, etc)", which could be read as covering the malformed requests tested here. Probably makes sense to update that documentation to say "request body is not valid JSON" instead, to match the behavior after this PR.

In commit "rpc: handle malformed jsonrpc 2.0 requests correctly" (02380237ddd2ed6878d7a3b0ae2807cfcf2cd9ff) nit: The [JSON-RPC 1.1 vs 2.0 table](https://github.com/bitcoin/bitcoin/blob/6355c9f8cf64b8c41a85ead6ca20fb2e88bd4ecf/doc/JSON-RPC-interface.md?plain=1#L92) says 2.0 requests get HTTP 200 "unless there is an actual HTTP server error (request parsing error, endpoint not found, etc)", which could be read as covering the malformed requests tested here. Probably makes sense to update that documentation to say "request body is not valid JSON" instead, to match the behavior after this PR.
ryanofsky (Migrated from github.com) commented 2026-11-04 20:13:19 +00:00

In commit "rpc: handle malformed jsonrpc 2.0 requests correctly" (02380237dd)

Since this commit only adds test cases, it's hard to tell from the diff what behavior it changes. Could the commit message say what these requests did before? The PR description explains it, but the commit only has a subject line. Something like:

A JSON-RPC 2.0 request that fails to parse after its "jsonrpc": "2.0" field
has been read, for example one with a missing or non-string method or
invalid params, reached the Assume in JSONErrorReply(). Debug builds
aborted, and release builds returned HTTP 400 with a 2.0 error body.

Return these errors like any other 2.0 error instead: HTTP 200 with the
error in the reply, or HTTP 204 and no reply for a request without an id.

The test comments could explain more too. The notification case confused me most: it wasn't clear why {"jsonrpc": "2.0"} fails to parse (it has no method), or how this differs from the invalid-notification case just above it, which parses fine and fails when the method runs. Also, since this case doesn't follow the JSON-RPC 2.0 spec (see the separate comment about it), the test should say so, so the behavior isn't mistaken for what the spec requires. Maybe:

--- a/test/functional/interface_rpc.py
+++ b/test/functional/interface_rpc.py
@@ -205,7 +205,8 @@ class RPCInterfaceTest(BitcoinTestFramework):
         response, status = send_json_rpc(self.nodes[0], {"jsonrpc": "3.0", "method": "getblockcount"})
         assert_equal(response, {"result": None, "error": {"code": RPC_INVALID_REQUEST, "message": "JSON-RPC version not supported"}})
         assert_equal(status, 400)
-        # invalid requests that are known to be 2.0 get RPC errors but not HTTP errors
+        # Malformed requests that are known to be JSON-RPC 2.0, because they
+        # have "jsonrpc": "2.0", get RPC errors with HTTP 200, not HTTP errors.
         for request, message in [
             ({}, "Missing method"),
             ({"method": 1}, "Method must be a string"),
@@ -233,7 +234,11 @@ class RPCInterfaceTest(BitcoinTestFramework):
         expect_http_rpc_status(204, None, self.nodes[0], "generatetoaddress", [1, "invalid_address"], 2, True)
         # Sanity check: command was not executed
         assert_equal(block_count + 1, self.nodes[0].getblockcount())
-        # No error response for notifications that fail to parse either
+        # No response either for a request without an id that fails to parse,
+        # here because it has no method, so the error happens before any method
+        # runs. This does not follow the JSON-RPC 2.0 spec, which treats an
+        # invalid request as not being a notification and replies with an error
+        # and "id": null.
         response, status = send_json_rpc(self.nodes[0], {"jsonrpc": "2.0"})
         assert_equal(response, None)
         assert_equal(status, 204)
In commit "rpc: handle malformed jsonrpc 2.0 requests correctly" (02380237ddd2ed6878d7a3b0ae2807cfcf2cd9ff) Since this commit only adds test cases, it's hard to tell from the diff what behavior it changes. Could the commit message say what these requests did before? The PR description explains it, but the commit only has a subject line. Something like: ``` A JSON-RPC 2.0 request that fails to parse after its "jsonrpc": "2.0" field has been read, for example one with a missing or non-string method or invalid params, reached the Assume in JSONErrorReply(). Debug builds aborted, and release builds returned HTTP 400 with a 2.0 error body. Return these errors like any other 2.0 error instead: HTTP 200 with the error in the reply, or HTTP 204 and no reply for a request without an id. ``` The test comments could explain more too. The [notification case](https://github.com/bitcoin/bitcoin/blob/02380237ddd2ed6878d7a3b0ae2807cfcf2cd9ff/test/functional/interface_rpc.py#L236-L239) confused me most: it wasn't clear why `{"jsonrpc": "2.0"}` fails to parse (it has no `method`), or how this differs from the invalid-notification case just above it, which parses fine and fails when the method runs. Also, since this case doesn't follow the JSON-RPC 2.0 spec (see the [separate comment about it](https://github.com/bitcoin/bitcoin/pull/36758#discussion_r4472663654)), the test should say so, so the behavior isn't mistaken for what the spec requires. Maybe: ```diff --- a/test/functional/interface_rpc.py +++ b/test/functional/interface_rpc.py @@ -205,7 +205,8 @@ class RPCInterfaceTest(BitcoinTestFramework): response, status = send_json_rpc(self.nodes[0], {"jsonrpc": "3.0", "method": "getblockcount"}) assert_equal(response, {"result": None, "error": {"code": RPC_INVALID_REQUEST, "message": "JSON-RPC version not supported"}}) assert_equal(status, 400) - # invalid requests that are known to be 2.0 get RPC errors but not HTTP errors + # Malformed requests that are known to be JSON-RPC 2.0, because they + # have "jsonrpc": "2.0", get RPC errors with HTTP 200, not HTTP errors. for request, message in [ ({}, "Missing method"), ({"method": 1}, "Method must be a string"), @@ -233,7 +234,11 @@ class RPCInterfaceTest(BitcoinTestFramework): expect_http_rpc_status(204, None, self.nodes[0], "generatetoaddress", [1, "invalid_address"], 2, True) # Sanity check: command was not executed assert_equal(block_count + 1, self.nodes[0].getblockcount()) - # No error response for notifications that fail to parse either + # No response either for a request without an id that fails to parse, + # here because it has no method, so the error happens before any method + # runs. This does not follow the JSON-RPC 2.0 spec, which treats an + # invalid request as not being a notification and replies with an error + # and "id": null. response, status = send_json_rpc(self.nodes[0], {"jsonrpc": "2.0"}) assert_equal(response, None) assert_equal(status, 204) ```
ryanofsky (Migrated from github.com) commented 2026-11-04 20:02:55 +00:00

In commit "rpc: handle malformed jsonrpc 2.0 requests correctly" (02380237dd)

Not a blocker, but if we want to comply with the spec it seems like this case should get an error reply instead of 204. The JSON-RPC 2.0 spec's examples answer an invalid Request object with no id ({"jsonrpc": "2.0", "method": 1, "params": "bar"}) with an error and "id": null, treating it as an invalid request rather than a notification. If we don't want to comply with the spec, the test comment should be updated to say this is intentional. The test comment suggestion includes that.

Note that compatibility with previous bitcoin core releases shouldn't be a concern in this case since before this PR this request made debug builds abort on the Assume in JSONErrorReply(), and release builds returned HTTP 400 with a "Missing method" error and no id.

In commit "rpc: handle malformed jsonrpc 2.0 requests correctly" (02380237ddd2ed6878d7a3b0ae2807cfcf2cd9ff) Not a blocker, but if we want to comply with the spec it seems like this case should get an error reply instead of 204. The JSON-RPC 2.0 spec's [examples](https://www.jsonrpc.org/specification#examples) answer an invalid Request object with no id (`{"jsonrpc": "2.0", "method": 1, "params": "bar"}`) with an error and `"id": null`, treating it as an invalid request rather than a notification. If we don't want to comply with the spec, the test comment should be updated to say this is intentional. The [test comment suggestion](https://github.com/bitcoin/bitcoin/pull/36758#discussion_r4472774752) includes that. Note that compatibility with previous bitcoin core releases shouldn't be a concern in this case since before this PR this request made debug builds abort on the `Assume` in `JSONErrorReply()`, and release builds returned HTTP 400 with a "Missing method" error and no id.
DrahtBot commented 2026-11-05 19:04:07 +00:00 (Migrated from github.com)

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

External sites

Reviews

See the guideline and AI policy for information on the review process.

Type Reviewers
ACK ryanofsky, hodlinator, janb84
Stale ACK fametrano

If your review is incorrectly listed, please copy-paste <!--meta-tag:bot-skip--> into the comment that the bot should ignore.

Conflicts

No conflicts as of last run.

<!--e57a25ab6845829454e8d69fc972939a--> The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. <!--006a51241073e994b41acfe9ec718e94--> ### External sites * Code coverage & benchmarks: https://corecheck.dev/bitcoin/bitcoin/pulls/36758 * Ralph review <img src=https://review.fish.foo/assets/bitcoin/bitcoin/36758.png alt="Ralph review status"> https://git.fish.foo/bitcoin/bitcoin/pulls/36758#author-ralph <!--021abf342d371248e50ceaed478a90ca--> ### Reviews See [the guideline](https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#code-review) and [AI policy](https://github.com/bitcoin/bitcoin/blob/master/doc/AI_POLICY.md) for information on the review process. | Type | Reviewers | | ---- | --------- | | ACK | [ryanofsky](https://github.com/bitcoin/bitcoin/pull/36758#pullrequestreview-5957374802), [hodlinator](https://github.com/bitcoin/bitcoin/pull/36758#pullrequestreview-5960622782), [janb84](https://github.com/bitcoin/bitcoin/pull/36758#pullrequestreview-6155447419) | | Stale ACK | [fametrano](https://github.com/bitcoin/bitcoin/pull/36758#pullrequestreview-5884508938) | If your review is incorrectly listed, please copy-paste <code>&lt;!--meta-tag:bot-skip--&gt;</code> into the comment that the bot should ignore. <!--174a7506f384e20aa4161008e828411d--> ### Conflicts No conflicts as of last run. <!--5faf32d7da4f0f540f40219e4f7537a3-->
pinheadmz (Migrated from github.com) reviewed 2026-11-05 19:05:11 +00:00
pinheadmz (Migrated from github.com) left a comment

push to 9b21a79587

Address feedback from @ryanofsky

  • move logic into JSONErrorReply
  • add tests first to assert current behavior
  • fix another jsonrpc2.0 bug (responding to malformed notifications with id)
push to 9b21a79587e130f0c51cc0ffc570c1d418258615 Address feedback from @ryanofsky - move logic into JSONErrorReply - add tests first to assert current behavior - fix another jsonrpc2.0 bug (responding to malformed notifications with id)
Lines 127-139
pinheadmz (Migrated from github.com) commented 2026-11-05 15:31:51 +00:00

Much better approach thanks, taking.

Much better approach thanks, taking.
pinheadmz (Migrated from github.com) commented 2026-11-05 15:43:37 +00:00

good catch! adding that change to the table in the doc

good catch! adding that change to the table in the doc
pinheadmz (Migrated from github.com) commented 2026-11-05 17:41:58 +00:00

I'll break out the tests into a test commit that asserts the current behavior, then update the test with the patch. Will clean up the comments too as you suggest.

I'll break out the tests into a test commit that asserts the current behavior, then update the test with the patch. Will clean up the comments too as you suggest.
pinheadmz (Migrated from github.com) commented 2026-11-05 18:33:52 +00:00

Great catch and essentially another jsonrpc 2.0 bug from the spec. the second commit now ensures there is always an id in 2.0 responses. This makes the test simpler too since all the malformed body cases have the same outcome.

Great catch and essentially another jsonrpc 2.0 bug from the spec. the second commit now ensures there is always an `id` in 2.0 responses. This makes the test simpler too since all the malformed body cases have the same outcome.
pinheadmz commented 2026-11-06 15:17:19 +00:00 (Migrated from github.com)

Ralph review mentions -rpcwhitelist which is handled in #36753

Ralph review mentions -rpcwhitelist which is handled in #36753
ryanofsky (Migrated from github.com) reviewed 2026-11-06 22:30:44 +00:00
ryanofsky (Migrated from github.com) left a comment

Thanks for the update! Moving the fix into JSONErrorReply() and the new test commit both look good, and thanks for fixing the missing "id" too.

I'm not re-ACKing yet because single requests and batches now disagree about what a notification is. I'd be happy with either of the options there: fixing batches too, or going back to the previous behavior for single requests and changing the notification rule separately. The other new comments are optional.

Thanks for the update! Moving the fix into `JSONErrorReply()` and the new test commit both look good, and thanks for fixing the missing `"id"` too. I'm not re-ACKing yet because [single requests and batches now disagree about what a notification is](https://github.com/bitcoin/bitcoin/pull/36758#discussion_r4498229560). I'd be happy with either of the options there: fixing batches too, or going back to the previous behavior for single requests and changing the notification rule separately. The other new comments are optional.
ryanofsky (Migrated from github.com) commented 2026-11-06 21:03:36 +00:00

In commit "rpc: handle malformed jsonrpc 2.0 requests correctly" (9b21a79587)

nit: The Notifications row says any request without an "id" field is a notification, but after this PR an invalid one gets an error reply, because the spec only counts valid Request objects as notifications. Maybe:

| Notifications: requests that get no reply | (not supported) | Supported for valid requests that exclude the "id" field. Returns HTTP status `204` "No Content". Invalid requests are not notifications, and get an error reply with `"id": null` even without an "id" field |
In commit "rpc: handle malformed jsonrpc 2.0 requests correctly" (9b21a79587e130f0c51cc0ffc570c1d418258615) nit: The Notifications row says any request without an `"id"` field is a notification, but after this PR an invalid one gets an error reply, because the spec only counts valid Request objects as notifications. Maybe: ```suggestion | Notifications: requests that get no reply | (not supported) | Supported for valid requests that exclude the "id" field. Returns HTTP status `204` "No Content". Invalid requests are not notifications, and get an error reply with `"id": null` even without an "id" field | ```
Lines 48-51
ryanofsky (Migrated from github.com) commented 2026-11-06 22:20:52 +00:00

In commit "rpc: handle malformed jsonrpc 2.0 requests correctly" (9b21a79587)

After this push, single requests and batches use different definitions of a notification. {"jsonrpc": "2.0"} gets an error reply with "id": null, as the spec requires, but [{"jsonrpc": "2.0"}] still gets HTTP 204 and no reply, because the batch loop treats any 2.0 entry without an id as a notification. The spec's batch example answers invalid entries with an error too.

I think it would be better not to leave it half-done: either fix batches too, or go back to the previous behavior for single requests (the previous push, or my earlier suggestion, which kept the 204) and change the notification rule in a separate PR. Fixing it everywhere seems simplest. If parse() decides whether a request is a notification, IsNotification() is only true for valid requests, the batch loop needs no changes, and JSONErrorReply() can return 204 for notifications, so #36753 can throw the same error for both versions. Diff from master:

--- a/src/httprpc.cpp
+++ b/src/httprpc.cpp
@@ -40,10 +40,17 @@ static bool g_rpc_whitelist_default = false;

 static UniValue JSONErrorReply(UniValue objError, const JSONRPCRequest& jreq, HTTPStatusCode& nStatus)
 {
-    // HTTP errors should never be returned if JSON-RPC v2 was requested. This
-    // function should only be called when a v1 request fails or when a request
-    // cannot be parsed, so the version is unknown.
-    Assume(jreq.m_json_version != JSONRPCVersion::V2);
+    // A request known to be JSON-RPC 2.0 gets the error in the reply with HTTP
+    // OK, or no reply if it is a notification. HTTP error statuses are only
+    // returned for 1.x requests and requests whose version is unknown.
+    if (jreq.m_json_version == JSONRPCVersion::V2) {
+        if (jreq.IsNotification()) {
+            nStatus = HTTP_NO_CONTENT;
+            return {};
+        }
+        nStatus = HTTP_OK;
+        return JSONRPCReplyObj(NullUniValue, std::move(objError), jreq.id, jreq.m_json_version);
+    }

     // Send error reply from json-rpc error object
     nStatus = HTTP_INTERNAL_SERVER_ERROR;
--- a/src/rpc/request.cpp
+++ b/src/rpc/request.cpp
@@ -68,7 +68,17 @@ UniValue JSONRPCReplyObj(UniValue result, UniValue error, std::optional<UniValue
         if (jsonrpc_version == JSONRPCVersion::V1_LEGACY) reply.pushKV("result", NullUniValue);
         reply.pushKV("error", std::move(error));
     }
-    if (id.has_value()) reply.pushKV("id", std::move(id.value()));
+    if (id.has_value()) {
+        reply.pushKV("id", std::move(id.value()));
+    } else if (jsonrpc_version == JSONRPCVersion::V2) {
+        // The request had no "id" member. This happens for notifications, and
+        // for invalid requests that left out the id (for example with a missing
+        // or non-string method name). The JSON-RPC 2.0 spec requires every
+        // response to have an "id", set to null when the request's id could not
+        // be determined, so add "id": null. For notifications this is harmless,
+        // because their replies are never sent.
+        reply.pushKV("id", NullUniValue);
+    }
     return reply;
 }

@@ -200,6 +210,13 @@ std::vector<UniValue> JSONRPCProcessBatchReply(const UniValue& in)

 void JSONRPCRequest::parse(const UniValue& valRequest)
 {
+    // Reset fields set by any previous request in the same batch, so if this
+    // request is invalid, its error reply does not use the previous id or
+    // version.
+    id = UniValue::VNULL;
+    m_json_version = JSONRPCVersion::V1_LEGACY;
+    m_notification = false;
+
     // Parse request
     if (!valRequest.isObject())
         throw JSONRPCError(RPC_INVALID_REQUEST, "Invalid Request object");
@@ -213,7 +230,6 @@ void JSONRPCRequest::parse(const UniValue& valRequest)
     }

     // Check for JSON-RPC 2.0 (default 1.1)
-    m_json_version = JSONRPCVersion::V1_LEGACY;
     const UniValue& jsonrpc_version = request.find_value("jsonrpc");
     if (!jsonrpc_version.isNull()) {
         if (!jsonrpc_version.isStr()) {
@@ -254,4 +270,9 @@ void JSONRPCRequest::parse(const UniValue& valRequest)
         params = UniValue(UniValue::VARR);
     else
         throw JSONRPCError(RPC_INVALID_REQUEST, "Params must be an array or object");
+
+    // A notification is a valid JSON-RPC 2.0 request without an "id" member.
+    // Invalid requests are not notifications, and get an error reply even
+    // without an id.
+    m_notification = m_json_version == JSONRPCVersion::V2 && !id.has_value();
 }
--- a/src/rpc/request.h
+++ b/src/rpc/request.h
@@ -63,9 +63,11 @@ public:
     std::string peerAddr;
     std::any context;
     JSONRPCVersion m_json_version = JSONRPCVersion::V1_LEGACY;
+    //! Set by parse() for a valid JSON-RPC 2.0 request without an "id" member.
+    bool m_notification{false};

     void parse(const UniValue& valRequest);
-    [[nodiscard]] bool IsNotification() const { return !id.has_value() && m_json_version == JSONRPCVersion::V2; };
+    [[nodiscard]] bool IsNotification() const { return m_notification; };
 };

 #endif // BITCOIN_RPC_REQUEST_H

The HTTP_NO_CONTENT branch in JSONErrorReply() isn't reachable yet, since valid 2.0 notifications never get there on this branch, but it makes the function correct for every 2.0 request. The JSONRPCReplyObj() comment is the one from the separate comment about it.

Resetting the fields at the start of parse() also fixes a bug that is already on master: a batch entry that isn't an object gets an error reply with the id and version of the entry before it. [{"jsonrpc": "2.0", "method": "getblockcount", "id": 5}, 1] gets "id": 5 for the 1, and [{"jsonrpc": "2.0", "method": "getblockcount"}, 1] gets no reply at all.

I tested this with the PR's tests plus the test changes below, which expect an error for the invalid notification in the batch tests and cover the reset. interface_rpc.py, rpc_whitelist.py, interface_http.py and rpc_users.py pass in a debug build.

Test changes
--- a/test/functional/interface_rpc.py
+++ b/test/functional/interface_rpc.py
@@ -43,12 +43,16 @@ def format_request(options, idx, fields):
     return request


-def format_response(options, idx, fields):
-    if options.version == 2 and options.notification:
+def format_response(options, idx, fields, invalid=False):
+    # Valid 2.0 notifications get no response. Invalid requests are not
+    # notifications, and get an error response with "id": null.
+    if options.version == 2 and options.notification and not invalid:
         return None
     response = {}
     if not options.notification:
         response.update(id=idx)
+    elif options.version == 2:
+        response.update(id=None)
     if options.version == 2:
         response.update(jsonrpc="2.0")
     else:
@@ -130,7 +134,7 @@ class RPCInterfaceTest(BitcoinTestFramework):
             if options is None:
                 continue
             request.append(format_request(options, idx, call))
-            r = format_response(options, idx, result)
+            r = format_response(options, idx, result, invalid="method" not in call)
             if r is not None:
                 response.append(r)

@@ -176,6 +180,17 @@ class RPCInterfaceTest(BitcoinTestFramework):
             request_fields={"jsonrpc": "2.1"},
             response_fields={"result": None, "error": {"code": RPC_INVALID_REQUEST, "message": "JSON-RPC version not supported"}}))

+    def test_batch_invalid_entries(self):
+        self.log.info("Testing that invalid batch entries do not reuse the previous entry's id...")
+        valid = {"jsonrpc": "2.0", "method": "getblockcount"}
+        error = {"result": None, "error": {"code": RPC_INVALID_REQUEST, "message": "Invalid Request object"}, "id": None}
+        response, status = send_json_rpc(self.nodes[0], [{**valid, "id": 5}, 1])
+        assert_equal(response, [{"jsonrpc": "2.0", "result": 0, "id": 5}, error])
+        assert_equal(status, 200)
+        response, status = send_json_rpc(self.nodes[0], [valid, 1])
+        assert_equal(response, [error])
+        assert_equal(status, 200)
+
     def test_http_status_codes(self):
         self.log.info("Testing HTTP status codes for JSON-RPC 1.1 requests...")
         # OK
@@ -269,6 +284,7 @@ class RPCInterfaceTest(BitcoinTestFramework):
     def run_test(self):
         self.test_getrpcinfo()
         self.test_batch_requests()
+        self.test_batch_invalid_entries()
         self.test_http_status_codes()
         self.test_work_queue_exceeded()

In commit "rpc: handle malformed jsonrpc 2.0 requests correctly" (9b21a79587e130f0c51cc0ffc570c1d418258615) After this push, single requests and batches use different definitions of a notification. `{"jsonrpc": "2.0"}` gets an error reply with `"id": null`, as the spec requires, but `[{"jsonrpc": "2.0"}]` still gets HTTP 204 and no reply, because the batch loop treats any 2.0 entry without an id as a notification. The spec's [batch example](https://www.jsonrpc.org/specification#examples) answers invalid entries with an error too. I think it would be better not to leave it half-done: either fix batches too, or go back to the previous behavior for single requests (the previous push, or my earlier suggestion, which kept the 204) and change the notification rule in a separate PR. Fixing it everywhere seems simplest. If `parse()` decides whether a request is a notification, `IsNotification()` is only true for valid requests, the batch loop needs no changes, and `JSONErrorReply()` can return 204 for notifications, so #36753 can throw the same error for both versions. Diff from master: ```diff --- a/src/httprpc.cpp +++ b/src/httprpc.cpp @@ -40,10 +40,17 @@ static bool g_rpc_whitelist_default = false; static UniValue JSONErrorReply(UniValue objError, const JSONRPCRequest& jreq, HTTPStatusCode& nStatus) { - // HTTP errors should never be returned if JSON-RPC v2 was requested. This - // function should only be called when a v1 request fails or when a request - // cannot be parsed, so the version is unknown. - Assume(jreq.m_json_version != JSONRPCVersion::V2); + // A request known to be JSON-RPC 2.0 gets the error in the reply with HTTP + // OK, or no reply if it is a notification. HTTP error statuses are only + // returned for 1.x requests and requests whose version is unknown. + if (jreq.m_json_version == JSONRPCVersion::V2) { + if (jreq.IsNotification()) { + nStatus = HTTP_NO_CONTENT; + return {}; + } + nStatus = HTTP_OK; + return JSONRPCReplyObj(NullUniValue, std::move(objError), jreq.id, jreq.m_json_version); + } // Send error reply from json-rpc error object nStatus = HTTP_INTERNAL_SERVER_ERROR; --- a/src/rpc/request.cpp +++ b/src/rpc/request.cpp @@ -68,7 +68,17 @@ UniValue JSONRPCReplyObj(UniValue result, UniValue error, std::optional<UniValue if (jsonrpc_version == JSONRPCVersion::V1_LEGACY) reply.pushKV("result", NullUniValue); reply.pushKV("error", std::move(error)); } - if (id.has_value()) reply.pushKV("id", std::move(id.value())); + if (id.has_value()) { + reply.pushKV("id", std::move(id.value())); + } else if (jsonrpc_version == JSONRPCVersion::V2) { + // The request had no "id" member. This happens for notifications, and + // for invalid requests that left out the id (for example with a missing + // or non-string method name). The JSON-RPC 2.0 spec requires every + // response to have an "id", set to null when the request's id could not + // be determined, so add "id": null. For notifications this is harmless, + // because their replies are never sent. + reply.pushKV("id", NullUniValue); + } return reply; } @@ -200,6 +210,13 @@ std::vector<UniValue> JSONRPCProcessBatchReply(const UniValue& in) void JSONRPCRequest::parse(const UniValue& valRequest) { + // Reset fields set by any previous request in the same batch, so if this + // request is invalid, its error reply does not use the previous id or + // version. + id = UniValue::VNULL; + m_json_version = JSONRPCVersion::V1_LEGACY; + m_notification = false; + // Parse request if (!valRequest.isObject()) throw JSONRPCError(RPC_INVALID_REQUEST, "Invalid Request object"); @@ -213,7 +230,6 @@ void JSONRPCRequest::parse(const UniValue& valRequest) } // Check for JSON-RPC 2.0 (default 1.1) - m_json_version = JSONRPCVersion::V1_LEGACY; const UniValue& jsonrpc_version = request.find_value("jsonrpc"); if (!jsonrpc_version.isNull()) { if (!jsonrpc_version.isStr()) { @@ -254,4 +270,9 @@ void JSONRPCRequest::parse(const UniValue& valRequest) params = UniValue(UniValue::VARR); else throw JSONRPCError(RPC_INVALID_REQUEST, "Params must be an array or object"); + + // A notification is a valid JSON-RPC 2.0 request without an "id" member. + // Invalid requests are not notifications, and get an error reply even + // without an id. + m_notification = m_json_version == JSONRPCVersion::V2 && !id.has_value(); } --- a/src/rpc/request.h +++ b/src/rpc/request.h @@ -63,9 +63,11 @@ public: std::string peerAddr; std::any context; JSONRPCVersion m_json_version = JSONRPCVersion::V1_LEGACY; + //! Set by parse() for a valid JSON-RPC 2.0 request without an "id" member. + bool m_notification{false}; void parse(const UniValue& valRequest); - [[nodiscard]] bool IsNotification() const { return !id.has_value() && m_json_version == JSONRPCVersion::V2; }; + [[nodiscard]] bool IsNotification() const { return m_notification; }; }; #endif // BITCOIN_RPC_REQUEST_H ``` The `HTTP_NO_CONTENT` branch in `JSONErrorReply()` isn't reachable yet, since valid 2.0 notifications never get there on this branch, but it makes the function correct for every 2.0 request. The `JSONRPCReplyObj()` comment is the one from [the separate comment about it](https://github.com/bitcoin/bitcoin/pull/36758#discussion_r4498229802). Resetting the fields at the start of `parse()` also fixes a bug that is already on master: a batch entry that isn't an object gets an error reply with the id and version of the entry before it. `[{"jsonrpc": "2.0", "method": "getblockcount", "id": 5}, 1]` gets `"id": 5` for the `1`, and `[{"jsonrpc": "2.0", "method": "getblockcount"}, 1]` gets no reply at all. I tested this with the PR's tests plus the test changes below, which expect an error for the invalid notification in the batch tests and cover the reset. `interface_rpc.py`, `rpc_whitelist.py`, `interface_http.py` and `rpc_users.py` pass in a debug build. <details><summary>Test changes</summary> ```diff --- a/test/functional/interface_rpc.py +++ b/test/functional/interface_rpc.py @@ -43,12 +43,16 @@ def format_request(options, idx, fields): return request -def format_response(options, idx, fields): - if options.version == 2 and options.notification: +def format_response(options, idx, fields, invalid=False): + # Valid 2.0 notifications get no response. Invalid requests are not + # notifications, and get an error response with "id": null. + if options.version == 2 and options.notification and not invalid: return None response = {} if not options.notification: response.update(id=idx) + elif options.version == 2: + response.update(id=None) if options.version == 2: response.update(jsonrpc="2.0") else: @@ -130,7 +134,7 @@ class RPCInterfaceTest(BitcoinTestFramework): if options is None: continue request.append(format_request(options, idx, call)) - r = format_response(options, idx, result) + r = format_response(options, idx, result, invalid="method" not in call) if r is not None: response.append(r) @@ -176,6 +180,17 @@ class RPCInterfaceTest(BitcoinTestFramework): request_fields={"jsonrpc": "2.1"}, response_fields={"result": None, "error": {"code": RPC_INVALID_REQUEST, "message": "JSON-RPC version not supported"}})) + def test_batch_invalid_entries(self): + self.log.info("Testing that invalid batch entries do not reuse the previous entry's id...") + valid = {"jsonrpc": "2.0", "method": "getblockcount"} + error = {"result": None, "error": {"code": RPC_INVALID_REQUEST, "message": "Invalid Request object"}, "id": None} + response, status = send_json_rpc(self.nodes[0], [{**valid, "id": 5}, 1]) + assert_equal(response, [{"jsonrpc": "2.0", "result": 0, "id": 5}, error]) + assert_equal(status, 200) + response, status = send_json_rpc(self.nodes[0], [valid, 1]) + assert_equal(response, [error]) + assert_equal(status, 200) + def test_http_status_codes(self): self.log.info("Testing HTTP status codes for JSON-RPC 1.1 requests...") # OK @@ -269,6 +284,7 @@ class RPCInterfaceTest(BitcoinTestFramework): def run_test(self): self.test_getrpcinfo() self.test_batch_requests() + self.test_batch_invalid_entries() self.test_http_status_codes() self.test_work_queue_exceeded() ``` </details>
Lines 75-76
ryanofsky (Migrated from github.com) commented 2026-11-06 22:20:54 +00:00

In commit "rpc: handle malformed jsonrpc 2.0 requests correctly" (9b21a79587)

This comment was hard for me to follow. It doesn't say the branch is for requests that had no "id" member, and it doesn't mention notifications, which also get here. Maybe:

        // The request had no "id" member. This happens for notifications, and
        // for invalid requests that left out the id (for example with a missing
        // or non-string method name). The JSON-RPC 2.0 spec requires every
        // response to have an "id", set to null when the request's id could not
        // be determined, so add "id": null. For notifications this is harmless,
        // because their replies are never sent.
In commit "rpc: handle malformed jsonrpc 2.0 requests correctly" (9b21a79587e130f0c51cc0ffc570c1d418258615) This comment was hard for me to follow. It doesn't say the branch is for requests that had no `"id"` member, and it doesn't mention notifications, which also get here. Maybe: ```suggestion // The request had no "id" member. This happens for notifications, and // for invalid requests that left out the id (for example with a missing // or non-string method name). The JSON-RPC 2.0 spec requires every // response to have an "id", set to null when the request's id could not // be determined, so add "id": null. For notifications this is harmless, // because their replies are never sent. ```
ryanofsky (Migrated from github.com) commented 2026-11-06 21:03:33 +00:00

re: https://github.com/bitcoin/bitcoin/pull/36758#discussion_r4483889331

I'll break out the tests into a test commit that asserts the current behavior

Thanks, this is better than what I suggested. I didn't think a test commit could show the old behavior since debug builds abort, but catching the disconnect and checking stderr for the failed Assume works well, and the test diff in the second commit now shows exactly what changed.

re: https://github.com/bitcoin/bitcoin/pull/36758#discussion_r4483889331 > I'll break out the tests into a test commit that asserts the current behavior Thanks, this is better than what I suggested. I didn't think a test commit could show the old behavior since debug builds abort, but catching the disconnect and checking stderr for the failed `Assume` works well, and the test diff in the second commit now shows exactly what changed.
ryanofsky (Migrated from github.com) commented 2026-11-06 21:03:34 +00:00

re: https://github.com/bitcoin/bitcoin/pull/36758#discussion_r4484432359

the second commit now ensures there is always an id in 2.0 responses

Thanks, this looks right for single requests. Batches still drop these requests, though, see the comment about batches.

re: https://github.com/bitcoin/bitcoin/pull/36758#discussion_r4484432359 > the second commit now ensures there is always an `id` in 2.0 responses Thanks, this looks right for single requests. Batches still drop these requests, though, see [the comment about batches](https://github.com/bitcoin/bitcoin/pull/36758#discussion_r4498229560).
ryanofsky (Migrated from github.com) commented 2026-11-06 21:03:37 +00:00

In commit "test: assert current RPC behavior when handling malformed request body" (bb036a9150)

nit: {**request} makes a copy that isn't needed, since the dict isn't modified, and -32600 could be RPC_INVALID_REQUEST like in the 2.0 loop below:

for request, message in cases:
    response, status = send_json_rpc(self.nodes[0], request)
    assert_equal(response, {"result": None, "error": {"code": RPC_INVALID_REQUEST, "message": message}})
    assert_equal(status, 400)
In commit "test: assert current RPC behavior when handling malformed request body" (bb036a9150ad79d6c6c9cc1ee225842874b6af9f) nit: `{**request}` makes a copy that isn't needed, since the dict isn't modified, and `-32600` could be `RPC_INVALID_REQUEST` like in the 2.0 loop below: ```python for request, message in cases: response, status = send_json_rpc(self.nodes[0], request) assert_equal(response, {"result": None, "error": {"code": RPC_INVALID_REQUEST, "message": message}}) assert_equal(status, 400) ```
pinheadmz (Migrated from github.com) reviewed 2026-11-09 19:55:40 +00:00
pinheadmz (Migrated from github.com) left a comment

push to f27a0bc523:

Clean up a test and some comments to address review by @ryanofsky however the biggest suggestion I did not take yet because we should review #36642 as prerequisitie.

push to f27a0bc5234d5117981d4723af1ec910efbe353c: Clean up a test and some comments to address review by @ryanofsky however the biggest suggestion I did not take yet because we should review #36642 as prerequisitie.
pinheadmz (Migrated from github.com) commented 2026-11-09 19:38:57 +00:00

I'm just gonna throw in the qualifier "valid" (requests) here but if you wanna push for the whole sentence I'll add it.

I'm just gonna throw in the qualifier "valid" (requests) here but if you wanna push for the whole sentence I'll add it.
Lines 48-51
pinheadmz (Migrated from github.com) commented 2026-11-09 19:54:14 +00:00

Heh ok this side bug is addressed in https://github.com/bitcoin/bitcoin/pull/36642 so I will focus on reviewing that, then rebase this on top to address the rest of your comment here.

Heh ok this side bug is addressed in https://github.com/bitcoin/bitcoin/pull/36642 so I will focus on reviewing that, then rebase this on top to address the rest of your comment here.
Lines 75-76
pinheadmz (Migrated from github.com) commented 2026-11-09 19:42:10 +00:00

Very clear thanks

Very clear thanks
pinheadmz (Migrated from github.com) commented 2026-11-09 19:32:33 +00:00

Cleaning this up as suggested, thanks

Cleaning this up as suggested, thanks
fametrano (Migrated from github.com) reviewed 2026-11-10 22:40:11 +00:00
fametrano (Migrated from github.com) left a comment

Concept ACK

You found this while reviewing my #36642, so with that merged today I ran this branch on master as a user with and without a whitelist (https://gist.github.com/fametrano/c15db81fbefd2f12a6d0ba9d829bda45/9a333a7c8ca8174577c5413d78f268543b670b4a). Merged onto master, the six malformed 2.0 requests of the new test get HTTP 200 with the error for both users, where master answers 400, and interface_rpc.py passes.

For the batch fix you plan: #36753's refused-batch reply drops an invalid element without an id through its own IsNotification() check. A "parsed" flag in the execution loop leaves that drop in place; deciding notifications in parse(), as ryanofsky suggested, fixes both.

Concept ACK You found this while reviewing my #36642, so with that merged today I ran this branch on master as a user with and without a whitelist (https://gist.github.com/fametrano/c15db81fbefd2f12a6d0ba9d829bda45/9a333a7c8ca8174577c5413d78f268543b670b4a). Merged onto master, the six malformed 2.0 requests of the new test get HTTP 200 with the error for both users, where master answers 400, and `interface_rpc.py` passes. For the batch fix you plan: #36753's refused-batch reply drops an invalid element without an id through its own `IsNotification()` check. A "parsed" flag in the execution loop leaves that drop in place; deciding notifications in `parse()`, as ryanofsky suggested, fixes both.
pinheadmz commented 2026-11-12 15:47:01 +00:00 (Migrated from github.com)

push to f5ed688fa1

  • rebase on master after merge of #36642
  • fix handling of batches with malformed requests, added an extra commit with @ryanofsky as coauthor
push to f5ed688fa1379c3703764538a27d66266e758968 - rebase on master after merge of #36642 - fix handling of batches with malformed requests, added an extra commit with @ryanofsky as coauthor
fametrano (Migrated from github.com) reviewed 2026-11-13 01:02:51 +00:00
fametrano (Migrated from github.com) left a comment

tACK f5ed688fa1

ryanofsky asked that batches follow the same notification rule as single requests, and the new commit decides it in parse(), as he suggested. I reran the probe from my last review on regtest (https://gist.github.com/fametrano/e5ebd604b25ed609b7144e53c1a23a5e/bf392bb18cdd5312a1607e09f466b75ccaab7852), with the previous head on the same master as the baseline.

The six malformed 2.0 requests of the test still get HTTP 200 with the error. For a user without a whitelist, a batch element without an id that fails to parse, such as {"jsonrpc":"2.0"}, had no reply before and now gets its error with "id":null. Valid notifications, alone or in a batch, still get 204 with no body. interface_rpc.py, rpc_whitelist.py, interface_http.py and rpc_users.py pass.

tACK f5ed688fa1379c3703764538a27d66266e758968 ryanofsky asked that batches follow the same notification rule as single requests, and the new commit decides it in `parse()`, as he suggested. I reran the probe from my last review on regtest (https://gist.github.com/fametrano/e5ebd604b25ed609b7144e53c1a23a5e/bf392bb18cdd5312a1607e09f466b75ccaab7852), with the previous head on the same master as the baseline. The six malformed 2.0 requests of the test still get HTTP 200 with the error. For a user without a whitelist, a batch element without an id that fails to parse, such as `{"jsonrpc":"2.0"}`, had no reply before and now gets its error with `"id":null`. Valid notifications, alone or in a batch, still get 204 with no body. `interface_rpc.py`, `rpc_whitelist.py`, `interface_http.py` and `rpc_users.py` pass.
ryanofsky (Migrated from github.com) approved these changes 2026-11-13 14:25:23 +00:00
ryanofsky (Migrated from github.com) left a comment

Code review ACK f5ed688fa1. On master, a malformed JSON-RPC 2.0 request makes debug builds abort and gets an HTTP 400 in release builds. With this PR it gets an HTTP 200 reply with the error, as the spec requires, and invalid requests without an id now get an error reply instead of being treated as notifications, both alone and in batches.

Thanks for the updates and for rebasing on #36642. The main remaining suggestion is to add commit messages to the second and third commits saying what behavior they change. The other comments are small test nits and can be ignored.

Code review ACK f5ed688fa1379c3703764538a27d66266e758968. On master, a malformed JSON-RPC 2.0 request makes debug builds abort and gets an HTTP 400 in release builds. With this PR it gets an HTTP 200 reply with the error, as the spec requires, and invalid requests without an id now get an error reply instead of being treated as notifications, both alone and in batches. Thanks for the updates and for rebasing on #36642. The main remaining suggestion is to add commit messages to the [second](https://github.com/bitcoin/bitcoin/pull/36758#discussion_r4564223263) and [third](https://github.com/bitcoin/bitcoin/pull/36758#discussion_r4564223454) commits saying what behavior they change. The other comments are small test nits and can be ignored.
ryanofsky (Migrated from github.com) commented 2026-11-13 13:31:20 +00:00

re: https://github.com/bitcoin/bitcoin/pull/36758#discussion_r4517122971

I'm just gonna throw in the qualifier "valid"

Thanks, "valid" is enough. No need for the rest of the sentence.

re: https://github.com/bitcoin/bitcoin/pull/36758#discussion_r4517122971 > I'm just gonna throw in the qualifier "valid" Thanks, "valid" is enough. No need for the rest of the sentence.
Lines 53-60
ryanofsky (Migrated from github.com) commented 2026-11-13 13:31:18 +00:00

re: https://github.com/bitcoin/bitcoin/pull/36758#discussion_r4517275774

this side bug is addressed in #36642

Thanks, agreed. Since #36642 every batch element gets its own copy of the unparsed request, so the reset at the start of parse() isn't needed, and the new commit fixes the rest. Singletons and batches now agree on what a notification is.

re: https://github.com/bitcoin/bitcoin/pull/36758#discussion_r4517275774 > this side bug is addressed in #36642 Thanks, agreed. Since #36642 every batch element gets its own copy of the unparsed request, so the reset at the start of `parse()` isn't needed, and the new commit fixes the rest. Singletons and batches now agree on what a notification is.
ryanofsky (Migrated from github.com) commented 2026-11-13 14:03:08 +00:00

In commit "rpc: handle malformed jsonrpc 2.0 requests correctly" (5004f241c5)

Could this commit and the next one have messages saying what behavior they change? It would be nice to be able to read the log and know how the server behaved before and after each change, without having to read the PR or the spec. Maybe something like:

Return HTTP 200 with an error reply for invalid JSON-RPC 2.0 requests,
such as ones with no method or with invalid params, like other 2.0
errors. Previously these requests hit an Assume() that aborted debug
builds, and release builds replied with HTTP 400.

JSONErrorReply() now handles 2.0 requests instead of asserting it never
gets them. Replies to requests without an "id" now include "id": null,
as JSON-RPC 2.0 requires.

And for the next commit, see the separate comment.

In commit "rpc: handle malformed jsonrpc 2.0 requests correctly" (5004f241c58113fbc29ddd2dbda3af0040827e90) Could this commit and the next one have messages saying what behavior they change? It would be nice to be able to read the log and know how the server behaved before and after each change, without having to read the PR or the spec. Maybe something like: ``` Return HTTP 200 with an error reply for invalid JSON-RPC 2.0 requests, such as ones with no method or with invalid params, like other 2.0 errors. Previously these requests hit an Assume() that aborted debug builds, and release builds replied with HTTP 400. JSONErrorReply() now handles 2.0 requests instead of asserting it never gets them. Replies to requests without an "id" now include "id": null, as JSON-RPC 2.0 requires. ``` And for the next commit, see [the separate comment](https://github.com/bitcoin/bitcoin/pull/36758#discussion_r4564223454).
Lines 271-274
ryanofsky (Migrated from github.com) commented 2026-11-13 14:03:09 +00:00

In commit "rpc: requests that fail to parse can not be jsonrpc2.0 notifications" (f5ed688fa1)

Suggested message for this commit (see the comment about the previous one):

Reply with an error to invalid JSON-RPC 2.0 requests without an "id" in
batches, instead of treating them as notifications and returning HTTP 204.
JSON-RPC 2.0 only treats _valid_ requests without an id as notifications.
This change keeps batch behavior consistent with nonbatch behavior after
previous commit which started returning error replies for invalid single
requests.
In commit "rpc: requests that fail to parse can not be jsonrpc2.0 notifications" (f5ed688fa1379c3703764538a27d66266e758968) Suggested message for this commit (see [the comment about the previous one](https://github.com/bitcoin/bitcoin/pull/36758#discussion_r4564223263)): ``` Reply with an error to invalid JSON-RPC 2.0 requests without an "id" in batches, instead of treating them as notifications and returning HTTP 204. JSON-RPC 2.0 only treats _valid_ requests without an id as notifications. This change keeps batch behavior consistent with nonbatch behavior after previous commit which started returning error replies for invalid single requests. ```
ryanofsky (Migrated from github.com) commented 2026-11-13 14:03:11 +00:00

In commit "rpc: requests that fail to parse can not be jsonrpc2.0 notifications" (f5ed688fa1)

nit: Since response_fields now also decides whether a request without an id expects a reply, is None seems more accurate than not. That way only an unset value means "no reply", and response_fields={} means "expect a reply with no extra fields" instead of being treated like None:

    if options.version == 2 and options.notification and options.response_fields is None:
In commit "rpc: requests that fail to parse can not be jsonrpc2.0 notifications" (f5ed688fa1379c3703764538a27d66266e758968) nit: Since `response_fields` now also decides whether a request without an id expects a reply, `is None` seems more accurate than `not`. That way only an unset value means "no reply", and `response_fields={}` means "expect a reply with no extra fields" instead of being treated like `None`: ```suggestion if options.version == 2 and options.notification and options.response_fields is None: ```
ryanofsky (Migrated from github.com) commented 2026-11-13 14:03:07 +00:00

In commit "rpc: requests that fail to parse can not be jsonrpc2.0 notifications" (f5ed688fa1)

The log message says this batch is all notifications, which is inaccurate after this commit: the batch has always included the invalid {"pizza": "sausage"} request, which used to be dropped as a notification and now gets an error reply. Maybe the message could just say the requests have no ids.

Also, format_response() already adds the jsonrpc and error fields from the call's expected result, so only the id is needed in response_fields and this could be simplified to:

        self.log.info("Testing JSON-RPC 2.0 batch of requests without ids...")
        # The request with no method (index 4) is invalid, so it is not a
        # notification, and gets an error reply with "id": null.
        self.test_batch_request(lambda idx: BatchOptions(version=2, notification=True, response_fields={"id": None} if idx == 4 else None))
In commit "rpc: requests that fail to parse can not be jsonrpc2.0 notifications" (f5ed688fa1379c3703764538a27d66266e758968) The log message says this batch is all notifications, which is inaccurate after this commit: the batch has always included the invalid `{"pizza": "sausage"}` request, which used to be dropped as a notification and now gets an error reply. Maybe the message could just say the requests have no ids. Also, `format_response()` already adds the `jsonrpc` and `error` fields from the call's expected result, so only the id is needed in `response_fields` and this could be simplified to: ```suggestion self.log.info("Testing JSON-RPC 2.0 batch of requests without ids...") # The request with no method (index 4) is invalid, so it is not a # notification, and gets an error reply with "id": null. self.test_batch_request(lambda idx: BatchOptions(version=2, notification=True, response_fields={"id": None} if idx == 4 else None)) ```
pinheadmz (Migrated from github.com) reviewed 2026-11-13 20:58:21 +00:00
pinheadmz (Migrated from github.com) left a comment

Push to 7f7428b457:

Address nits and expand commit messages per @ryanofsky feedback

Push to 7f7428b457ed2a3394dfc0e626485aaac4dbc266: Address nits and expand commit messages per @ryanofsky feedback
Lines 53-60
pinheadmz (Migrated from github.com) commented 2026-11-13 20:57:06 +00:00

👍

👍
Lines 271-274
pinheadmz (Migrated from github.com) commented 2026-11-13 20:56:57 +00:00

👍

👍
pinheadmz (Migrated from github.com) commented 2026-11-13 20:51:14 +00:00

Sure using is None here

Sure using `is None` here
pinheadmz (Migrated from github.com) commented 2026-11-13 20:49:57 +00:00

Taking this, more correct comment and cleaner code thanks.

Taking this, more correct comment and cleaner code thanks.
ryanofsky (Migrated from github.com) approved these changes 2026-11-16 17:22:18 +00:00
ryanofsky (Migrated from github.com) left a comment

Code review ACK 7f7428b457. On master, a malformed JSON-RPC 2.0 request makes debug builds abort and gets an HTTP 400 in release builds. With this PR it gets an HTTP 200 reply with the error, as the spec requires, and invalid requests without an id now get an error reply instead of being treated as notifications, both alone and in batches.

Since the last review, the only changes are the new commit messages and the two test cleanups. Thanks for taking these! One more suggestion, not a blocker: the HTTP_NO_CONTENT branch in JSONErrorReply() that I suggested earlier turns out to be dead code, and could be dropped from the last commit.

Code review ACK 7f7428b457ed2a3394dfc0e626485aaac4dbc266. On master, a malformed JSON-RPC 2.0 request makes debug builds abort and gets an HTTP 400 in release builds. With this PR it gets an HTTP 200 reply with the error, as the spec requires, and invalid requests without an id now get an error reply instead of being treated as notifications, both alone and in batches. Since the last review, the only changes are the new commit messages and the two test cleanups. Thanks for taking these! One more suggestion, not a blocker: the [`HTTP_NO_CONTENT` branch in `JSONErrorReply()`](https://github.com/bitcoin/bitcoin/pull/36758#discussion_r4589017331) that I suggested earlier turns out to be dead code, and could be dropped from the last commit.
Lines 50-53
ryanofsky (Migrated from github.com) commented 2026-11-16 17:16:39 +00:00

In commit "rpc: requests that fail to parse can not be jsonrpc2.0 notifications" (7f7428b457)

I suggested adding this block in https://github.com/bitcoin/bitcoin/pull/36758#discussion_r4498229560, but I think it should be dropped, because it's dead code in this PR. IsNotification() is only true after parse() succeeds, and nothing that throws after a successful parse reaches JSONErrorReply(): a single 2.0 request runs with catch_errors=true, the whitelist check returns 403 without throwing, and batch elements catch their own errors. Adding this dead code also makes it harder to understand how the real change in this commit actually works.

(I included this in my earlier suggestion because I was mixing this PR up with #36753, which needs something similar when it refuses a valid notification after parsing. But it can just be added there, so JSONErrorReply does not need to change at all in this commit.)

In commit "rpc: requests that fail to parse can not be jsonrpc2.0 notifications" (7f7428b457ed2a3394dfc0e626485aaac4dbc266) I suggested adding this block in https://github.com/bitcoin/bitcoin/pull/36758#discussion_r4498229560, but I think it should be dropped, because it's dead code in this PR. `IsNotification()` is only true after `parse()` succeeds, and nothing that throws after a successful parse reaches `JSONErrorReply()`: a single 2.0 request runs with [`catch_errors=true`](https://github.com/bitcoin/bitcoin/blob/7f7428b457ed2a3394dfc0e626485aaac4dbc266/src/rpc/server.cpp#L725-L732), the whitelist check returns 403 without throwing, and batch elements catch their own errors. Adding this dead code also makes it harder to understand how the real change in this commit actually works. (I included this in my earlier suggestion because I was mixing this PR up with #36753, which needs something similar when it refuses a valid notification after parsing. But it can just be added there, so `JSONErrorReply` does not need to change at all in this commit.)
hodlinator (Migrated from github.com) approved these changes 2026-11-17 12:56:06 +00:00
hodlinator (Migrated from github.com) left a comment

ACK 7f7428b457

Does indeed bring the behavior for invalid requests closer to the JSON-RPC 2.0 spec.

ACK 7f7428b457ed2a3394dfc0e626485aaac4dbc266 Does indeed bring the behavior for invalid requests closer to the JSON-RPC 2.0 spec.
hodlinator (Migrated from github.com) commented 2026-11-17 11:18:59 +00:00

nit: We know there is no pre-existing id field, so could use the quicker method here and on other such lines that are touched:

        reply.pushKVEnd("id", std::move(id.value()));
nit: We know there is no pre-existing `id` field, so could use the quicker method here and on other such lines that are touched: ```suggestion reply.pushKVEnd("id", std::move(id.value())); ```
hodlinator (Migrated from github.com) commented 2026-11-17 12:52:00 +00:00

nit: The reason for making IsNotification() use a "cached" value is not blatantly obvious. Could make it clearer if you touch again. Something like:

    //! Set at the end of a successful parse() of a JSON-RPC 2.0 request without an "id" member.
nit: The reason for making `IsNotification()` use a "cached" value is not blatantly obvious. Could make it clearer if you touch again. Something like: ```suggestion //! Set at the end of a successful parse() of a JSON-RPC 2.0 request without an "id" member. ```
pinheadmz (Migrated from github.com) reviewed 2026-11-17 20:31:51 +00:00
pinheadmz (Migrated from github.com) left a comment

push to 7611c96553

Address nits from @ryanofsky and @hodlinator thank you!

push to 7611c965535c41dfd09085bf1c571ef778b913e0 Address nits from @ryanofsky and @hodlinator thank you!
Lines 50-53
pinheadmz (Migrated from github.com) commented 2026-11-17 20:01:07 +00:00

Good catch, checked with an assert(false) here. A request can only be a notification now if parse() succeeds. If parse() succeeds there is no other JSONErrorReply() path before IsNotification() returns early.

Good catch, checked with an `assert(false)` here. A request can only be a notification now if `parse()` succeeds. If `parse()` succeeds there is no other `JSONErrorReply()` path before `IsNotification()` returns early.
pinheadmz (Migrated from github.com) commented 2026-11-17 20:11:59 +00:00

nice little optimization here, skipping UniValue::findKey() thanks.

nice little optimization here, skipping `UniValue::findKey()` thanks.
pinheadmz (Migrated from github.com) commented 2026-11-17 20:15:16 +00:00

sure, this is much more clear.

sure, this is much more clear.
ryanofsky (Migrated from github.com) approved these changes 2026-11-18 13:44:48 +00:00
ryanofsky (Migrated from github.com) left a comment

Code review ACK 7611c96553. Nice, targeted fixes for JSON-RPC server handing malformed JSON-RPC 2.0 requests incorrectly. The first commit just adds test coverage. The second commit makes malformed single requests return JSON errors instead of HTTP errors and avoid crashing debug builds. The third commit makes malformed batch subrequests without ids return errors instead of being treated like notifications and returning nothing.

Since the last review, the unreachable HTTP_NO_CONTENT branch was dropped, so the last commit no longer touches JSONErrorReply(), and hodlinator's two suggestions were applied. Thanks for the updates!

Code review ACK 7611c965535c41dfd09085bf1c571ef778b913e0. Nice, targeted fixes for JSON-RPC server handing malformed JSON-RPC 2.0 requests incorrectly. The first commit just adds test coverage. The second commit makes malformed single requests return JSON errors instead of HTTP errors and avoid crashing debug builds. The third commit makes malformed batch subrequests without ids return errors instead of being treated like notifications and returning nothing. Since the last review, the unreachable `HTTP_NO_CONTENT` branch was dropped, so the last commit no longer touches `JSONErrorReply()`, and hodlinator's two suggestions were applied. Thanks for the updates!
hodlinator (Migrated from github.com) approved these changes 2026-11-18 16:19:05 +00:00
hodlinator (Migrated from github.com) left a comment

re-ACK 7611c96553

Changes since first review:

  • Removed dead code
  • More optimal setting of UniValue fields
  • Clarified JSONRPCRequest::m_notification comment
re-ACK 7611c965535c41dfd09085bf1c571ef778b913e0 Changes since first review: * Removed dead code * More optimal setting of `UniValue` fields * Clarified `JSONRPCRequest::m_notification` comment
janb84 (Migrated from github.com) reviewed 2026-12-02 17:11:38 +00:00
janb84 (Migrated from github.com) left a comment

ACK 7611c96553

Makes the behavior for invalid requests more JSON-RPC 2.0 compliant.

Only one optional hardening remark, don't think it's big enough to invalidate the ACKs for it.

ACK 7611c965535c41dfd09085bf1c571ef778b913e0 Makes the behavior for invalid requests more JSON-RPC 2.0 compliant. Only one optional hardening remark, don't think it's big enough to invalidate the ACKs for it.
janb84 (Migrated from github.com) commented 2026-12-02 17:02:30 +00:00

Hardening option:
Consider resetting m_notification at the top of parse() so it doesn't depend on callers passing a fresh object."

    m_notification = false;
    // Parse request
Hardening option: Consider resetting `m_notification` at the top of parse() so it doesn't depend on callers passing a fresh object." ```suggestion m_notification = false; // Parse request ```
ryanofsky (Migrated from github.com) reviewed 2026-12-02 22:34:44 +00:00
ryanofsky (Migrated from github.com) commented 2026-12-02 22:31:27 +00:00

re: https://github.com/bitcoin/bitcoin/pull/36758#discussion_r4773174350

Consider resetting m_notification at the top of parse() so it doesn't depend on callers passing a fresh object.

Agree this would be nice hardening, and that it isn't worth a push here: both callers parse a fresh object since #36642. If we do add it, it should probably reset id and m_json_version too, because parse() throws before setting them when the request isn't an object, so a reused object would still reply with the previous id. I can add that to #36753, which touches parse() anyway.

re: https://github.com/bitcoin/bitcoin/pull/36758#discussion_r4773174350 > Consider resetting `m_notification` at the top of parse() so it doesn't depend on callers passing a fresh object. Agree this would be nice hardening, and that it isn't worth a push here: both callers parse a fresh object since #36642. If we do add it, it should probably reset `id` and `m_json_version` too, because `parse()` [throws before setting them](https://github.com/bitcoin/bitcoin/blob/7611c965535c41dfd09085bf1c571ef778b913e0/src/rpc/request.cpp#L214-L226) when the request isn't an object, so a reused object would still reply with the previous id. I can add that to #36753, which touches `parse()` anyway.
ryanofsky (Migrated from github.com) commented 2026-12-02 22:31:30 +00:00

In commit "rpc: requests that fail to parse can not be jsonrpc2.0 notifications" (7611c96553)

Not a blocker, could be a follow-up: now that entry 4 here gets an error reply, no batch test reaches the HTTP 204 "all notifications" branch any more, since every remaining batch expects at least one response. The Ralph review noticed this. Adding back a batch of only the valid notifications would cover it, e.g.:

self.log.info("Testing JSON-RPC 2.0 batch of only valid notifications...")
self.test_batch_request(lambda idx: BatchOptions(version=2, notification=True) if idx < 4 else None)
In commit "rpc: requests that fail to parse can not be jsonrpc2.0 notifications" (7611c965535c41dfd09085bf1c571ef778b913e0) Not a blocker, could be a follow-up: now that entry 4 here gets an error reply, no batch test reaches the HTTP 204 "all notifications" branch any more, since every remaining batch expects at least one response. The [Ralph review](https://review.fish.foo/report/36758-7611c965535c41dfd09085bf1c571ef778b913e0-2767-6.html#finding-finding%3A2) noticed this. Adding back a batch of only the valid notifications would cover it, e.g.: ```python self.log.info("Testing JSON-RPC 2.0 batch of only valid notifications...") self.test_batch_request(lambda idx: BatchOptions(version=2, notification=True) if idx < 4 else None) ```
winterrdog (Migrated from github.com) reviewed 2026-12-03 01:40:35 +00:00
winterrdog (Migrated from github.com) left a comment

post-merge crACK 7611c96553

post-merge crACK 7611c965535c41dfd09085bf1c571ef778b913e0
Sign in to join this conversation.
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
bitcoin/bitcoin!36758
No description provided.