What changed, and why it matters
This patch changes the Monero wallet RPC server so that it binds to its network port and starts listening before loading the wallet, and writes the auto-generated RPC login password file only after successfully binding. Previously, the server generated and wrote the password file before binding and before loading the wallet. The main practical effect is to reduce the window during which the generated password file exists on disk before the RPC service is actually ready, and to avoid creating the password file if binding fails. It also moves background-mining checks earlier. The change is a hardening improvement rather than a clear-cut fix for an active vulnerability, but it reduces exposure of sensitive credentials on disk and avoids serving RPC before the wallet is loaded.
Treat as a security-hardening improvement and include in release notes. Users running monero-wallet-rpc should upgrade to benefit from the reduced credential-file exposure window. No immediate emergency response is indicated by the diff alone, but a routine security patch release is appropriate.
Security signals we found
Deferred write of auto-generated RPC credentials to disk until after successful network bind
Reordered startup so RPC server binds before wallet is loaded
Reduced window where a generated password file exists while the service is not yet listening
Avoids creating a password file if the RPC server fails to initialize
No explicit bug or CVE reference in commit message or diff
Evidence from the diff
The commit reorders wallet_rpc_server::init() and the t_daemon startup sequence. In init(), generation of the random RPC password is decoupled from writing the .login file: the password is saved in a local optional (generated_password) and the file write is deferred until after epee::http_server_impl_base::init() returns true. The bind_port argument is no longer moved before init so it remains available for the filename. In t_daemon::run(), wrpc->init(&vm) is called before loading the wallet (wallet_file/from_json) and before the just_dir branch; the previous post-load init call is removed. Additionally, check_background_mining() is moved from near the end of init() to the start of run(). The patch therefore ensures the network socket is bound and the HTTP server initialized before wallet data is loaded, and the generated login secret is not persisted to disk unless binding succeeds.
Changed components
src/wallet/wallet_rpc_server.cppwallet_rpc_server::init()wallet_rpc_server::run()t_daemon::run()RPC login file generationInspect captured patch +39 / −30
### src/wallet/wallet_rpc_server.cpp
@@ -236,6 +236,7 @@ namespace tools
bool wallet_rpc_server::run()
{
m_stop = false;
+ check_background_mining();
const auto auto_refresh_evaluation_ms = std::chrono::milliseconds(200);
@@ -350,6 +351,7 @@ namespace tools
m_vm = vm;
boost::optional<epee::net_utils::http::login> http_login{};
+ boost::optional<epee::wipeable_string> generated_password{};
std::string bind_port = command_line::get_arg(*m_vm, arg_rpc_bind_port);
const bool disable_auth = command_line::get_arg(*m_vm, arg_disable_rpc_login);
m_restricted = command_line::get_arg(*m_vm, arg_restricted);
@@ -396,25 +398,7 @@ namespace tools
default_rpc_username,
string_encoding::base64_encode(rand_128bit.data(), rand_128bit.size())
);
-
- std::string temp = "monero-wallet-rpc." + bind_port + ".login";
- rpc_login_file = tools::private_file::drop_and_recreate(temp);
- if (!rpc_login_file.handle())
- {
- LOG_ERROR(tr("Failed to create file ") << temp << tr(". Check permissions or remove file"));
- return false;
- }
- std::fputs(http_login->username.c_str(), rpc_login_file.handle());
- std::fputc(':', rpc_login_file.handle());
- const epee::wipeable_string password = http_login->password;
- std::fwrite(password.data(), 1, password.size(), rpc_login_file.handle());
- std::fflush(rpc_login_file.handle());
- if (std::ferror(rpc_login_file.handle()))
- {
- LOG_ERROR(tr("Error writing to file ") << temp);
- return false;
- }
- LOG_PRINT_L0(tr("RPC username/password is stored in file ") << temp);
+ generated_password.emplace(http_login->password);
}
else // chosen user/pass
{
@@ -429,8 +413,6 @@ namespace tools
const auto over_one_period_ago = std::chrono::steady_clock::now() - std::chrono::seconds(m_auto_refresh_period.load(std::memory_order_relaxed) * 2);
m_last_auto_refresh_time = over_one_period_ago;
- check_background_mining();
-
const auto max_connections_public = command_line::get_arg(vm, arg_rpc_max_connections_per_public_ip);
const auto max_connections_private = command_line::get_arg(vm, arg_rpc_max_connections_per_private_ip);
const auto max_connections = command_line::get_arg(vm, arg_rpc_max_connections);
@@ -449,15 +431,38 @@ namespace tools
m_net_server.set_threads_prefix("RPC");
m_net_server.get_config_object().m_max_content_length = MAX_RPC_CONTENT_LENGTH * 100;
auto rng = [](size_t len, uint8_t *ptr) { return crypto::rand(len, ptr); };
- return epee::http_server_impl_base<wallet_rpc_server, connection_context>::init(
- rng, std::move(bind_port), std::move(rpc_config->bind_ip),
+ if (!epee::http_server_impl_base<wallet_rpc_server, connection_context>::init(
+ rng, bind_port, std::move(rpc_config->bind_ip),
std::move(rpc_config->bind_ipv6_address), std::move(rpc_config->use_ipv6), std::move(rpc_config->require_ipv4),
std::move(rpc_config->access_control_origins), std::move(http_login),
std::move(rpc_config->ssl_options),
max_connections_public, max_connections_private, max_connections,
command_line::get_arg(vm, arg_rpc_response_soft_limit),
rpc_config->disable_md5
- );
+ ))
+ return false;
+
+ if (generated_password)
+ {
+ const std::string temp = "monero-wallet-rpc." + bind_port + ".login";
+ rpc_login_file = tools::private_file::drop_and_recreate(temp);
+ if (!rpc_login_file.handle())
+ {
+ LOG_ERROR(tr("Failed to create file ") << temp << tr(". Check permissions or remove file"));
+ return false;
+ }
+ std::fputs(default_rpc_username, rpc_login_file.handle());
+ std::fputc(':', rpc_login_file.handle());
+ std::fwrite(generated_password->data(), 1, generated_password->size(), rpc_login_file.handle());
+ std::fflush(rpc_login_file.handle());
+ if (std::ferror(rpc_login_file.handle()))
+ {
+ LOG_ERROR(tr("Error writing to file ") << temp);
+ return false;
+ }
+ LOG_PRINT_L0(tr("RPC username/password is stored in file ") << temp);
+ }
+ return true;
}
//------------------------------------------------------------------------------------------------------------------------------
void wallet_rpc_server::check_background_mining()
@@ -5194,16 +5199,22 @@ class t_daemon
LOG_ERROR(tools::wallet_rpc_server::tr("Invalid configuration: ") << e.what());
return false;
}
- wal = NULL;
- goto just_dir;
}
-
- if (wallet_file.empty() && from_json.empty())
+ else if (wallet_file.empty() && from_json.empty())
{
LOG_ERROR(tools::wallet_rpc_server::tr("Must specify --wallet-file or --generate-from-json or --wallet-dir"));
return false;
}
+ if (!wrpc->init(&vm))
+ {
+ LOG_ERROR(tools::wallet_rpc_server::tr("Failed to initialize wallet RPC server"));
+ return false;
+ }
+
+ if (!wallet_dir.empty())
+ goto just_dir;
+
LOG_PRINT_L0(tools::wallet_rpc_server::tr("Loading wallet..."));
if(!wallet_file.empty())
{
@@ -5262,8 +5273,6 @@ class t_daemon
}
just_dir:
if (wal) wrpc->set_wallet(wal.release());
- bool r = wrpc->init(&vm);
- CHECK_AND_ASSERT_MES(r, false, tools::wallet_rpc_server::tr("Failed to initialize wallet RPC server"));
tools::signal_handler::install([this](int) {
wrpc->stop_refresh(); // a running refresh blocks server exit
wrpc->send_stop_signal();Why this scored 57/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.