Skip to content

Commit a2a2816

Browse files
Eligioojxs
andauthored
fix(autonat): reject inbound dial request from peer if its not connected (#5597)
## Description As discovered and described in the issue below, there are situations where an incoming AutoNAT dial can come from a non-connected peer. However `resolve_inbound_request` expects that this situation cannot occur. This PR adds a check upfront and refuses the incoming dial when no connected peer is found. Fixes #5570. ## Change checklist - [x] I have performed a self-review of my own code - [x] I have made corresponding changes to the documentation - [ ] I have added tests that prove my fix is effective or that my feature works - [x] A changelog entry has been made in the appropriate crates Co-authored-by: João Oliveira <[email protected]>
1 parent cdc9638 commit a2a2816

File tree

5 files changed

+21
-3
lines changed

5 files changed

+21
-3
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ futures-bounded = { version = "0.2.4" }
7777
futures-rustls = { version = "0.26.0", default-features = false }
7878
libp2p = { version = "0.54.1", path = "libp2p" }
7979
libp2p-allow-block-list = { version = "0.4.1", path = "misc/allow-block-list" }
80-
libp2p-autonat = { version = "0.13.0", path = "protocols/autonat" }
80+
libp2p-autonat = { version = "0.13.1", path = "protocols/autonat" }
8181
libp2p-connection-limits = { version = "0.4.0", path = "misc/connection-limits" }
8282
libp2p-core = { version = "0.42.0", path = "core" }
8383
libp2p-dcutr = { version = "0.12.0", path = "protocols/dcutr" }

protocols/autonat/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## 0.13.1
2+
- Verify that an incoming AutoNAT dial comes from a connected peer. See [PR 5597](https://github.com/libp2p/rust-libp2p/pull/5597).
3+
14
## 0.13.0
25

36
- Due to the refactor of `Transport` it's no longer required to create a seperate transport for

protocols/autonat/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name = "libp2p-autonat"
33
edition = "2021"
44
rust-version = { workspace = true }
55
description = "NAT and firewall detection for libp2p"
6-
version = "0.13.0"
6+
version = "0.13.1"
77
authors = ["David Craven <[email protected]>", "Elena Frank <[email protected]>", "Hannes Furmans <[email protected]>"]
88
license = "MIT"
99
repository = "https://github.com/libp2p/rust-libp2p"

protocols/autonat/src/v1/behaviour/as_server.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,21 @@ impl<'a> HandleInnerEvent for AsServer<'a> {
107107
},
108108
} => {
109109
let probe_id = self.probe_id.next();
110+
if !self.connected.contains_key(&peer) {
111+
tracing::debug!(
112+
%peer,
113+
"Reject inbound dial request from peer since it is not connected"
114+
);
115+
116+
return VecDeque::from([ToSwarm::GenerateEvent(Event::InboundProbe(
117+
InboundProbeEvent::Error {
118+
probe_id,
119+
peer,
120+
error: InboundProbeError::Response(ResponseError::DialRefused),
121+
},
122+
))]);
123+
}
124+
110125
match self.resolve_inbound_request(peer, request) {
111126
Ok(addrs) => {
112127
tracing::debug!(

0 commit comments

Comments
 (0)