@@ -101,6 +101,17 @@ class RpcHttpRequest
101101 }
102102};
103103
104+ static bool whitelisted (JSONRPCRequest jreq)
105+ {
106+ if (g_rpc_whitelist[jreq.authUser ].count (jreq.strMethod )) return true ;
107+
108+ // check for composite command after
109+ if (!jreq.params .isArray () || jreq.params .empty ()) return false ;
110+ if (!jreq.params [0 ].isStr ()) return false ;
111+
112+ return g_rpc_whitelist[jreq.authUser ].count (jreq.strMethod + jreq.params [0 ].get_str ());
113+ }
114+
104115static bool JSONErrorReply (RpcHttpRequest& rpcRequest, const UniValue& objError, const UniValue& id)
105116{
106117 // Send error reply from json-rpc error object
@@ -226,7 +237,7 @@ static bool HTTPReq_JSONRPC(const CoreContext& context, HTTPRequest* req)
226237 jreq.parse (valRequest);
227238 rpcRequest.command = jreq.strMethod ;
228239
229- if (user_has_whitelist && !g_rpc_whitelist[jreq. authUser ]. count (jreq. strMethod )) {
240+ if (user_has_whitelist && !whitelisted (jreq)) {
230241 LogPrintf (" RPC User %s not allowed to call method %s\n " , jreq.authUser , jreq.strMethod );
231242 return rpcRequest.send_reply (HTTP_FORBIDDEN);
232243 }
@@ -245,7 +256,7 @@ static bool HTTPReq_JSONRPC(const CoreContext& context, HTTPRequest* req)
245256 const UniValue& request = valRequest[reqIdx].get_obj ();
246257 // Parse method
247258 std::string strMethod = find_value (request, " method" ).get_str ();
248- if (!g_rpc_whitelist[jreq. authUser ]. count (strMethod )) {
259+ if (!whitelisted (jreq )) {
249260 LogPrintf (" RPC User %s not allowed to call method %s\n " , jreq.authUser , strMethod);
250261 return rpcRequest.send_reply (HTTP_FORBIDDEN);
251262 }
0 commit comments