diff --git a/comms/dht/src/inbound/decryption.rs b/comms/dht/src/inbound/decryption.rs index 941aa2290b..3be67efdba 100644 --- a/comms/dht/src/inbound/decryption.rs +++ b/comms/dht/src/inbound/decryption.rs @@ -197,6 +197,7 @@ where S: Service } } + #[allow(clippy::too_many_lines)] async fn validate_and_decrypt_message( node_identity: Arc, message: DhtInboundMessage, @@ -220,6 +221,24 @@ where S: Service return Err(DecryptionError::EncryptedMessageNoDestination); } + if !message.dht_header.destination.is_unknown() && + message + .dht_header + .destination + .public_key() + .map(|pk| pk != node_identity.public_key()) + .unwrap_or(false) + { + debug!( + target: LOG_TARGET, + "Encrypted message (source={}, {}) not destined for this peer. Passing to next service (Trace: {})", + message.source_peer.node_id, + message.dht_header.message_tag, + message.tag + ); + return Ok(DecryptedDhtMessage::failed(message)); + } + let e_pk = dht_header .ephemeral_public_key .as_ref()