Skip to content

Commit

Permalink
feat: ban peer unexpected response (#5608)
Browse files Browse the repository at this point in the history
Description
---
ban a peer if they sent an unexpected message

Motivation and Context
---
audit finding, TARI-002
  • Loading branch information
SWvheerden authored Aug 9, 2023
1 parent 91db6fb commit 02494ae
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions base_layer/core/src/base_node/comms_interface/inbound_handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -659,10 +659,10 @@ where B: BlockchainBackend + 'static
match self
.outbound_nci
.request_blocks_by_hashes_from_peer(block_hash, Some(source_peer.clone()))
.await?
.await
{
Some(block) => Ok(block),
None => {
Ok(Some(block)) => Ok(block),
Ok(None) => {
if let Err(e) = self
.connectivity
.ban_peer_until(
Expand All @@ -684,6 +684,21 @@ where B: BlockchainBackend + 'static
source_peer
)))
},
Err(CommsInterfaceError::UnexpectedApiResponse) => {
debug!(
target: LOG_TARGET,
"Peer `{}` sent unexpected API response.", source_peer
);
if let Err(e) = self
.connectivity
.ban_peer(source_peer.clone(), format!("Peer sen invalid API response"))
.await
{
error!(target: LOG_TARGET, "Failed to ban peer: {}", e);
}
Err(CommsInterfaceError::UnexpectedApiResponse)
},
Err(e) => Err(e),
}
}

Expand Down

0 comments on commit 02494ae

Please sign in to comment.