wallet: redact RPC creds everywhere and warn once on a login from env
The app-spawned child already takes its login from the sealed store record and only falls back to ONIONWIRE_WALLET_RPC_LOGIN; make that order explicit in the code and name the exposure once per process when the fallback is used. The dial URL still carries user:pass (Wallet::from_url needs it), but no rendering path repeats it: Endpoint::redacted and WalletClient::redacted_url print http://<redacted>:<redacted>@host:port/json_rpc, WalletClient has a hand-written Debug, and error/status copy redacts the whole login, not just the password half. Residual, documented at the top of wallet_child.rs: --rpc-login is visible in /proc/<pid>/cmdline to same-uid processes because monero-wallet-rpc has no other credential channel.
This commit is contained in:
parent
36969a7e95
commit
625879e000
3 changed files with 224 additions and 17 deletions
|
|
@ -22,6 +22,13 @@
|
|||
//! * The two Tor clients do not share state: the SOCKS child gets its own
|
||||
//! `state_dir`/`cache_dir` under the wallet dir.
|
||||
//! * `--trusted-daemon` is never passed: a remote daemon is untrusted.
|
||||
//! * Residual, and not fixable while the child is a spawned `monero-wallet-rpc`:
|
||||
//! `--rpc-login` is visible in `/proc/<pid>/cmdline` to same-uid processes
|
||||
//! because `monero-wallet-rpc` offers no other credential channel. The
|
||||
//! mitigation is a loopback-only bind, a strong generated login, and never
|
||||
//! handing the child a remote daemon. The login is also never rendered: the
|
||||
//! client's `url()` carries it for `Wallet::from_url`, while `Debug` and
|
||||
//! [`WalletClient::redacted_url`] show `http://<redacted>:<redacted>@127.0.0.1:<port>`.
|
||||
//! * The in-process daemon is *not* a child: it is a value owned by this struct,
|
||||
//! and dropping it shuts the node down. It still binds the same loopback RPC
|
||||
//! port, so everything downstream of `--daemon-address` is unchanged.
|
||||
|
|
@ -1060,12 +1067,23 @@ impl WalletChildStatus {
|
|||
/// The loopback client built from the generated URL — the production path when
|
||||
/// the app owns the child. Never `ONIONWIRE_WALLET_RPC`, never anything but
|
||||
/// numeric loopback.
|
||||
#[derive(Debug, Clone)]
|
||||
#[derive(Clone)]
|
||||
pub struct WalletClient {
|
||||
url: String,
|
||||
no_spend: bool,
|
||||
}
|
||||
|
||||
/// Hand-written: `url` carries the generated login, so a derived `Debug` would
|
||||
/// turn any `{:?}` — a log line, a panic message, an assert — into a leak.
|
||||
impl std::fmt::Debug for WalletClient {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
f.debug_struct("WalletClient")
|
||||
.field("url", &self.redacted_url())
|
||||
.field("no_spend", &self.no_spend)
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
|
||||
impl WalletClient {
|
||||
/// Build the [`Wallet`] this child serves. The chain-side RPC budget is the
|
||||
/// wallet backend's default (see `CHAIN_RPC_TIMEOUT`), because a first sync
|
||||
|
|
@ -1076,11 +1094,18 @@ impl WalletClient {
|
|||
.with_no_spend(self.no_spend)
|
||||
}
|
||||
|
||||
/// The loopback URL. Carries the generated creds — do not log it.
|
||||
/// The loopback URL. Carries the generated creds — do not log it; use
|
||||
/// [`WalletClient::redacted_url`] for anything a human or a log can see.
|
||||
pub fn url(&self) -> &str {
|
||||
&self.url
|
||||
}
|
||||
|
||||
/// The same endpoint with both halves of the login replaced:
|
||||
/// `http://<redacted>:<redacted>@127.0.0.1:<port>/json_rpc`.
|
||||
pub fn redacted_url(&self) -> String {
|
||||
wallet::redact_url(&self.url)
|
||||
}
|
||||
|
||||
pub fn no_spend(&self) -> bool {
|
||||
self.no_spend
|
||||
}
|
||||
|
|
@ -2055,6 +2080,26 @@ mod tests {
|
|||
rest.split('@').next().expect("userinfo").to_string()
|
||||
}
|
||||
|
||||
/// The client dials with creds in the URL, but nothing that renders it may
|
||||
/// repeat them: `Debug` and `redacted_url` are the display surfaces.
|
||||
#[test]
|
||||
fn wallet_client_debug_and_redacted_url_hide_the_login() {
|
||||
let client = WalletClient {
|
||||
url: "http://alice:[email protected]:18083/json_rpc".into(),
|
||||
no_spend: false,
|
||||
};
|
||||
let dbg = format!("{client:?}");
|
||||
assert!(!dbg.contains("s3cret"), "{dbg}");
|
||||
assert!(!dbg.contains("alice:s3cret"), "{dbg}");
|
||||
assert!(dbg.contains("127.0.0.1"), "{dbg}");
|
||||
assert_eq!(
|
||||
client.redacted_url(),
|
||||
"http://<redacted>:<redacted>@127.0.0.1:18083/json_rpc"
|
||||
);
|
||||
// The dial still needs the real userinfo — redaction is for display.
|
||||
assert!(client.url().contains("alice:s3cret"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn pick_port_is_free_loopback_and_bindable() {
|
||||
let port = WalletChild::pick_port().unwrap();
|
||||
|
|
|
|||
Loading…
Reference in a new issue