Skip to content

Commit e389c4d

Browse files
committed
Merge bitcoin/bitcoin#25043: Reject invalid rpcauth formats
fa12706 Reject invalid rpcauth formats (MacroFake) Pull request description: This was added in commit 438ee59, but I couldn't determine if it was intentional. One reason to accept `foo:bar:baz` over `foo:bar$baz` is that `$` may be eaten by the shell. Though, I don't think many users pass `rpcauth` via the shell. Also it should be easy to avoid by passing `'-rpcauth=foo:bar$baz'` or `"-rpcauth=foo:bar\$baz"`. Can be tested with the added test. ACKs for top commit: pk-b2: ACK fa12706 Tree-SHA512: 9998cbb295c79f7b0342bf86e1d3e5b5ab90851c627662ad6495b699a65a9035998173cf1debfd94325387faba184de683407b609fe86acdd8f6749157644441
2 parents 5d53cf3 + fa12706 commit e389c4d

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

src/httprpc.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,22 @@
44

55
#include <httprpc.h>
66

7-
#include <chainparams.h>
87
#include <crypto/hmac_sha256.h>
98
#include <httpserver.h>
109
#include <rpc/protocol.h>
1110
#include <rpc/server.h>
1211
#include <util/strencodings.h>
1312
#include <util/string.h>
1413
#include <util/system.h>
15-
#include <util/translation.h>
1614
#include <walletinitinterface.h>
1715

1816
#include <algorithm>
1917
#include <iterator>
2018
#include <map>
2119
#include <memory>
22-
#include <stdio.h>
2320
#include <set>
2421
#include <string>
22+
#include <vector>
2523

2624
#include <boost/algorithm/string.hpp>
2725

@@ -254,13 +252,14 @@ static bool InitRPCAuthentication()
254252
LogPrintf("Config options rpcuser and rpcpassword will soon be deprecated. Locally-run instances may remove rpcuser to use cookie-based auth, or may be replaced with rpcauth. Please see share/rpcauth for rpcauth auth generation.\n");
255253
strRPCUserColonPass = gArgs.GetArg("-rpcuser", "") + ":" + gArgs.GetArg("-rpcpassword", "");
256254
}
257-
if (gArgs.GetArg("-rpcauth","") != "")
258-
{
255+
if (gArgs.GetArg("-rpcauth", "") != "") {
259256
LogPrintf("Using rpcauth authentication.\n");
260257
for (const std::string& rpcauth : gArgs.GetArgs("-rpcauth")) {
261-
std::vector<std::string> fields;
262-
boost::split(fields, rpcauth, boost::is_any_of(":$"));
263-
if (fields.size() == 3) {
258+
std::vector<std::string> fields{SplitString(rpcauth, ':')};
259+
const std::vector<std::string> salt_hmac{SplitString(fields.back(), '$')};
260+
if (fields.size() == 2 && salt_hmac.size() == 2) {
261+
fields.pop_back();
262+
fields.insert(fields.end(), salt_hmac.begin(), salt_hmac.end());
264263
g_rpcauth.push_back(fields);
265264
} else {
266265
LogPrintf("Invalid -rpcauth argument.\n");

test/functional/rpc_users.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,9 @@ def run_test(self):
107107
self.stop_node(0)
108108
self.nodes[0].assert_start_raises_init_error(expected_msg=init_error, extra_args=['-rpcauth=foo'])
109109
self.nodes[0].assert_start_raises_init_error(expected_msg=init_error, extra_args=['-rpcauth=foo:bar'])
110+
self.nodes[0].assert_start_raises_init_error(expected_msg=init_error, extra_args=['-rpcauth=foo:bar:baz'])
111+
self.nodes[0].assert_start_raises_init_error(expected_msg=init_error, extra_args=['-rpcauth=foo$bar:baz'])
112+
self.nodes[0].assert_start_raises_init_error(expected_msg=init_error, extra_args=['-rpcauth=foo$bar$baz'])
110113

111114
self.log.info('Check that failure to write cookie file will abort the node gracefully')
112115
cookie_file = os.path.join(get_datadir_path(self.options.tmpdir, 0), self.chain, '.cookie.tmp')

0 commit comments

Comments
 (0)