From 7f2cfe9294ec1fa7bece2a8069114c1b6985650f Mon Sep 17 00:00:00 2001 From: selsta Date: Wed, 25 Mar 2026 20:37:18 +0100 Subject: zmq: add restricted rpc mode --- src/rpc/daemon_handler.cpp | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) (limited to 'src/rpc/daemon_handler.cpp') diff --git a/src/rpc/daemon_handler.cpp b/src/rpc/daemon_handler.cpp index c1e4c10bf..671889ddd 100644 --- a/src/rpc/daemon_handler.cpp +++ b/src/rpc/daemon_handler.cpp @@ -27,6 +27,7 @@ // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "daemon_handler.h" +#include "rpc/zmq_restricted_methods.h" #include #include @@ -109,12 +110,14 @@ namespace rpc }; } // anonymous - DaemonHandler::DaemonHandler(cryptonote::core& c, t_p2p& p2p) - : m_core(c), m_p2p(p2p) + DaemonHandler::DaemonHandler(cryptonote::core& c, t_p2p& p2p, bool restricted) + : m_core(c), m_p2p(p2p), m_restricted(restricted) { const auto last_sorted = std::is_sorted_until(std::begin(handlers), std::end(handlers)); if (last_sorted != std::end(handlers)) throw std::logic_error{std::string{"ZMQ JSON-RPC handlers map is not properly sorted, see "} + last_sorted->method_name}; + + check_blocked_methods_sorted(); } void DaemonHandler::handle(const GetHeight::Request& req, GetHeight::Response& res) @@ -930,13 +933,24 @@ namespace rpc epee::byte_slice DaemonHandler::handle(std::string&& request) { - MDEBUG("Handling RPC request: " << request); + if (m_restricted) + MDEBUG("Handling RPC request"); + else + MDEBUG("Handling RPC request: " << request); try { FullMessage req_full(std::move(request), true); const std::string request_type = req_full.getRequestType(); + if (m_restricted && is_blocked_in_restricted_mode(request_type)) + { + Message fail; + fail.status = Message::STATUS_FAILED; + fail.error_details = "\"" + request_type + "\" is not available in restricted mode."; + return FullMessage::getResponse(fail, req_full.getID()); + } + const auto matched_handler = std::lower_bound(std::begin(handlers), std::end(handlers), request_type); if (matched_handler == std::end(handlers) || matched_handler->method_name != request_type) return BAD_REQUEST(request_type, req_full.getID()); -- cgit v1.2.3