diff --git a/src/httprpc.cpp b/src/httprpc.cpp index 56bbe4a680..ae9a821348 100644 --- a/src/httprpc.cpp +++ b/src/httprpc.cpp @@ -328,7 +328,19 @@ void StopHTTPRPC() } } -const std::set& GetWhitelistedRpcs(const std::string& user_name) +std::set GetWhitelistedRpcs(const std::string& user_name) { - return g_rpc_whitelist.at(user_name); + if (auto it = g_rpc_whitelist.find(user_name); it != g_rpc_whitelist.end()) { + return it->second; + } + if (g_rpc_whitelist_default) { + return std::set(); + } + + // Build a list of every method + std::set allowed_methods; + for (const auto& method_name : tableRPC.listCommands()) { + allowed_methods.insert(method_name); + } + return allowed_methods; } diff --git a/src/httprpc.h b/src/httprpc.h index ab25c1a100..55a1e271dd 100644 --- a/src/httprpc.h +++ b/src/httprpc.h @@ -35,6 +35,6 @@ void StopREST(); /** Returns a collection of whitelisted RPCs for the given user */ -const std::set& GetWhitelistedRpcs(const std::string& user_name); +std::set GetWhitelistedRpcs(const std::string& user_name); #endif // BITCOIN_HTTPRPC_H diff --git a/test/functional/rpc_getrpcwhitelist.py b/test/functional/rpc_getrpcwhitelist.py index 91fa9ce741..41e6b45bca 100755 --- a/test/functional/rpc_getrpcwhitelist.py +++ b/test/functional/rpc_getrpcwhitelist.py @@ -66,5 +66,9 @@ class RPCWhitelistTest(BitcoinTestFramework): result = call_rpc(self.nodes[0], self.settings_forbidden, 'getrpcwhitelist') assert_equal(result['status'], 403) + # should return a long list of allowed RPC methods (ie, all of them) + result = self.nodes[0].getrpcwhitelist() + assert len(result['methods']) > 10 + if __name__ == "__main__": RPCWhitelistTest().main()