Skip to content

Commit c8752c2

Browse files
committed
identify: Check the provided address ends with the peer ID
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
1 parent 51ab40b commit c8752c2

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

src/protocol/libp2p/identify.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,8 +342,24 @@ impl Identify {
342342
let listen_addresses = info
343343
.listen_addrs
344344
.iter()
345-
.filter_map(|address| Multiaddr::try_from(address.clone()).ok())
345+
.filter_map(|address| {
346+
let address = Multiaddr::try_from(address.clone()).ok()?;
347+
348+
// Ensure the address ends with the provided peer ID and is not empty.
349+
if address.is_empty() {
350+
return None;
351+
}
352+
if let Some(multiaddr::Protocol::P2p(peer_id)) = address.iter().last() {
353+
if peer_id != peer.into() {
354+
tracing::debug!(target: LOG_TARGET, ?peer, ?address, "peer identified provided invalid address");
355+
return None;
356+
}
357+
}
358+
359+
Some(address)
360+
})
346361
.collect();
362+
347363
let observed_address =
348364
info.observed_addr.and_then(|address| Multiaddr::try_from(address).ok());
349365
let protocol_version = info.protocol_version;

0 commit comments

Comments
 (0)