AI-generated analysisPublished automatically and not human-verified. Validated context appears in community notes below.
← Watch feed
Low 41 Bitcoin

Merge bitcoin/bitcoin#36758: rpc: handle malformed jsonrpc 2.0 requests correctly

Public commit record

What the developer wrote

Authored by Ryan Ofsky

100/100 · Strong
Merge bitcoin/bitcoin#36758: rpc: handle malformed jsonrpc 2.0 requests correctly

7611c965535c41dfd09085bf1c571ef778b913e0 rpc: requests that fail to parse can not be jsonrpc2.0 notifications (Matthew Zipkin)
0ef1cb66575b7a3f07f30aa52eff28664234db41 rpc: handle malformed jsonrpc 2.0 requests correctly (Matthew Zipkin)
d847ecd6b3bf1799bbeae5973b25d341d3e4d7f6 test: assert current RPC behavior when handling malformed request body (Matthew Zipkin)

Pull request description:

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.

ACKs for top commit:
ryanofsky:
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.
hodlinator:
re-ACK 7611c965535c41dfd09085bf1c571ef778b913e0
janb84:
ACK 7611c965535c41dfd09085bf1c571ef778b913e0

Tree-SHA512: 57828c3866e5152d34f3afa333cf76afb735d832b8f3acd582c7974cf35c3d9c6151533f9f91a4eab37d2a26ab1974e97d2db248d1ba0258c618fdb524a898ad
✓ Specific, descriptive subject✓ Names a concrete action or component✓ Provides detailed explanatory context✓ Explains rationale or failure mode✓ Mentions testing or verification✓ Links an issue, advisory, or supporting reference✓ Names security-relevant behavior explicitly
The short version

What changed, and why it matters

This update fixes a bug in Bitcoin Core's JSON-RPC server. When a malformed request claimed to use JSON-RPC 2.0, the server could crash in debug builds or return the wrong HTTP status code in release builds. The fix makes the server return a proper JSON-RPC error inside a normal HTTP 200 response, as the JSON-RPC 2.0 spec expects. It also stops malformed batch subrequests from being silently treated as notifications. The crash only happens with RPC authentication enabled and only in debug builds, so it is mainly a testing/reliability issue rather than a live-network threat.

Recommended action

Apply the patch. It is a low-urgency correctness fix. Operators running debug builds with RPC exposed and authentication enabled should update to avoid a potential crash from malformed RPC traffic. No immediate mainnet consensus or wallet risk is indicated.

Security signals we found

01

Debug-build assertion failure (crash) reachable via authenticated RPC

02

Protocol non-compliance: malformed JSON-RPC 2.0 requests returned HTTP 400 instead of HTTP 200 with JSON-RPC error body

03

Malformed batch subrequests without id were incorrectly treated as notifications and produced no reply

04

Fix adds explicit version check before choosing HTTP error vs JSON-RPC error response

Risk score

Why this scored 41/100

Our methodology →
Potential impact 8/30
Exploitability 7/25
Stealth signal 6/15
Affected reach 8/15
Confidence 8/10
Evidence quality 4/5
Human-validated context

Community notes

Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.

No validated notes yet.

The AI analysis stands alone for now. Submit a note if you can add evidence or important context.