Skip to content

Commit 45f5006

Browse files
committed
Merge #14618: rpc: Make HTTP RPC debug logging more informative
ab8c6f2 Add SAFE_CHARS[SAFE_CHARS_URI]: Chars allowed in URIs (RFC 3986) (practicalswift) 9912486 rpc: Make HTTP RPC debug logging more informative (practicalswift) Pull request description: * Make HTTP RPC debug logging more informative * Avoid excessively large log messages (which could theoretically fill up the disk) when running with debug option `-debug=http` Tree-SHA512: 9068862fb7d34db1e12e6b9dde78b669b86c65b4fed3ea8c9eb6c35310d77fd12b16644728fd7e9fbf25059d25114bded9e061eb3de649d8847486ec42041ce9
2 parents 76ae7a1 + ab8c6f2 commit 45f5006

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

src/httpserver.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -224,21 +224,25 @@ static void http_request_cb(struct evhttp_request* req, void* arg)
224224
}
225225
std::unique_ptr<HTTPRequest> hreq(new HTTPRequest(req));
226226

227-
LogPrint(BCLog::HTTP, "Received a %s request for %s from %s\n",
228-
RequestMethodString(hreq->GetRequestMethod()), hreq->GetURI(), hreq->GetPeer().ToString());
229-
230227
// Early address-based allow check
231228
if (!ClientAllowed(hreq->GetPeer())) {
229+
LogPrint(BCLog::HTTP, "HTTP request from %s rejected: Client network is not allowed RPC access\n",
230+
hreq->GetPeer().ToString());
232231
hreq->WriteReply(HTTP_FORBIDDEN);
233232
return;
234233
}
235234

236235
// Early reject unknown HTTP methods
237236
if (hreq->GetRequestMethod() == HTTPRequest::UNKNOWN) {
237+
LogPrint(BCLog::HTTP, "HTTP request from %s rejected: Unknown HTTP request method\n",
238+
hreq->GetPeer().ToString());
238239
hreq->WriteReply(HTTP_BADMETHOD);
239240
return;
240241
}
241242

243+
LogPrint(BCLog::HTTP, "Received a %s request for %s from %s\n",
244+
RequestMethodString(hreq->GetRequestMethod()), SanitizeString(hreq->GetURI(), SAFE_CHARS_URI).substr(0, 100), hreq->GetPeer().ToString());
245+
242246
// Find registered handler for prefix
243247
std::string strURI = hreq->GetURI();
244248
std::string path;

src/util/strencodings.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ static const std::string SAFE_CHARS[] =
2020
CHARS_ALPHA_NUM + " .,;-_/:?@()", // SAFE_CHARS_DEFAULT
2121
CHARS_ALPHA_NUM + " .,;-_?@", // SAFE_CHARS_UA_COMMENT
2222
CHARS_ALPHA_NUM + ".-_", // SAFE_CHARS_FILENAME
23+
CHARS_ALPHA_NUM + "!*'();:@&=+$,/?#[]-_.~%", // SAFE_CHARS_URI
2324
};
2425

2526
std::string SanitizeString(const std::string& str, int rule)

src/util/strencodings.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ enum SafeChars
2525
SAFE_CHARS_DEFAULT, //!< The full set of allowed chars
2626
SAFE_CHARS_UA_COMMENT, //!< BIP-0014 subset
2727
SAFE_CHARS_FILENAME, //!< Chars allowed in filenames
28+
SAFE_CHARS_URI, //!< Chars allowed in URIs (RFC 3986)
2829
};
2930

3031
/**

0 commit comments

Comments
 (0)