RPC: getrpcwhitelist: Return all methods (or none) if no explicit whitelist defined

This commit is contained in:
Luke Dashjr 2023-09-29 13:01:25 +00:00
parent e52d7d2033
commit 651c171539
3 changed files with 19 additions and 3 deletions

View File

@ -328,7 +328,19 @@ void StopHTTPRPC()
} }
} }
const std::set<std::string>& GetWhitelistedRpcs(const std::string& user_name) std::set<std::string> 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<std::string>();
}
// Build a list of every method
std::set<std::string> allowed_methods;
for (const auto& method_name : tableRPC.listCommands()) {
allowed_methods.insert(method_name);
}
return allowed_methods;
} }

View File

@ -35,6 +35,6 @@ void StopREST();
/** Returns a collection of whitelisted RPCs for the given user /** Returns a collection of whitelisted RPCs for the given user
*/ */
const std::set<std::string>& GetWhitelistedRpcs(const std::string& user_name); std::set<std::string> GetWhitelistedRpcs(const std::string& user_name);
#endif // BITCOIN_HTTPRPC_H #endif // BITCOIN_HTTPRPC_H

View File

@ -66,5 +66,9 @@ class RPCWhitelistTest(BitcoinTestFramework):
result = call_rpc(self.nodes[0], self.settings_forbidden, 'getrpcwhitelist') result = call_rpc(self.nodes[0], self.settings_forbidden, 'getrpcwhitelist')
assert_equal(result['status'], 403) 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__": if __name__ == "__main__":
RPCWhitelistTest().main() RPCWhitelistTest().main()