Skip to content

Commit 3615003

Browse files
committed
net: Always default rpcbind to localhost, never "all interfaces"
We don't support binding to untrusted networks, so avoid a default where that is typical
1 parent d7b0258 commit 3615003

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

src/httpserver.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -300,9 +300,12 @@ static bool HTTPBindAddresses(struct evhttp* http)
300300
std::vector<std::pair<std::string, uint16_t> > endpoints;
301301

302302
// Determine what addresses to bind to
303-
if (!gArgs.IsArgSet("-rpcallowip")) { // Default to loopback if not allowing external IPs
303+
if (!(gArgs.IsArgSet("-rpcallowip") && gArgs.IsArgSet("-rpcbind"))) { // Default to loopback if not allowing external IPs
304304
endpoints.push_back(std::make_pair("::1", http_port));
305305
endpoints.push_back(std::make_pair("127.0.0.1", http_port));
306+
if (gArgs.IsArgSet("-rpcallowip")) {
307+
LogPrintf("WARNING: option -rpcallowip was specified without -rpcbind; this doesn't usually make sense\n");
308+
}
306309
if (gArgs.IsArgSet("-rpcbind")) {
307310
LogPrintf("WARNING: option -rpcbind was ignored because -rpcallowip was not specified, refusing to allow everyone to connect\n");
308311
}
@@ -313,9 +316,6 @@ static bool HTTPBindAddresses(struct evhttp* http)
313316
SplitHostPort(strRPCBind, port, host);
314317
endpoints.push_back(std::make_pair(host, port));
315318
}
316-
} else { // No specific bind address specified, bind to any
317-
endpoints.push_back(std::make_pair("::", http_port));
318-
endpoints.push_back(std::make_pair("0.0.0.0", http_port));
319319
}
320320

321321
// Bind addresses

src/init.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,7 @@ void SetupServerArgs()
500500
gArgs.AddArg("-rest", strprintf("Accept public REST requests (default: %u)", DEFAULT_REST_ENABLE), false, OptionsCategory::RPC);
501501
gArgs.AddArg("-rpcallowip=<ip>", "Allow JSON-RPC connections from specified source. Valid for <ip> are a single IP (e.g. 1.2.3.4), a network/netmask (e.g. 1.2.3.4/255.255.255.0) or a network/CIDR (e.g. 1.2.3.4/24). This option can be specified multiple times", false, OptionsCategory::RPC);
502502
gArgs.AddArg("-rpcauth=<userpw>", "Username and hashed password for JSON-RPC connections. The field <userpw> comes in the format: <USERNAME>:<SALT>$<HASH>. A canonical python script is included in share/rpcauth. The client then connects normally using the rpcuser=<USERNAME>/rpcpassword=<PASSWORD> pair of arguments. This option can be specified multiple times", false, OptionsCategory::RPC);
503-
gArgs.AddArg("-rpcbind=<addr>[:port]", "Bind to given address to listen for JSON-RPC connections. This option is ignored unless -rpcallowip is also passed. Port is optional and overrides -rpcport. Use [host]:port notation for IPv6. This option can be specified multiple times (default: 127.0.0.1 and ::1 i.e., localhost, or if -rpcallowip has been specified, 0.0.0.0 and :: i.e., all addresses)", false, OptionsCategory::RPC);
503+
gArgs.AddArg("-rpcbind=<addr>[:port]", "Bind to given address to listen for JSON-RPC connections. This option is ignored unless -rpcallowip is also passed. Port is optional and overrides -rpcport. Use [host]:port notation for IPv6. This option can be specified multiple times (default: 127.0.0.1 and ::1 i.e., localhost)", false, OptionsCategory::RPC);
504504
gArgs.AddArg("-rpccookiefile=<loc>", "Location of the auth cookie. Relative paths will be prefixed by a net-specific datadir location. (default: data dir)", false, OptionsCategory::RPC);
505505
gArgs.AddArg("-rpcpassword=<pw>", "Password for JSON-RPC connections", false, OptionsCategory::RPC);
506506
gArgs.AddArg("-rpcport=<port>", strprintf("Listen for JSON-RPC connections on <port> (default: %u, testnet: %u, regtest: %u)", defaultBaseParams->RPCPort(), testnetBaseParams->RPCPort(), regtestBaseParams->RPCPort()), false, OptionsCategory::RPC);

0 commit comments

Comments
 (0)