Skip to content

Commit e03409c

Browse files
committed
Fix nonsensical -norpcbind and -norpcallowip behavior
Treat specifying -norpcbind and -norpcallowip the same as not specifying -rpcbind or -rpcallowip, instead of failing to bind to localhost and failing to show warnings. Also add code comment to clarify what intent of existing code is.
1 parent 40c4899 commit e03409c

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/httpserver.cpp

+8-4
Original file line numberDiff line numberDiff line change
@@ -362,16 +362,20 @@ static bool HTTPBindAddresses(struct evhttp* http)
362362
std::vector<std::pair<std::string, uint16_t>> endpoints;
363363

364364
// Determine what addresses to bind to
365-
if (!(gArgs.IsArgSet("-rpcallowip") && gArgs.IsArgSet("-rpcbind"))) { // Default to loopback if not allowing external IPs
365+
// To prevent misconfiguration and accidental exposure of the RPC
366+
// interface, require -rpcallowip and -rpcbind to both be specified
367+
// together. If either is missing, ignore both values, bind to localhost
368+
// instead, and log warnings.
369+
if (gArgs.GetArgs("-rpcallowip").empty() || gArgs.GetArgs("-rpcbind").empty()) { // Default to loopback if not allowing external IPs
366370
endpoints.emplace_back("::1", http_port);
367371
endpoints.emplace_back("127.0.0.1", http_port);
368-
if (gArgs.IsArgSet("-rpcallowip")) {
372+
if (!gArgs.GetArgs("-rpcallowip").empty()) {
369373
LogPrintf("WARNING: option -rpcallowip was specified without -rpcbind; this doesn't usually make sense\n");
370374
}
371-
if (gArgs.IsArgSet("-rpcbind")) {
375+
if (!gArgs.GetArgs("-rpcbind").empty()) {
372376
LogPrintf("WARNING: option -rpcbind was ignored because -rpcallowip was not specified, refusing to allow everyone to connect\n");
373377
}
374-
} else if (gArgs.IsArgSet("-rpcbind")) { // Specific bind address
378+
} else { // Specific bind addresses
375379
for (const std::string& strRPCBind : gArgs.GetArgs("-rpcbind")) {
376380
uint16_t port{http_port};
377381
std::string host;

0 commit comments

Comments
 (0)