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

http-server: guard against crashes from unhandled exceptions

Public commit record

What the developer wrote

Authored by furszy

95/100 · Strong
http-server: guard against crashes from unhandled exceptions

Currently, if an exception is thrown at the top-level HTTP request
handler (prior to invoking the command), the program crashes.

Ideally, each handler should catch all exceptions internally and
be responsible for sanitizing them and crafting the client response.
This is because only the handler knows the correct response format,
which differs per server type. However, because this cannot always
be guaranteed, it is safer to also catch exceptions in the top-level
server code, log the unexpected error, and disconnect the socket.

This both guards against crashes caused by uncaught exceptions and
prevents the client from hanging indefinitely while waiting for a
response that will never arrive.

The following diff can be used to trigger the crash in master
(just run single node functional tests like feature_shutdown.py):
```
diff --git a/src/httprpc.cpp b/src/httprpc.cpp
--- a/src/httprpc.cpp
+++ b/src/httprpc.cpp
@@ -103,6 +103,9 @@

static bool HTTPReq_JSONRPC(const std::any& context, HTTPRequest* req)
{
+ static int i = 0; // skip initial requests as they are used in the RPC warmup phase.
+ if (i++ > 3) throw std::runtime_error("error from json rpc handler");
+
// JSONRPC handles only POST
if (req->GetRequestMethod() != HTTPRequest::POST) {
req->WriteReply(HTTP_BAD_METHOD, "JSONRPC server handles only POST requests");

```

Note:
This leaves a TODO in the code because error responses should eventually
be specialized per server type. REST clients expect plain text responses,
while JSON-RPC clients expect a JSON error object.
The TODO is there because this is not consistently enforced everywhere
in the current codebase, and we should tackle them all at once.
✓ Specific, descriptive subject✓ Names a concrete action or component✓ Provides detailed explanatory context✓ Explains rationale or failure mode✓ Mentions testing or verification
The short version

What changed, and why it matters

This change fixes a bug in Bitcoin Core's built-in web server where an unexpected error inside an HTTP request handler could crash the entire program. The patch wraps each request in a safety net: if something throws an error, it is logged, the client connection is closed, and the program keeps running instead of crashing. The commit message also includes a test snippet showing the crash can be triggered intentionally.

Recommended action

Apply the patch. It is a straightforward defensive hardening change. Review individual HTTP handlers separately to ensure they catch exceptions internally and produce format-appropriate error responses (JSON-RPC vs REST), as noted by the TODO.

Security signals we found

01

Denial-of-service via unhandled exception in HTTP request handler

02

Process crash from top-level exception propagation

03

Client hang due to missing response on handler failure

04

Defensive catch-all exception handling added at HTTP server boundary

Risk score

Why this scored 62/100

Our methodology →
Potential impact 18/30
Exploitability 12/25
Stealth signal 8/15
Affected reach 12/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.