Skip to content

Commit

Permalink
rpc: fix DoS vector in get_output_distribution
Browse files Browse the repository at this point in the history
This will prevent people spending old pre-rct outputs using a
stranger's node, which may be a good thing
  • Loading branch information
moneromooo-monero committed Oct 24, 2021
1 parent 61e1630 commit a4954a9
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/rpc/core_rpc_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3007,6 +3007,14 @@ namespace cryptonote
if (use_bootstrap_daemon_if_necessary<COMMAND_RPC_GET_OUTPUT_DISTRIBUTION>(invoke_http_mode::JON_RPC, "get_output_distribution", req, res, r))
return r;

const bool restricted = m_restricted && ctx;
if (restricted && req.amounts != std::vector<uint64_t>(1, 0))
{
error_resp.code = CORE_RPC_ERROR_CODE_RESTRICTED;
error_resp.message = "Restricted RPC can only get output distribution for rct outputs. Use your own node.";
return false;
}

size_t n_0 = 0, n_non0 = 0;
for (uint64_t amount: req.amounts)
if (amount) ++n_non0; else ++n_0;
Expand Down Expand Up @@ -3048,6 +3056,13 @@ namespace cryptonote
if (use_bootstrap_daemon_if_necessary<COMMAND_RPC_GET_OUTPUT_DISTRIBUTION>(invoke_http_mode::BIN, "/get_output_distribution.bin", req, res, r))
return r;

const bool restricted = m_restricted && ctx;
if (restricted && req.amounts != std::vector<uint64_t>(1, 0))
{
res.status = "Restricted RPC can only get output distribution for rct outputs. Use your own node.";
return false;
}

size_t n_0 = 0, n_non0 = 0;
for (uint64_t amount: req.amounts)
if (amount) ++n_non0; else ++n_0;
Expand Down

0 comments on commit a4954a9

Please sign in to comment.