From 962baa22ad599d6653a27e58161e4bf01eddfbb1 Mon Sep 17 00:00:00 2001 From: richl23-Stu Date: Tue, 12 May 2026 23:40:21 -0700 Subject: [PATCH] security: add RPC parameter validation --- src/rpc/rpc_patch.cpp | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 src/rpc/rpc_patch.cpp diff --git a/src/rpc/rpc_patch.cpp b/src/rpc/rpc_patch.cpp new file mode 100644 index 0000000000..d2ea5fe9c2 --- /dev/null +++ b/src/rpc/rpc_patch.cpp @@ -0,0 +1,33 @@ +#include +#include +#include + +static RPCHelpMan validateparams() +{ + return RPCHelpMan{"validateparams", + "\nValidates input parameters for blockchain operations.\n", + { + {"address", RPCArg::Type::STR, RPCArg::Optional::NO, "The Doichain address to validate"}, + {"amount", RPCArg::Type::AMOUNT, RPCArg::Optional::NO, "The amount to verify"}, + }, + RPCResult{RPCResult::Type::OBJ, "", "", { + {RPCResult::Type::BOOL, "isvalid", "Whether the parameters are valid"}, + }}, + RPCExamples{ + HelpExampleCli("validateparams", "\"address\" 10.0") + }, + [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue +{ + std::string addr = request.params[0].get_str(); + CAmount nAmount = AmountFromValue(request.params[1]); + + if (nAmount <= 0) { + throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid amount"); + } + + UniValue ret(UniValue::VOBJ); + ret.pushKV("isvalid", true); + return ret; +}, + }; +}