From d0760c918ab75c837548ca27f19a46d387f77004 Mon Sep 17 00:00:00 2001 From: tv Date: Fri, 6 Nov 2026 04:31:04 +0100 Subject: strangers messages small --- src/transport/mycelium/mod.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'src/transport/mycelium/mod.rs') diff --git a/src/transport/mycelium/mod.rs b/src/transport/mycelium/mod.rs index 7bae0a7..369d683 100644 --- a/src/transport/mycelium/mod.rs +++ b/src/transport/mycelium/mod.rs @@ -89,6 +89,8 @@ pub(crate) struct MyceliumTransport { messages_endpoint: Url, pubkey_basepath: Url, local_id: String, + /// Whose messages may be large (`transport::Admission`). + admission: std::sync::OnceLock, } /// This transport's options, checked when the configuration is loaded @@ -247,6 +249,7 @@ impl MyceliumTransport { messages_endpoint: rest_url.join("/api/v1/messages")?, pubkey_basepath: rest_url.join("/api/v1/pubkey/")?, local_id: admin.node_pubkey, + admission: std::sync::OnceLock::new(), }; transport.discard_backlog().await; Ok(transport) @@ -317,6 +320,10 @@ impl MyceliumTransport { #[async_trait] impl Transport for MyceliumTransport { + fn set_admission(&self, admission: crate::transport::Admission) { + let _ = self.admission.set(admission); + } + fn local_id(&self) -> &str { &self.local_id } @@ -413,6 +420,21 @@ impl Transport for MyceliumTransport { // PINGs and PONGs aren't handled after the message before them (`is_probe`). let handler: std::sync::Arc = std::sync::Arc::from(handler); while let Some(inbound_message) = rx.recv().await { + // Mycelium has taken it whole already; a stranger's large one isn't decoded. + let limit = crate::transport::Admission::limit( + self.admission.get(), + SCHEME, + &inbound_message.src_pk, + MAX_INBOUND_BYTES, + ); + if base64_decoded_len(&inbound_message.payload) > limit { + tracing::debug!( + from = %Addressed(SCHEME, &inbound_message.src_pk), + limit, + "Dropping a large message from a peer not admitted" + ); + continue; + } match parse_message(&inbound_message) { Ok((sender, parsed)) => { // The message itself is logged above, in the paths layer. -- cgit v1.3.1