Container Management (CONT-01 through CONT-06): - Fix needs_archy_net: add lnd, nbxplorer to archy-net list - Add StartupTier dependency ordering to health monitor (DB→Core→Dependent→App→UI) - Add exponential backoff (10s/30s/90s) with 1hr stability reset - Add get_health_check_args() with health checks for 20+ apps - Add get_memory_limit() with per-app limits (128m-4g vs blanket 2g) - Create docs/network-topology.md - Fix fedimint containers on both nodes (moved to archy-net) Security Audit (SEC-01 through SEC-06): - Add sanitize_error_message() — strips internal paths from RPC errors - Add validate_identity_id() — blocks path traversal on identity operations - Add validate_did() — blocks path traversal on federation operations - Add message size limits: node-send-message (1MB), dwn.write-message (10MB) - Add rate limits for federation endpoints (join: 5/60s, invite: 10/300s) - Configure journald (500MB max, 7 day retention) on both nodes - Add /etc/logrotate.d/archipelago for backend + crowdsec logs - Verify all 4 nginx security headers on both nodes Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
125 lines
4.8 KiB
Rust
125 lines
4.8 KiB
Rust
use super::RpcHandler;
|
|
use crate::{federation, node_message, nostr_discovery, peers};
|
|
use crate::peers::KnownPeer;
|
|
use anyhow::Result;
|
|
|
|
impl RpcHandler {
|
|
pub(super) async fn handle_node_add_peer(
|
|
&self,
|
|
params: Option<serde_json::Value>,
|
|
) -> Result<serde_json::Value> {
|
|
let params = params.ok_or_else(|| anyhow::anyhow!("Missing params"))?;
|
|
let onion = params
|
|
.get("onion")
|
|
.and_then(|v| v.as_str())
|
|
.ok_or_else(|| anyhow::anyhow!("Missing onion"))?;
|
|
let pubkey = params
|
|
.get("pubkey")
|
|
.and_then(|v| v.as_str())
|
|
.ok_or_else(|| anyhow::anyhow!("Missing pubkey"))?;
|
|
let name = params.get("name").and_then(|v| v.as_str()).map(String::from);
|
|
|
|
let peer = KnownPeer {
|
|
onion: onion.to_string(),
|
|
pubkey: pubkey.to_string(),
|
|
name,
|
|
added_at: Some(chrono::Utc::now().to_rfc3339()),
|
|
};
|
|
let peers = peers::add_peer(&self.config.data_dir, peer).await?;
|
|
Ok(serde_json::json!({ "peers": peers }))
|
|
}
|
|
|
|
pub(super) async fn handle_node_list_peers(&self) -> Result<serde_json::Value> {
|
|
let peers = peers::load_peers(&self.config.data_dir).await?;
|
|
Ok(serde_json::json!({ "peers": peers }))
|
|
}
|
|
|
|
pub(super) async fn handle_node_remove_peer(
|
|
&self,
|
|
params: Option<serde_json::Value>,
|
|
) -> Result<serde_json::Value> {
|
|
let params = params.ok_or_else(|| anyhow::anyhow!("Missing params"))?;
|
|
let pubkey = params
|
|
.get("pubkey")
|
|
.and_then(|v| v.as_str())
|
|
.ok_or_else(|| anyhow::anyhow!("Missing pubkey"))?;
|
|
let peers = peers::remove_peer(&self.config.data_dir, pubkey).await?;
|
|
Ok(serde_json::json!({ "peers": peers }))
|
|
}
|
|
|
|
pub(super) async fn handle_node_send_message(
|
|
&self,
|
|
params: Option<serde_json::Value>,
|
|
) -> Result<serde_json::Value> {
|
|
let params = params.ok_or_else(|| anyhow::anyhow!("Missing params"))?;
|
|
let onion = params
|
|
.get("onion")
|
|
.and_then(|v| v.as_str())
|
|
.ok_or_else(|| anyhow::anyhow!("Missing onion"))?;
|
|
let message = params
|
|
.get("message")
|
|
.and_then(|v| v.as_str())
|
|
.ok_or_else(|| anyhow::anyhow!("Missing message"))?;
|
|
|
|
// Limit message size to 1MB to prevent DoS
|
|
if message.len() > 1_048_576 {
|
|
anyhow::bail!("Message too large (max 1MB)");
|
|
}
|
|
|
|
// Validate onion is a known peer or federated node to prevent SSRF
|
|
let known_peers = peers::load_peers(&self.config.data_dir).await?;
|
|
let is_known_peer = known_peers.iter().any(|p| {
|
|
p.onion == onion || p.onion == format!("{}.onion", onion)
|
|
|| format!("{}.onion", p.onion) == onion
|
|
});
|
|
let is_known_fed = if !is_known_peer {
|
|
let fed_nodes = federation::load_nodes(&self.config.data_dir).await.unwrap_or_default();
|
|
fed_nodes.iter().any(|n| {
|
|
n.onion == onion || n.onion == format!("{}.onion", onion)
|
|
|| format!("{}.onion", n.onion) == onion
|
|
})
|
|
} else {
|
|
false
|
|
};
|
|
if !is_known_peer && !is_known_fed {
|
|
return Err(anyhow::anyhow!(
|
|
"Onion address not in known peers or federation. Add the peer first."
|
|
));
|
|
}
|
|
|
|
let (data, _) = self.state_manager.get_snapshot().await;
|
|
let pubkey = data.server_info.pubkey.clone();
|
|
node_message::send_to_peer(onion, &pubkey, message).await?;
|
|
Ok(serde_json::json!({ "ok": true, "sent_to": onion }))
|
|
}
|
|
|
|
pub(super) async fn handle_node_check_peer(
|
|
&self,
|
|
params: Option<serde_json::Value>,
|
|
) -> Result<serde_json::Value> {
|
|
let params = params.ok_or_else(|| anyhow::anyhow!("Missing params"))?;
|
|
let onion = params
|
|
.get("onion")
|
|
.and_then(|v| v.as_str())
|
|
.ok_or_else(|| anyhow::anyhow!("Missing onion"))?;
|
|
let reachable = node_message::check_peer_reachable(onion).await.unwrap_or(false);
|
|
Ok(serde_json::json!({ "onion": onion, "reachable": reachable }))
|
|
}
|
|
|
|
pub(super) async fn handle_node_messages_received(&self) -> Result<serde_json::Value> {
|
|
let messages = node_message::get_received();
|
|
Ok(serde_json::json!({ "messages": messages }))
|
|
}
|
|
|
|
pub(super) async fn handle_node_nostr_discover(&self) -> Result<serde_json::Value> {
|
|
let identity_dir = self.config.data_dir.join("identity");
|
|
let nodes = nostr_discovery::discover_archipelago_nodes(
|
|
&identity_dir,
|
|
&self.config.nostr_relays,
|
|
self.config.nostr_tor_proxy.as_deref(),
|
|
)
|
|
.await?;
|
|
Ok(serde_json::json!({ "nodes": nodes }))
|
|
}
|
|
}
|